[PATCH 0 of 6] Refactor localrepo.commit() to read from changectx
Patrick Mézard
pmezard at gmail.com
Sun Jun 15 16:26:21 CDT 2008
Paul Moore a écrit :
> 2008/6/15 Patrick Mezard <pmezard at gmail.com>:
>> I would like to have some feedback about this approach before starting with the
>> memctx and refactoring convert.
>
> I'm not particularly qualified to comment on the changes themselves,
> but from an earlier comment I understand that one of the implications
> here is that the convert extension will not need to use the working
> directory as "intermediate storage".
Yay !
> I am strongly in favour of this,
> as I think it was at the root of an issue I had a while ago, where a
> Subversion repo I was tracking gave me some problems because of case
> clashes. Doing the conversion in stages seemed to resolve the issue,
> and I suspect it was caused by the dirstate not being able to hold one
> of the intermediate states.
Yay !!
> So I'm generally in favour of this change
I think all of us are.
I am really waiting feedback from Matt about this, to know whether it matches what he suggested in the previous patch series.
For the record, I have a rebased version of the convert part, it works fine and is not especially ugly. Here is the memctx part, which is the API part allowing direct commits. I will post the full series later.
# HG changeset patch
# User Patrick Mezard <pmezard at gmail.com>
# Date 1213564805 -7200
# Node ID 8792f27df24bdd4c3e8a951751dbb041e70865b5
# Parent 1d7b17c3d8abd0b2961d6fa993332803a4357fec
context: add memctx for memory commits
diff --git a/mercurial/context.py b/mercurial/context.py
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -673,3 +673,83 @@
return (t, tz)
def cmp(self, text): return self._repo.wread(self._path) == text
+
+class memctx(object):
+ """A memctx is a subset of changectx supposed to be built on memory
+ and passed to commit functions.
+
+ parents - a pair of parent nodeids.
+ filectxfn - a callable taking (repo, memctx, path) arguments and
+ returning a memctx object.
+ date - any valid date string or (unixtime, offset), or None.
+ user - username string, or None.
+ extra - a dictionary of extra values, or None.
+ """
+ def __init__(self, repo, parents, text, files, filectxfn, user=None,
+ date=None, extra=None):
+ self._repo = repo
+ self._rev = None
+ self._node = None
+ self._text = text
+ self._date = date and util.parsedate(date) or util.makedate()
+ self._user = user or self._repo.ui.username()
+ parents = [(p or nullid) for p in parents]
+ self._parents = [self._repo.changectx(p) for p in (p1, p2)]
+ files = list(files)
+ files.sort()
+ self._status = [files, [], [], [], []]
+ self._filectxfn = filectxfn
+
+ self._extra = extra and extra.copy() or {}
+ if self._extra.get('branch') == '':
+ self._extra['branch'] = 'default'
+
+ def __str__(self):
+ return str(self._parents[0]) + "+"
+
+ def __nonzero__(self):
+ return True
+
+ def user(self): return self._user
+ def date(self): return self._date
+ def description(self): return self._text
+ def files(self): return self.modified()
+ def modified(self): return self._status[0]
+ def added(self): return self._status[1]
+ def removed(self): return self._status[2]
+ def deleted(self): return self._status[3]
+ def unknown(self): return self._status[4]
+ def clean(self): return self._status[5]
+ def branch(self): return self._extra['branch']
+ def extra(self): return self._extra
+
+ def parents(self):
+ """return contexts for each parent changeset"""
+ return self._parents
+
+ def filectx(self, path, filelog=None):
+ """get a file context from the working directory"""
+ return self._filectxfn(self._repo, self, path)
+
+class memfilectx(object):
+ """A memfilectx is a subset of filectx supposed to be built by client
+ code and passed to commit functions.
+ """
+ def __init__(self, path, data, islink, isexec, copied):
+ """copied is the source file path, or None."""
+ self._path = path
+ self._data = data
+ self._flags = (islink and 'l' or '') + (isexec and 'x' or '')
+ self._copied = None
+ if copied:
+ self._copied = (copied, nullid)
+
+ def __nonzero__(self): return True
+ def __str__(self): return "%s@%s" % (self.path(), self._changectx)
+ def path(self): return self._path
+ def data(self): return self._data
+ def fileflags(self): return self._flags
+ def isexec(self): return 'x' in self._flags
+ def islink(self): return 'l' in self._flags
+ def renamed(self): return self._copied
+
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
--
Patrick Mézard
More information about the Mercurial-devel
mailing list