localrepo: hide commit() file selection behind workingctx

This commit is contained in:
Patrick Mezard 2008-06-18 22:52:25 +02:00
parent d2d7e18a64
commit f2fb1d0609
2 changed files with 19 additions and 16 deletions

View File

@ -446,14 +446,18 @@ class workingctx(changectx):
"""A workingctx object makes access to data related to """A workingctx object makes access to data related to
the current working directory convenient. the current working directory convenient.
parents - a pair of parent nodeids, or None to use the dirstate. 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._repo = repo
self._rev = None self._rev = None
self._node = None self._node = None
if parents: if parents:
p1, p2 = parents p1, p2 = parents
self._parents = [self._repo.changectx(p) for p in (p1, p2)] self._parents = [self._repo.changectx(p) for p in (p1, p2)]
if changes:
self._status = list(changes)
def __str__(self): def __str__(self):
return str(self._parents[0]) + "+" return str(self._parents[0]) + "+"

View File

@ -491,8 +491,8 @@ class localrepository(repo.repository):
def changectx(self, changeid=None): def changectx(self, changeid=None):
return context.changectx(self, changeid) return context.changectx(self, changeid)
def workingctx(self, parents=None): def workingctx(self, parents=None, changes=None):
return context.workingctx(self, parents) return context.workingctx(self, parents, changes)
def parents(self, changeid=None): def parents(self, changeid=None):
''' '''
@ -777,29 +777,28 @@ class localrepository(repo.repository):
(match and (match.files() or match.anypats()))): (match and (match.files() or match.anypats()))):
raise util.Abort(_('cannot partially commit a merge ' raise util.Abort(_('cannot partially commit a merge '
'(do not specify files or patterns)')) '(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: if files:
modified, removed = [], []
for f in files: for f in files:
s = self.dirstate[f] s = self.dirstate[f]
if s in 'nma': if s in 'nma':
commit.append(f) modified.append(f)
elif s == 'r': elif s == 'r':
remove.append(f) removed.append(f)
else: else:
self.ui.warn(_("%s not tracked!\n") % f) self.ui.warn(_("%s not tracked!\n") % f)
changes = [modified, [], removed, [], []]
else: else:
changes = self.status(match=match)[:5] changes = self.status(match=match)
modified, added, removed, deleted, unknown = changes
commit = modified + added
remove = removed
else: 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) c1 = self.changelog.read(p1)
c2 = self.changelog.read(p2) c2 = self.changelog.read(p2)