[PATCH] transplant: remove the restriction that the destination repository be nonempty.

Jacob Lee artdent at gmail.com
Fri Apr 24 21:41:06 CDT 2009


I recently wanted to transplant an entire repository to run a filter
on it to remove some sensitive information that accidentally got
committed. I was thus trying to transplant from elsewhere into an
empty repository, but the transplant extension forbade that. I removed
the restriction with no ill effects; here is the patch and a test.

# HG changeset patch
# User Jacob Lee <artdent at gmail.com>
# Date 1240610418 18000
# Node ID d72517ad3ca62c4505ab0bce06a6a9915b75dabb
# Parent  4f13ed6ee5448cf5de72446f2b6a418e33f691da
transplant: remove the restriction that the destination repository be nonempty.

diff -r 4f13ed6ee544 -r d72517ad3ca6 hgext/transplant.py
--- a/hgext/transplant.py	Thu Apr 23 15:40:10 2009 -0500
+++ b/hgext/transplant.py	Fri Apr 24 17:00:18 2009 -0500
@@ -528,8 +528,6 @@
     tp = transplanter(ui, repo)

     p1, p2 = repo.dirstate.parents()
-    if p1 == revlog.nullid:
-        raise util.Abort(_('no revision checked out'))
     if not opts.get('continue'):
         if p2 != revlog.nullid:
             raise util.Abort(_('outstanding uncommitted merges'))
diff -r 4f13ed6ee544 -r d72517ad3ca6 tests/test-transplant
--- a/tests/test-transplant	Thu Apr 23 15:40:10 2009 -0500
+++ b/tests/test-transplant	Fri Apr 24 17:00:18 2009 -0500
@@ -114,3 +114,24 @@
 echo % tranplant
 hg transplant -m 1
 cd ..
+
+echo '% test transplant into empty repository'
+hg init empty
+cd empty
+hg transplant -s ../t -b tip -a
+cd ..
+
+echo '% test filter'
+hg init filter
+cd filter
+cat <<EOF >test-filter
+#!/bin/sh
+
+echo "$1"
+echo "$2"
+sed 's/r1/r2/' $1 > $1.new
+mv $1.new $1
+EOF
+chmod +x test-filter
+hg transplant -s ../t -b tip -a --filter ./test-filter
+hg log --template '{rev} {parents} {desc}\n'
diff -r 4f13ed6ee544 -r d72517ad3ca6 tests/test-transplant.out
--- a/tests/test-transplant.out	Thu Apr 23 15:40:10 2009 -0500
+++ b/tests/test-transplant.out	Fri Apr 24 17:00:18 2009 -0500
@@ -136,3 +136,9 @@
 % tranplant
 applying 42dc4432fd35
 1:42dc4432fd35 merged at a9f4acbac129
+% test transplant into empty repository
+requesting all changes
+adding changesets
+adding manifests
+adding file changes
+added 4 changesets with 4 changes to 4 files

-- 
Jacob Lee
artdent at gmail.com


More information about the Mercurial-devel mailing list