[PATCH 16 of 19] localrepo: use workingcontext members instead of changes array during commit

David Schleimer dschleimer at fb.com
Sun Feb 10 17:30:06 CST 2013


# HG changeset patch
# User David Schleimer <dschleimer at fb.com>
# Date 1360512756 28800
# Node ID 486ffe802a0386d1aafa666d67363e937756e1e7
# Parent  d45c2924e79b417059dfc166e2364e85d4fd09a7
localrepo: use workingcontext members instead of changes array during commit

This changes localrepo.commit from building an array of changes, and
constructing a new workingcontext from that array to constructiong a
workingcotext, calling it's status method to fill in it's lists of
changes, and hten munging those lists.  this is preperatory to moving
the actual munging logic into workingcontext.  I also believe this
diff is a readability improvement, since it uses named methods rather
than integer list indeces to access the various file lists.

The long-term point of this is to move commit logic out of localrepo
and into workgincontext, so that other code can extend workingcontext
and have access to that logic.

diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -1151,19 +1151,20 @@
                 raise util.Abort(_('cannot partially commit a merge '
                                    '(do not specify files or patterns)'))
 
-            changes = self.status(match=match, clean=force)
+            wctx.status(match=match, clean=force)
             if force:
-                changes[0].extend(changes[6]) # mq may commit unchanged files
+                # mq may commit unchanged files
+                wctx.modified().extend(wctx.clean())
 
             subs = []
             # check subrepos
             # only manage subrepos and .hgsubstate if .hgsub is present
             if '.hgsub' in wctx:
                 # we'll decide whether to track this ourselves, thanks
-                if '.hgsubstate' in changes[0]:
-                    changes[0].remove('.hgsubstate')
-                if '.hgsubstate' in changes[2]:
-                    changes[2].remove('.hgsubstate')
+                if '.hgsubstate' in wctx.modified():
+                    wctx.modified().remove('.hgsubstate')
+                if '.hgsubstate' in wctx.removed():
+                    wctx.removed().remove('.hgsubstate')
 
                 subs, commitsubs, newstate = wctx.commitablesubstate(match,
                                                                      force)
@@ -1174,23 +1175,23 @@
                         '.hgsub' in (rawchanges[0] + rawchanges[1])):
                         raise util.Abort(
                             _("can't commit subrepos without .hgsub"))
-                    changes[0].insert(0, '.hgsubstate')
+                    wctx.modified().insert(0, '.hgsubstate')
 
-            elif '.hgsub' in changes[2]:
+            elif '.hgsub' in wctx.removed():
                 # clean up .hgsubstate when .hgsub is removed
                 if ('.hgsubstate' in wctx and
-                    '.hgsubstate' not in changes[0] + changes[1] + changes[2]):
-                    changes[2].insert(0, '.hgsubstate')
+                    '.hgsubstate' not in wctx.files()):
+                    wctx.removed().insert(0, '.hgsubstate')
 
             # make sure all explicit patterns are matched
             if not force and match.files():
-                matched = set(changes[0] + changes[1] + changes[2])
+                matched = set(wctx.files())
 
                 for f in match.files():
                     f = self.dirstate.normalize(f)
                     if f == '.' or f in matched or f in wctx.substate:
                         continue
-                    if f in changes[3]: # missing
+                    if f in wctx.deleted(): # missing
                         fail(f, _('file not found!'))
                     if f in vdirs: # visited directory
                         d = f + '/'
@@ -1202,7 +1203,7 @@
                     elif f not in self.dirstate:
                         fail(f, _("file not tracked!"))
 
-            cctx = context.workingctx(self, changes=changes)
+            cctx = wctx
 
             if (not force and not extra.get("close") and not merge
                 and not cctx.files()


More information about the Mercurial-devel mailing list