You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@impala.apache.org by ta...@apache.org on 2018/01/25 21:46:44 UTC

[5/6] impala git commit: IMPALA-6410: Use subprocess in compare_branches.py.

IMPALA-6410: Use subprocess in compare_branches.py.

Switches bin/compare_branches.py to use 'subprocess' instead
of 'sh'. We often use 'sh' in Impala testing code for its
friendly API, but it has to be installed separately. To avoid
automation that is just doing git operations needing to
either build the Impala python environment or otherwise get
extra libraries, I converted the usages.

As a side-effect, the script outputs the stdout of 'git cherry-pick',
whereas it used to swallow it. I like it better this way.

I tested this by running it in an environment which needed
some cherry-picks.

Change-Id: I509a548a129e7ad67aaf800a8ba03cffad51dd81
Reviewed-on: http://gerrit.cloudera.org:8080/9130
Reviewed-by: Jim Apple <jb...@apache.org>
Tested-by: Impala Public Jenkins


Project: http://git-wip-us.apache.org/repos/asf/impala/repo
Commit: http://git-wip-us.apache.org/repos/asf/impala/commit/088d6add
Tree: http://git-wip-us.apache.org/repos/asf/impala/tree/088d6add
Diff: http://git-wip-us.apache.org/repos/asf/impala/diff/088d6add

Branch: refs/heads/master
Commit: 088d6add784619e4f1be84588bafe94faf1693f4
Parents: b38db91
Author: Philip Zeyliger <ph...@cloudera.com>
Authored: Wed Jan 24 15:54:27 2018 -0800
Committer: Impala Public Jenkins <im...@gerrit.cloudera.org>
Committed: Thu Jan 25 20:27:59 2018 +0000

----------------------------------------------------------------------
 bin/compare_branches.py | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/impala/blob/088d6add/bin/compare_branches.py
----------------------------------------------------------------------
diff --git a/bin/compare_branches.py b/bin/compare_branches.py
index 6a81901..7050924 100755
--- a/bin/compare_branches.py
+++ b/bin/compare_branches.py
@@ -64,7 +64,7 @@ import json
 import logging
 import os
 import re
-import sh
+import subprocess
 import sys
 
 from collections import defaultdict
@@ -136,8 +136,8 @@ def build_commit_map(branch, merge_base):
   fields = ['%H', '%s', '%an', '%cd', '%b']
   pretty_format = '\x1f'.join(fields) + '\x1e'
   result = OrderedDict()
-  for line in sh.git.log(
-      branch, "^" + merge_base, pretty=pretty_format, color='never').split('\x1e'):
+  for line in subprocess.check_output(["git", "log", branch, "^" + merge_base,
+    "--pretty=" + pretty_format, "--color=never"]).split('\x1e'):
     if line == "":
       # if no changes are identified by the git log, we get an empty string
       continue
@@ -174,8 +174,9 @@ def cherrypick(cherry_pick_hashes, full_target_branch_name):
     return
 
   # Cherrypicking only makes sense if we're on the equivalent of the target branch.
-  head_sha = sh.git('rev-parse', 'HEAD').strip()
-  target_branch_sha = sh.git('rev-parse', full_target_branch_name).strip()
+  head_sha = subprocess.check_output(['git', 'rev-parse', 'HEAD']).strip()
+  target_branch_sha = subprocess.check_output(
+      ['git', 'rev-parse', full_target_branch_name]).strip()
   if head_sha != target_branch_sha:
     print "Cannot cherrypick because %s (%s) and HEAD (%s) are divergent." % (
         full_target_branch_name, target_branch_sha, head_sha)
@@ -183,7 +184,8 @@ def cherrypick(cherry_pick_hashes, full_target_branch_name):
 
   cherry_pick_hashes.reverse()
   for cherry_pick_hash in cherry_pick_hashes:
-    sh.git('cherry-pick', '--keep-redundant-commits', cherry_pick_hash)
+    subprocess.check_call(
+        ['git', 'cherry-pick', '--keep-redundant-commits', cherry_pick_hash])
 
 
 def main():
@@ -202,19 +204,19 @@ def main():
   # Ensure all branches are up to date, unless remotes are disabled
   # by specifying them with an empty string.
   if options.source_remote_name != "":
-    sh.git.fetch(options.source_remote_name)
+    subprocess.check_call(['git', 'fetch', options.source_remote_name])
     full_source_branch_name = options.source_remote_name + '/' + options.source_branch
   else:
     full_source_branch_name = options.source_branch
   if options.target_remote_name != "":
     if options.source_remote_name != options.target_remote_name:
-      sh.git.fetch(options.target_remote_name)
+      subprocess.check_call(['git', 'fetch', options.target_remote_name])
     full_target_branch_name = options.target_remote_name + '/' + options.target_branch
   else:
     full_target_branch_name = options.target_branch
 
-  merge_base = sh.git("merge-base",
-      full_source_branch_name, full_target_branch_name).strip()
+  merge_base = subprocess.check_output(["git", "merge-base",
+      full_source_branch_name, full_target_branch_name]).strip()
   source_commits = build_commit_map(full_source_branch_name, merge_base)
   target_commits = build_commit_map(full_target_branch_name, merge_base)