]> arthur.barton.de Git - bup.git/commitdiff
Fix git_commit_dates() to handle (obvious) duplicates
authorRob Browning <rlb@defaultvalue.org>
Sat, 17 May 2014 20:34:32 +0000 (15:34 -0500)
committerRob Browning <rlb@defaultvalue.org>
Sat, 17 May 2014 20:43:54 +0000 (15:43 -0500)
Since git show will suppress duplicate results, change
git_commit_dates() to detect that situation and repair the damage.

Though currently, it can only handle cases where the duplicates are
obvious, i.e. have the same exact string in the argument list.  It
won't be able to handle cases where two arguments differ, but resolve
to the same underlying hash.  For our current purposes, that should be
fine since we only pass in hashes.

Signed-off-by: Rob Browning <rlb@defaultvalue.org>
lib/bup/git.py

index 1e2364aaf3b924e114eb6e264c34cd0eceb943db..314a5b3956a59bbd9602d93da771aee865d674f5 100644 (file)
@@ -760,12 +760,29 @@ def rev_list(ref, count=None):
 
 
 def get_commit_dates(refs):
-    """Get the dates for the specified commit refs."""
+    """Get the dates for the specified commit refs.  For now, every unique
+       string in refs must resolve to a different commit or this
+       function will fail."""
     result = []
     cmd = ['git', 'show', '-s', '--pretty=format:%ct']
     for chunk in batchpipe(cmd, refs, preexec_fn=_gitenv):
         result += [int(x) for x in chunk.splitlines()]
-    return result
+    if len(result) == len(refs):
+        return result
+    # git show suppressed duplicates -- fix it
+    ref_dates = {}
+    corrected_result = []
+    dates = iter(result)
+    for ref in refs:
+        prev_date = ref_dates.get(ref)
+        if prev_date:
+            corrected_result.append(prev_date)
+        else:
+            date = next(dates)
+            ref_dates[ref] = date
+            corrected_result.append(date)
+    assert(next(dates, None) is None)
+    return corrected_result
 
 
 def rev_parse(committish):