pre-upload: allow different --rerun-since argument interpretations

When passing the --rerun-since command line option, date is not the
easiest to specify time limit when trying to determine how many
patches should be checked.

Let's allow specifying different arguments to this command line
option, adding sha1 of an existing patch and number of patches to

The following heuristics are used: if the value is shorter than 3
symbols, it must be the number of patches to check. If the value has
dashes in it, it must be a date. Otherwise it must be a SHA1.

TEST=verified that --rerun-since properly checks patches
     with any of all three formats.

Change-Id: I4a9383e820fa1c74fb7d26241d82495233d68969
Signed-off-by: Vadim Bendebury <>
Reviewed-by: Mike Frysinger <>
diff --git a/ b/
index d1d12ca..9672431 100755
--- a/
+++ b/
@@ -1793,10 +1793,12 @@
                       'specified, the repo tool will be used to figure this '
                       'out based on the dir.')
   parser.add_argument('--rerun-since', default=None,
-                      help='Rerun hooks on old commits since the given date.  '
-                      'The date should match git log\'s concept of a date.  '
-                      'e.g. 2012-06-20. This option is mutually exclusive '
-                      'with --pre-submit.')
+                      help='Rerun hooks on old commits since some point '
+                      'in the past.  The argument could be a date (should '
+                      'match git log\'s concept of a date, e.g. 2012-06-20), '
+                      'or a SHA1, or just a number of commits to check (from 1 '
+                      'to 99).  This option is mutually exclusive with '
+                      '--pre-submit.')
   parser.add_argument('--pre-submit', action="store_true",
                       help='Run the check against the pending commit.  '
                       'This option should be used at the \'git commit\' '
@@ -1811,7 +1813,16 @@
       raise BadInvocation('Can\'t pass commits and use rerun-since: %s' %
                           ' '.join(opts.commits))
-    cmd = ['git', 'log', '--since="%s"' % opts.rerun_since, '--pretty=%H']
+    if len(opts.rerun_since) < 3 and opts.rerun_since.isdigit():
+      # This must be the number of commits to check. We don't expect the user
+      # to want to check more than 99 commits.
+      limit = '-n%s' % opts.rerun_since
+    elif git.IsSHA1(opts.rerun_since, False):
+      limit = '%s..' %  opts.rerun_since
+    else:
+      # This better be a date.
+      limit = '--since=%s' % opts.rerun_since
+    cmd = ['git', 'log', limit, '--pretty=%H']
     all_commits = _run_command(cmd).splitlines()
     bot_commits = _run_command(cmd + ['--author=chrome-bot']).splitlines()