record: minor refactoring of dorecord
authorLaurent Charignon <lcharignon@fb.com>
Thu, 12 Mar 2015 17:50:23 -0700
changeset 24345 01b39149ebb3
parent 24344 6b43baac6dfb
child 24346 31edcea517c1
record: minor refactoring of dorecord It prepares the way for introducing the flag to reverse hunk selection
mercurial/cmdutil.py
--- a/mercurial/cmdutil.py	Thu Mar 12 14:42:55 2015 -0700
+++ b/mercurial/cmdutil.py	Thu Mar 12 17:50:23 2015 -0700
@@ -39,6 +39,9 @@
 def dorecord(ui, repo, commitfunc, cmdsuggest, backupall,
             filterfn, *pats, **opts):
     import merge as mergemod
+    hunkclasses = (crecordmod.uihunk, patch.recordhunk)
+    ishunk = lambda x: isinstance(x, hunkclasses)
+
     if not ui.interactive():
         raise util.Abort(_('running non-interactively, use %s instead') %
                          cmdsuggest)
@@ -96,10 +99,8 @@
 
         newandmodifiedfiles = set()
         for h in chunks:
-            iscrecordhunk = isinstance(h, crecordmod.uihunk)
-            ishunk = isinstance(h, patch.recordhunk)
             isnew = h.filename() in status.added
-            if (ishunk or iscrecordhunk) and isnew and not h in originalchunks:
+            if ishunk(h) and isnew and not h in originalchunks:
                 newandmodifiedfiles.add(h.filename())
 
         modified = set(status.modified)