changeset 72:f9655697ea60

- pulled in several changes from record.py (from crew revision 226a328a7ff3) -- seems to have resolved issue #16.
author Mark Edgington <edgimar@gmail.com>
date Mon, 16 Aug 2010 12:33:41 +0200
parents 8fcd78da99f9
children 1164bfd10266
files crecord/__init__.py crecord/crecord_core.py
diffstat 2 files changed, 25 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/crecord/__init__.py
+++ b/crecord/__init__.py
@@ -16,10 +16,10 @@
 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.
@@ -32,7 +32,9 @@
 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.
+    '''
 
     try:
         mq = extensions.find('mq')
--- a/crecord/crecord_core.py
+++ b/crecord/crecord_core.py
@@ -20,7 +20,7 @@
 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):
@@ -42,47 +42,34 @@
             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()
         fp.write(''.join(chunks))
         fp.seek(0)
 
         # 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 = {}
@@ -121,14 +108,18 @@
 
             # 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:
                 try:
                     ui.debug('applying patch\n')
                     ui.debug(fp.getvalue())
-                    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: