changeset 5810:124577de40a7

context: preserve changeset in filectx if we have one If we know original changeset we are working with - try hard to preserve it. Fallback to filelog.linkrev() only if we have no way to get original changeset, since linkrev() may point to other changeset.
author Maxim Dounin <mdounin@mdounin.ru>
date Sat, 29 Dec 2007 16:57:43 +0300
parents 34c4131abdf9
children 180a3eee4b75
files mercurial/context.py tests/test-issue672.out
diffstat 2 files changed, 12 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/context.py	Sat Jan 05 17:36:16 2008 +0100
+++ b/mercurial/context.py	Sat Dec 29 16:57:43 2007 +0300
@@ -159,12 +159,11 @@
         if filelog:
             self._filelog = filelog
 
-        if fileid is None:
-            if changectx is None:
-                self._changeid = changeid
-            else:
-                self._changectx = changectx
-        else:
+        if changeid is not None:
+            self._changeid = changeid
+        if changectx is not None:
+            self._changectx = changectx
+        if fileid is not None:
             self._fileid = fileid
 
     def __getattr__(self, name):
@@ -175,7 +174,10 @@
             self._filelog = self._repo.file(self._path)
             return self._filelog
         elif name == '_changeid':
-            self._changeid = self._filelog.linkrev(self._filenode)
+            if '_changectx' in self.__dict__:
+                self._changeid = self._changectx.rev()
+            else:
+                self._changeid = self._filelog.linkrev(self._filenode)
             return self._changeid
         elif name == '_filenode':
             if '_fileid' in self.__dict__:
@@ -229,6 +231,8 @@
     def rev(self):
         if '_changectx' in self.__dict__:
             return self._changectx.rev()
+        if '_changeid' in self.__dict__:
+            return self._changectx.rev() 
         return self._filelog.linkrev(self._filenode)
 
     def node(self): return self._changectx.node()
--- a/tests/test-issue672.out	Sat Jan 05 17:36:16 2008 +0100
+++ b/tests/test-issue672.out	Sat Dec 29 16:57:43 2007 +0300
@@ -45,7 +45,7 @@
  1: remote moved to 1a -> m
 copying 1 to 1a
 merging 1 and 1a
-my 1@746e9549ea96+ other 1a@2f8037f47a5c ancestor 1@81f4b099af3d
+my 1@746e9549ea96+ other 1a@ac7575e3c052 ancestor 1@81f4b099af3d
 removing 1
 0 files updated, 1 files merged, 0 files removed, 0 files unresolved
 (branch merge, don't forget to commit)