changeset 6709:f84f507c53d3

context: let workingctx.date(), .user() and description() be overriden
author Patrick Mezard <pmezard@gmail.com>
date Wed, 18 Jun 2008 22:52:26 +0200
parents 7566f00a3979
children 0aa91f69a4c4
files mercurial/context.py mercurial/localrepo.py tests/test-committer.out
diffstat 3 files changed, 24 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/context.py	Wed Jun 18 22:52:26 2008 +0200
+++ b/mercurial/context.py	Wed Jun 18 22:52:26 2008 +0200
@@ -446,14 +446,26 @@
     """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.
+    date - any valid date string or (unixtime, offset), or None.
+    user - username string, or None.
     extra - a dictionary of extra values, or None.
     changes - a list of file lists as returned by localrepo.status()
                or None to use the repository status.
     """
-    def __init__(self, repo, parents=None, extra=None, changes=None):
+    def __init__(self, repo, parents=None, text="", user=None, date=None, 
+                 extra=None, changes=None):
         self._repo = repo
         self._rev = None
         self._node = None
+        self._text = text
+        if date is not None:
+            self._date = util.parsedate(date)
+        else:
+            self._date = util.makedate()
+        if user:
+            self._user = user
+        else:
+            self._user = self._repo.ui.username()
         if parents:
             p1, p2 = parents
             self._parents = [self._repo.changectx(p) for p in (p1, p2)]
@@ -518,9 +530,9 @@
 
     def manifest(self): return self._manifest
 
-    def user(self): return self._repo.ui.username()
-    def date(self): return util.makedate()
-    def description(self): return ""
+    def user(self): return self._user
+    def date(self): return self._date
+    def description(self): return self._text
     def files(self):
         f = self.modified() + self.added() + self.removed()
         f.sort()
--- a/mercurial/localrepo.py	Wed Jun 18 22:52:26 2008 +0200
+++ b/mercurial/localrepo.py	Wed Jun 18 22:52:26 2008 +0200
@@ -491,8 +491,10 @@
     def changectx(self, changeid=None):
         return context.changectx(self, changeid)
 
-    def workingctx(self, parents=None, extra=None, changes=None):
-        return context.workingctx(self, parents, extra, changes)
+    def workingctx(self, parents=None, text="", user=None, date=None, 
+                   extra=None, changes=None):
+        return context.workingctx(self, parents, text, user, date, extra, 
+                                  changes)
 
     def parents(self, changeid=None):
         '''
@@ -795,11 +797,13 @@
                 update_dirstate = (self.dirstate.parents()[0] == p1)
                 changes = [files, [], [], [], []]
 
-            wctx = self.workingctx((p1, p2), extra, changes)
+            wctx = self.workingctx((p1, p2), text, user, date, extra, changes)
             commit = wctx.modified() + wctx.added()
             remove = wctx.removed()
             extra = wctx.extra().copy()
             branchname = extra['branch']
+            user = wctx.user()
+            text = wctx.description()
 
             c1 = self.changelog.read(p1)
             c2 = self.changelog.read(p2)
@@ -868,7 +872,6 @@
                                    (new, removed))
 
             # add changeset
-            user = user or self.ui.username()
             if (not empty_ok and not text) or force_editor:
                 edittext = []
                 if text:
@@ -901,7 +904,7 @@
             text = '\n'.join(lines)
 
             n = self.changelog.add(mn, changed + removed, text, trp, p1, p2,
-                                   user, date, extra)
+                                   user, wctx.date(), extra)
             self.hook('pretxncommit', throw=True, node=hex(n), parent1=xp1,
                       parent2=xp2)
             tr.close()
--- a/tests/test-committer.out	Wed Jun 18 22:52:26 2008 +0200
+++ b/tests/test-committer.out	Wed Jun 18 22:52:26 2008 +0200
@@ -22,7 +22,5 @@
 date:        Mon Jan 12 13:46:40 1970 +0000
 summary:     commit-1
 
-transaction abort!
-rollback completed
 abort: Please specify a username.
 No username found, using user@host instead