changeset 1747:91c56c427171

transitive copy/rename Add support for transitive copy or rename operations, e.g. hg rename a b ... (possibly edit b) hg rename b c hg commit ... by actually renaming "b" as "c" while recording a copy of "a" to "c" and a removal of "a".
author Robin Farine <robin.farine@terminus.org>
date Sat, 18 Feb 2006 07:37:59 -0800
parents 299c3e26ee45
children 2428e6d66f06 f29857aaa053
files mercurial/commands.py mercurial/localrepo.py tests/test-merge3.out tests/test-rename tests/test-rename.out
diffstat 5 files changed, 34 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/commands.py	Sat Feb 18 16:31:02 2006 +0100
+++ b/mercurial/commands.py	Sat Feb 18 07:37:59 2006 -0800
@@ -818,14 +818,19 @@
         reasons = {'?': _('is not managed'),
                    'a': _('has been marked for add'),
                    'r': _('has been marked for remove')}
-        reason = reasons.get(repo.dirstate.state(abs))
+        state = repo.dirstate.state(abs)
+        reason = reasons.get(state)
         if reason:
+            if state == 'a':
+                origsrc = repo.dirstate.copied(abs)
+                if origsrc is not None:
+                    return origsrc
             if exact:
                 ui.warn(_('%s: not copying - file %s\n') % (rel, reason))
         else:
-            return True
-
-    def copy(abssrc, relsrc, target, exact):
+            return abs
+
+    def copy(origsrc, abssrc, relsrc, target, exact):
         abstarget = util.canonpath(repo.root, cwd, target)
         reltarget = util.pathto(cwd, abstarget)
         prevsrc = targets.get(abstarget)
@@ -864,7 +869,7 @@
         if ui.verbose or not exact:
             ui.status(_('copying %s to %s\n') % (relsrc, reltarget))
         targets[abstarget] = abssrc
-        repo.copy(abssrc, abstarget)
+        repo.copy(origsrc, abstarget)
         copied.append((abssrc, relsrc, exact))
 
     def targetpathfn(pat, dest, srcs):
@@ -938,8 +943,9 @@
     for pat in pats:
         srcs = []
         for tag, abssrc, relsrc, exact in walk(repo, [pat], opts):
-            if okaytocopy(abssrc, relsrc, exact):
-                srcs.append((abssrc, relsrc, exact))
+            origsrc = okaytocopy(abssrc, relsrc, exact)
+            if origsrc:
+                srcs.append((origsrc, abssrc, relsrc, exact))
         if not srcs:
             continue
         copylist.append((tfn(pat, dest, srcs), srcs))
@@ -947,8 +953,8 @@
         raise util.Abort(_('no files to copy'))
 
     for targetpath, srcs in copylist:
-        for abssrc, relsrc, exact in srcs:
-            copy(abssrc, relsrc, targetpath(abssrc), exact)
+        for origsrc, abssrc, relsrc, exact in srcs:
+            copy(origsrc, abssrc, relsrc, targetpath(abssrc), exact)
 
     if errors:
         ui.warn(_('(consider using --after)\n'))
--- a/mercurial/localrepo.py	Sat Feb 18 16:31:02 2006 +0100
+++ b/mercurial/localrepo.py	Sat Feb 18 07:37:59 2006 -0800
@@ -597,7 +597,6 @@
             if os.path.exists(p):
                 self.ui.warn(_("%s still exists!\n") % f)
             elif self.dirstate.state(f) == 'a':
-                self.ui.warn(_("%s never committed!\n") % f)
                 self.dirstate.forget([f])
             elif f not in self.dirstate:
                 self.ui.warn(_("%s not tracked!\n") % f)
--- a/tests/test-merge3.out	Sat Feb 18 16:31:02 2006 +0100
+++ b/tests/test-merge3.out	Sat Feb 18 07:37:59 2006 -0800
@@ -1,3 +1,2 @@
 removing b
-b never committed!
 nothing changed
--- a/tests/test-rename	Sat Feb 18 16:31:02 2006 +0100
+++ b/tests/test-rename	Sat Feb 18 07:37:59 2006 -0800
@@ -158,3 +158,16 @@
 hg rename d1 d3
 hg status
 hg update -C
+
+echo "# transitive rename"
+hg rename d1/b d1/bb
+hg rename d1/bb d1/bc
+hg status
+hg update -C
+
+echo "# transitive rename --after"
+hg rename d1/b d1/bb
+mv d1/bb d1/bc
+hg rename --after d1/bb d1/bc
+hg status
+hg update -C
--- a/tests/test-rename.out	Sat Feb 18 16:31:02 2006 +0100
+++ b/tests/test-rename.out	Sat Feb 18 07:37:59 2006 -0800
@@ -246,3 +246,9 @@
 R d1/b
 R d1/ba
 R d1/d11/a1
+# transitive rename
+A d1/bc
+R d1/b
+# transitive rename --after
+A d1/bc
+R d1/b