changeset 6707:02bad34230a2

localrepo: hide commit() file selection behind workingctx
author Patrick Mezard <pmezard@gmail.com>
date Wed, 18 Jun 2008 22:52:25 +0200
parents 716a1296e182
children 7566f00a3979
files mercurial/context.py mercurial/localrepo.py
diffstat 2 files changed, 19 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/context.py	Wed Jun 18 22:52:25 2008 +0200
+++ b/mercurial/context.py	Wed Jun 18 22:52:25 2008 +0200
@@ -446,14 +446,18 @@
     """A workingctx object makes access to data related to
     the current working directory convenient.
     parents - a pair of parent nodeids, or None to use the dirstate.
+    changes - a list of file lists as returned by localrepo.status()
+               or None to use the repository status.
     """
-    def __init__(self, repo, parents=None):
+    def __init__(self, repo, parents=None, changes=None):
         self._repo = repo
         self._rev = None
         self._node = None
         if parents:
             p1, p2 = parents
             self._parents = [self._repo.changectx(p) for p in (p1, p2)]
+        if changes:
+            self._status = list(changes)
 
     def __str__(self):
         return str(self._parents[0]) + "+"
--- a/mercurial/localrepo.py	Wed Jun 18 22:52:25 2008 +0200
+++ b/mercurial/localrepo.py	Wed Jun 18 22:52:25 2008 +0200
@@ -491,8 +491,8 @@
     def changectx(self, changeid=None):
         return context.changectx(self, changeid)
 
-    def workingctx(self, parents=None):
-        return context.workingctx(self, parents)
+    def workingctx(self, parents=None, changes=None):
+        return context.workingctx(self, parents, changes)
 
     def parents(self, changeid=None):
         '''
@@ -777,29 +777,28 @@
                     (match and (match.files() or match.anypats()))):
                     raise util.Abort(_('cannot partially commit a merge '
                                        '(do not specify files or patterns)'))
-            else:
-                p1, p2 = p1, p2 or nullid
-                update_dirstate = (self.dirstate.parents()[0] == p1)
 
-            wctx = self.workingctx((p1, p2))
-
-            if use_dirstate:
                 if files:
+                    modified, removed = [], []
                     for f in files:
                         s = self.dirstate[f]
                         if s in 'nma':
-                            commit.append(f)
+                            modified.append(f)
                         elif s == 'r':
-                            remove.append(f)
+                            removed.append(f)
                         else:
                             self.ui.warn(_("%s not tracked!\n") % f)
+                    changes = [modified, [], removed, [], []]
                 else:
-                    changes = self.status(match=match)[:5]
-                    modified, added, removed, deleted, unknown = changes
-                    commit = modified + added
-                    remove = removed
+                    changes = self.status(match=match)
             else:
-                commit = files
+                p1, p2 = p1, p2 or nullid
+                update_dirstate = (self.dirstate.parents()[0] == p1)
+                changes = [files, [], [], [], []]
+
+            wctx = self.workingctx((p1, p2), changes)
+            commit = wctx.modified() + wctx.added()
+            remove = wctx.removed()
 
             c1 = self.changelog.read(p1)
             c2 = self.changelog.read(p2)