doc/README.scrapyard: add missing commit IDs
[oweals/u-boot.git] / tools / patman / gitutil.py
index f48575013f5703ce43c2cbf5195b8746511fc7fc..b7f673955218ef3a49aee8ad5427353b8e6c2a27 100644 (file)
@@ -39,7 +39,8 @@ def CountCommitsToBranch():
     Return:
         Number of patches that exist on top of the branch
     """
-    pipe = [['git', 'log', '--no-color', '--oneline', '@{upstream}..'],
+    pipe = [['git', 'log', '--no-color', '--oneline', '--no-decorate',
+             '@{upstream}..'],
             ['wc', '-l']]
     stdout = command.RunPipe(pipe, capture=True, oneline=True).stdout
     patch_count = int(stdout)
@@ -55,10 +56,14 @@ def GetUpstream(git_dir, branch):
     Returns:
         Name of upstream branch (e.g. 'upstream/master') or None if none
     """
-    remote = command.OutputOneLine('git', '--git-dir', git_dir, 'config',
-            'branch.%s.remote' % branch)
-    merge = command.OutputOneLine('git', '--git-dir', git_dir, 'config',
-            'branch.%s.merge' % branch)
+    try:
+        remote = command.OutputOneLine('git', '--git-dir', git_dir, 'config',
+                                       'branch.%s.remote' % branch)
+        merge = command.OutputOneLine('git', '--git-dir', git_dir, 'config',
+                                      'branch.%s.merge' % branch)
+    except:
+        return None
+
     if remote == '.':
         return merge
     elif remote and merge:
@@ -77,9 +82,11 @@ def GetRangeInBranch(git_dir, branch, include_upstream=False):
         branch: Name of branch
     Return:
         Expression in the form 'upstream..branch' which can be used to
-        access the commits.
+        access the commits. If the branch does not exist, returns None.
     """
     upstream = GetUpstream(git_dir, branch)
+    if not upstream:
+        return None
     return '%s%s..%s' % (upstream, '~' if include_upstream else '', branch)
 
 def CountCommitsInBranch(git_dir, branch, include_upstream=False):
@@ -89,10 +96,14 @@ def CountCommitsInBranch(git_dir, branch, include_upstream=False):
         git_dir: Directory containing git repo
         branch: Name of branch
     Return:
-        Number of patches that exist on top of the branch
+        Number of patches that exist on top of the branch, or None if the
+        branch does not exist.
     """
     range_expr = GetRangeInBranch(git_dir, branch, include_upstream)
-    pipe = [['git', '--git-dir', git_dir, 'log', '--oneline', range_expr],
+    if not range_expr:
+        return None
+    pipe = [['git', '--git-dir', git_dir, 'log', '--oneline', '--no-decorate',
+             range_expr],
             ['wc', '-l']]
     result = command.RunPipe(pipe, capture=True, oneline=True)
     patch_count = int(result.stdout)
@@ -106,7 +117,7 @@ def CountCommits(commit_range):
     Return:
         Number of patches that exist on top of the branch
     """
-    pipe = [['git', 'log', '--oneline', commit_range],
+    pipe = [['git', 'log', '--oneline', '--no-decorate', commit_range],
             ['wc', '-l']]
     stdout = command.RunPipe(pipe, capture=True, oneline=True).stdout
     patch_count = int(stdout)