edgimar avatar edgimar committed f965569

- pulled in several changes from record.py (from crew revision 226a328a7ff3) --
seems to have resolved issue #16.

Comments (0)

Files changed (2)


 def crecord(ui, repo, *pats, **opts):
     '''interactively select changes to commit
-    If a list of files is omitted, all changes reported by "hg status"
+    If a list of files is omitted, all changes reported by :hg:`status`
     will be candidates for recording.
-    See "hg help dates" for a list of formats valid for -d/--date.
+    See :hg:`help dates` for a list of formats valid for -d/--date.
     You will be shown a list of patch hunks from which you can select
     those you would like to apply to the commit.
 def qcrecord(ui, repo, patch, *pats, **opts):
     '''interactively record a new patch
-    See "hg help qnew" & "hg help record" for more information and usage.'''
+    See :hg:`help qnew` & :hg:`help crecord` for more information and
+    usage.
+    '''
         mq = extensions.find('mq')


 import chunk_selector
 def dorecord(ui, repo, commitfunc, *pats, **opts):
-    if not ui.interactive:
+    if not ui.interactive():
         raise util.Abort(_('running non-interactively, use commit instead'))
     def recordfunc(ui, repo, message, match, opts):
             raise util.Abort(_('cannot partially commit a merge '
                                '(use hg commit instead)'))
-        if match.files():
-            changes = None
-        else:
-            changes = repo.status(match=match)[:3]
-            modified, added, removed = changes
-            match = cmdutil.matchfiles(repo, modified + added + removed)
+        changes = repo.status(match=match)[:3]
         diffopts = mdiff.diffopts(git=True, nodates=True)
-        chunks = patch.diff(repo, repo.dirstate.parents()[0], match=match,
-                            changes=changes, opts=diffopts)
+        chunks = patch.diff(repo, changes=changes, opts=diffopts)
         fp = cStringIO.StringIO()
         # 1. filter patch, so we have intending-to apply subset of it
-        if changes is not None:
-            chunks = crpatch.filterpatch(opts,
-                                         crpatch.parsepatch(changes, fp),
-                                         chunk_selector.chunkselector)
-        else:
-            chgs = repo.status(match=match)[:3]
-            chunks = crpatch.filterpatch(opts,
-                                         crpatch.parsepatch(chgs, fp),
-                                         chunk_selector.chunkselector)
+        chunks = crpatch.filterpatch(opts,
+                                     crpatch.parsepatch(changes, fp),
+                                     chunk_selector.chunkselector)
         del fp
-        contenders = {}
+        contenders = set()
         for h in chunks:
-            try: contenders.update(dict.fromkeys(h.files()))
-            except AttributeError: pass
+            try:
+                contenders.update(set(h.files()))
+            except AttributeError:
+                pass
-        newfiles = [f for f in match.files() if f in contenders]
+        changed = changes[0] + changes[1] + changes[2]
+        newfiles = [f for f in changed if f in contenders]
         if not newfiles:
             ui.status(_('no changes to record\n'))
             return 0
-        if changes is None:
-            match = cmdutil.matchfiles(repo, newfiles)
-            changes = repo.status(match=match)
-        modified = dict.fromkeys(changes[0])
+        modified = set(changes[0])
         # 2. backup changed files, so we can restore them in the end
         backups = {}
             # 3a. apply filtered patch to clean repo  (clean)
             if backups:
-                hg.revert(repo, repo.dirstate.parents()[0], backups.has_key)
+                hg.revert(repo, repo.dirstate.parents()[0],
+                          lambda key: key in backups)
             # 3b. (apply)
             if dopatch:
                     ui.debug('applying patch\n')
-                    patch.internalpatch(fp, ui, 1, repo.root)
+                    pfiles = {}
+                    patch.internalpatch(fp, ui, 1, repo.root, files=pfiles,
+                                        eolmode=None)
+                    patch.updatedir(ui, repo, pfiles)
                 except patch.PatchError, err:
                     s = str(err)
                     if s:
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.