changeset 14255:576256a81cb6

patch: introduce changedfiles returns the set of all changed files in a given patch
author Idan Kamara <idankk86@gmail.com>
date Fri, 06 May 2011 19:03:41 +0300
parents d6a762d93b77
children d04ba50e104d
files mercurial/patch.py
diffstat 1 files changed, 22 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/patch.py	Sat May 07 23:14:36 2011 +0200
+++ b/mercurial/patch.py	Fri May 06 19:03:41 2011 +0300
@@ -1246,6 +1246,28 @@
     except PatchError, err:
         raise util.Abort(str(err))
 
+def changedfiles(patchpath, strip=1):
+    fp = open(patchpath, 'rb')
+    try:
+        changed = set()
+        for state, values in iterhunks(fp):
+            if state == 'hunk':
+                continue
+            elif state == 'file':
+                afile, bfile, first_hunk = values
+                current_file, missing = selectfile(afile, bfile,
+                                                   first_hunk, strip)
+                changed.add(current_file)
+            elif state == 'git':
+                for gp in values:
+                    gp.path = pathstrip(gp.path, strip - 1)[1]
+                    changed.add(gp.path)
+            else:
+                raise util.Abort(_('unsupported parser state: %s') % state)
+        return changed
+    finally:
+        fp.close()
+
 def b85diff(to, tn):
     '''print base85-encoded binary diff'''
     def gitindex(text):