[Python-checkins] cpython (merge 3.4 -> default): Issue #24031: make patchcheck now supports git checkouts, too.

christian.heimes python-checkins at python.org
Thu Apr 23 11:26:06 CEST 2015


https://hg.python.org/cpython/rev/d1b706e57fbe
changeset:   95785:d1b706e57fbe
parent:      95783:f60f65507d8e
parent:      95784:0f9c43fb189d
user:        Christian Heimes <christian at python.org>
date:        Thu Apr 23 11:25:41 2015 +0200
summary:
  Issue #24031: make patchcheck now supports git checkouts, too.

files:
  Misc/NEWS                   |   4 ++
  Tools/scripts/patchcheck.py |  34 ++++++++++++++++++------
  2 files changed, 29 insertions(+), 9 deletions(-)


diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -41,6 +41,10 @@
 
 - Issue #24029: Document the name binding behavior for submodule imports.
 
+Tools/Demos
+-----------
+
+- Issue #24031: make patchcheck now supports git checkouts, too.
 
 What's New in Python 3.5.0 alpha 4?
 ===================================
diff --git a/Tools/scripts/patchcheck.py b/Tools/scripts/patchcheck.py
--- a/Tools/scripts/patchcheck.py
+++ b/Tools/scripts/patchcheck.py
@@ -49,15 +49,31 @@
 @status("Getting the list of files that have been added/changed",
         info=lambda x: n_files_str(len(x)))
 def changed_files():
-    """Get the list of changed or added files from Mercurial."""
-    if not os.path.isdir(os.path.join(SRCDIR, '.hg')):
-        sys.exit('need a checkout to get modified files')
-
-    cmd = 'hg status --added --modified --no-status'
-    if mq_patches_applied():
-        cmd += ' --rev qparent'
-    with subprocess.Popen(cmd.split(), stdout=subprocess.PIPE) as st:
-        return [x.decode().rstrip() for x in st.stdout]
+    """Get the list of changed or added files from Mercurial or git."""
+    if os.path.isdir(os.path.join(SRCDIR, '.hg')):
+        cmd = 'hg status --added --modified --no-status'
+        if mq_patches_applied():
+            cmd += ' --rev qparent'
+        with subprocess.Popen(cmd.split(), stdout=subprocess.PIPE) as st:
+            return [x.decode().rstrip() for x in st.stdout]
+    elif os.path.isdir(os.path.join(SRCDIR, '.git')):
+        cmd = 'git status --porcelain'
+        filenames = []
+        with subprocess.Popen(cmd.split(), stdout=subprocess.PIPE) as st:
+            for line in st.stdout:
+                line = line.decode().rstrip()
+                status = set(line[:2])
+                # modified, added or unmerged files
+                if not status.intersection('MAU'):
+                    continue
+                filename = line[3:]
+                if ' -> ' in filename:
+                    # file is renamed
+                    filename = filename.split(' -> ', 2)[1].strip()
+                filenames.append(filename)
+        return filenames
+    else:
+        sys.exit('need a Mercurial or git checkout to get modified files')
 
 
 def report_modified_files(file_paths):

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list