[PATCH 3 of 5] patch: introduce changedfiles
Idan Kamara
idankk86 at gmail.com
Fri May 6 11:58:06 CDT 2011
# HG changeset patch
# User Idan Kamara <idankk86 at gmail.com>
# Date 1304697821 -10800
# Node ID 1365953fe513ea8b9a68d238df5c65565475480c
# Parent 7766361172826971d52df6c19a300d72e7f2abfc
patch: introduce changedfiles
returns the set of all changed files in a given patch
diff -r 776636117282 -r 1365953fe513 mercurial/patch.py
--- a/mercurial/patch.py Fri May 06 18:45:12 2011 +0300
+++ b/mercurial/patch.py Fri May 06 19:03:41 2011 +0300
@@ -1107,6 +1107,28 @@
return _applydiff(ui, fp, patchfile, copyfile, changed, strip=strip,
eolmode=eolmode)
+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 _applydiff(ui, fp, patcher, copyfn, changed, strip=1, eolmode='strict'):
rejects = 0
err = 0
More information about the Mercurial-devel
mailing list