[PATCH 1 of 6] context: let workingctx parents be overriden

Patrick Mézard pmezard at gmail.com
Mon Jun 16 16:12:54 CDT 2008


Matt Mackall a écrit :
>> So providing I remove the changes to localrepo.workingctx() and mark
>> the extra parameters as implementation details, what do you think
>> about this ? I already have [2] so we can move forward if this
>> refactoring is accepted.
> 
> I'm a little worried by the patch that splits out a _commitctx function.
> Perhaps we should be instead migrating some of the ugly guts of commit
> out into commands.py or cmdutil.py. Localrepo really shouldn't bother
> itself with editors and such..

I split localrepo._commitctx() because:
1- Separating the context initialization from the generic commit routine looked good
2- The generic routine can almost be used directly with "memctx" except for the locking part: I cannot lock in it since we need to lock when building the workingctx from the dirstate. So I extracted it assuming I would add something like:

diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -799,6 +799,17 @@
         finally:
             del lock, wlock
 
+    def commitctx(self, ctx):
+        wlock = lock = None
+        try:
+            wlock = self.wlock()
+            lock = self.lock()
+            use_dirstate = False
+            update_dirstate = False
+            return self._commitctx(ctx, True, False, True, False, False)
+        finally:
+            del lock, wlock
+
     def _commitctx(self, wctx, force=False, force_editor=False, empty_ok=False,
                   use_dirstate=True, update_dirstate=True):
         tr = None



But nothing prevents me from extracting this whole block too:


"""
            if (not empty_ok and not text) or force_editor:
                edittext = []
                if text:
                    edittext.append(text)
                edittext.append("")
                edittext.append(_("HG: Enter commit message."
                                  "  Lines beginning with 'HG:' are removed."))
                edittext.append("HG: --")
                edittext.append("HG: user: %s" % user)
                if p2 != nullid:
                    edittext.append("HG: branch merge")
                if branchname:
                    edittext.append("HG: branch '%s'" % util.tolocal(branchname))
                edittext.extend(["HG: changed %s" % f for f in changed])
                edittext.extend(["HG: removed %s" % f for f in removed])
                if not changed and not remove:
                    edittext.append("HG: no files changed")
                edittext.append("")
                # run editor in the repository root
                olddir = os.getcwd()
                os.chdir(self.root)
                text = self.ui.edit("\n".join(edittext), user)
                os.chdir(olddir)

            lines = [line.rstrip() for line in text.rstrip().splitlines()]
            while lines and not lines[0]:
                del lines[0]
            if not lines and use_dirstate:
                raise util.Abort(_("empty commit message"))
            text = '\n'.join(lines)
"""

into a cmdutil function. I want to keep the line filtering part for I would like to reuse it in mq to reproduce the same aborting behaviour when refreshing/creating patches with explicit empty messages.

So, I will push the patch queue in 2 days with the following changes:
- do not change localrepo.workingctx() and use the workingctx constructor directly
- document that workingctx arguments are not intended for consumption, people should use localrepo.workingctx()
- extract the above block in a cmdutil function.

--
Patrick Mézard



More information about the Mercurial-devel mailing list