commit: move editor outside transaction
authorMatt Mackall <mpm@selenic.com>
Mon, 18 May 2009 17:36:24 -0500
changeset 8496 a21605de1509
parent 8495 5b7596b142ad
child 8497 ff22d4c3ac04
commit: move editor outside transaction The commit editor is now invoked before files and manifest are committed. The editor is now run with only the wlock held and aborting an edit no longer requires rolling back a transaction. Changes to files during a commit still result in undefined behavior. (This is preliminary work for committing subrepositories)
mercurial/localrepo.py
tests/test-commit.out
tests/test-import.out
tests/test-keyword.out
tests/test-record.out
--- a/mercurial/localrepo.py	Mon May 18 22:55:45 2009 +0200
+++ b/mercurial/localrepo.py	Mon May 18 17:36:24 2009 -0500
@@ -810,9 +810,14 @@
                 if f in ms and ms[f] == 'u':
                     raise util.Abort(_("unresolved merge conflicts "
                                                     "(see hg resolve)"))
+
             wctx = context.workingctx(self, (p1, p2), text, user, date,
                                       extra, changes)
-            ret = self.commitctx(wctx, editor, True)
+            if editor:
+                wctx._text = editor(self, wctx,
+                                    changes[1], changes[0], changes[2])
+
+            ret = self.commitctx(wctx, True)
             ms.reset()
 
             # update dirstate
@@ -829,7 +834,7 @@
                 self.dirstate.invalidate() # didn't successfully commit
             wlock.release()
 
-    def commitctx(self, ctx, editor=None, error=False):
+    def commitctx(self, ctx, error=False):
         """Add a new revision to current repository.
 
         Revision information is passed via the context argument.
@@ -870,13 +875,6 @@
                     else:
                         remove.append(f)
 
-            updated, added = [], []
-            for f in sorted(changed):
-                if f in m1 or f in m2:
-                    updated.append(f)
-                else:
-                    added.append(f)
-
             # update manifest
             m1.update(new)
             removed = [f for f in sorted(remove) if f in m1 or f in m2]
@@ -890,9 +888,6 @@
                                    p2.manifestnode(), (new, removed1))
 
             text = ctx.description()
-            if editor:
-                text = editor(self, ctx, added, updated, removed)
-
             lines = [line.rstrip() for line in text.rstrip().splitlines()]
             while lines and not lines[0]:
                 del lines[0]
--- a/tests/test-commit.out	Mon May 18 22:55:45 2009 +0200
+++ b/tests/test-commit.out	Mon May 18 17:36:24 2009 -0500
@@ -1,6 +1,4 @@
 % commit date test
-transaction abort!
-rollback completed
 abort: empty commit message
 abort: impossible time zone offset: 4444444
 abort: invalid date: '1\t15.1' 
@@ -116,6 +114,4 @@
 HG: added added
 HG: changed changed
 HG: removed removed
-transaction abort!
-rollback completed
 abort: empty commit message
--- a/tests/test-import.out	Mon May 18 22:55:45 2009 +0200
+++ b/tests/test-import.out	Mon May 18 17:36:24 2009 -0500
@@ -32,8 +32,6 @@
 updating working directory
 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
 applying ../tip.patch
-transaction abort!
-rollback completed
 abort: empty commit message
 % import of plain diff should be ok with message
 requesting all changes
@@ -150,8 +148,6 @@
 updating working directory
 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
 applying patch from stdin
-transaction abort!
-rollback completed
 abort: empty commit message
 % hg export in email, should use patch header
 requesting all changes
--- a/tests/test-keyword.out	Mon May 18 22:55:45 2009 +0200
+++ b/tests/test-keyword.out	Mon May 18 17:36:24 2009 -0500
@@ -112,10 +112,6 @@
 A b
 % default keyword expansion including commit hook
 % interrupted commit should not change state or run commit hook
-a
-b
-transaction abort!
-rollback completed
 abort: empty commit message
 % status
 A a
@@ -281,8 +277,6 @@
 ignore $Id$
 a
 % interrupted commit should not change state
-transaction abort!
-rollback completed
 abort: empty commit message
 % status
 M a
--- a/tests/test-record.out	Mon May 18 22:55:45 2009 +0200
+++ b/tests/test-record.out	Mon May 18 17:36:24 2009 -0500
@@ -53,9 +53,7 @@
 % select files but no hunks
 diff --git a/empty-rw b/empty-rw
 new file mode 100644
-examine changes to 'empty-rw'? [Ynsfdaq?]  transaction abort!
-rollback completed
-abort: empty commit message
+examine changes to 'empty-rw'? [Ynsfdaq?]  abort: empty commit message
 
 changeset:   -1:000000000000
 tag:         tip