Add source-tracking revprop's
authorTony Duckles <tony@nynim.org>
Sat, 7 Jan 2012 05:20:30 +0000 (23:20 -0600)
committerTony Duckles <tony@nynim.org>
Sat, 7 Jan 2012 05:22:14 +0000 (23:22 -0600)
svn2svn.py
tests/make-replay-repo.sh

index 93c461e41f1d7a1e7e420eb13171f64173d3fe33..069b2862ec240765f4f48bfcc02d61aefed39b36 100755 (executable)
@@ -166,6 +166,7 @@ def parse_svn_info_xml(xml_string):
         d['url'] = entry.find('url').text
         d['revision'] = int(entry.get('revision'))
         d['repos_url'] = tree.find('.//repository/root').text
+        d['repos_uuid'] = tree.find('.//repository/uuid').text
         d['last_changed_rev'] = int(tree.find('.//commit').get('revision'))
         d['kind'] = entry.get('kind')
     return d
@@ -725,7 +726,7 @@ def process_svn_log_entry(log_entry, source_repos_url, source_url, target_url):
 
     return commit_paths
 
-def pull_svn_rev(log_entry, source_repos_url, source_url, target_url, keep_author=False):
+def pull_svn_rev(log_entry, source_repos_url, source_repos_uuid, source_url, target_url, keep_author=False):
     """
     Pull SVN changes from the given log entry.
     Returns the new SVN revision.
@@ -791,6 +792,11 @@ def pull_svn_rev(log_entry, source_repos_url, source_url, target_url, keep_autho
         #    commit_from_svn_log_entry(log_entry, commit_paths, keep_author=keep_author)
         #else:
             raise ExternalCommandFailed
+
+    # Add source-tracking revprop's
+    run_svn(["propset", "--revprop", "-r", "HEAD", "svn2svn:source_uuid", source_repos_uuid])
+    run_svn(["propset", "--revprop", "-r", "HEAD", "svn2svn:source_url", source_repos_url])
+    run_svn(["propset", "--revprop", "-r", "HEAD", "svn2svn:source_rev", svn_rev])
     print "(Finished source rev #"+str(svn_rev)+")"
 
 
@@ -819,6 +825,10 @@ def main():
     # Find the greatest_rev in the source repo
     svn_info = get_svn_info(source_url)
     greatest_rev = svn_info['revision']
+    # Get the base URL for the source repos, e.g. u'svn://svn.example.com/svn/repo'
+    source_repos_url = svn_info['repos_url']
+    # Get the UUID for the source repos
+    source_repos_uuid = svn_info['repos_uuid']
 
     dup_wc = "_dup_wc"
 
@@ -878,6 +888,10 @@ def main():
             run_svn(["export", "--force", "-r" , str(svn_rev), source_url+"/"+path+"@"+str(svn_rev), path])
             run_svn(["add", path])
         commit_from_svn_log_entry(svn_start_log, [], keep_author)
+        # Add source-tracking revprop's
+        run_svn(["propset", "--revprop", "-r", "HEAD", "svn2svn:source_uuid", source_repos_uuid])
+        run_svn(["propset", "--revprop", "-r", "HEAD", "svn2svn:source_url", source_repos_url])
+        run_svn(["propset", "--revprop", "-r", "HEAD", "svn2svn:source_rev", svn_rev])
     else:
         dup_wc = os.path.abspath(dup_wc)
         os.chdir(dup_wc)
@@ -886,19 +900,13 @@ def main():
         if svn_rev < 1:
             display_error("Invalid arguments\n\nNeed to pass result rev # (-r) when using continue-mode (-c)", False)
 
-
-    # Get SVN info
-    svn_info = get_svn_info(source_url)
-    # Get the base URL for the source repos, e.g. u'svn://svn.example.com/svn/repo'
-    source_repos_url = svn_info['repos_url']
-
     # Load SVN log starting from svn_rev + 1
     it_log_entries = iter_svn_log_entries(source_url, svn_rev + 1, greatest_rev)
 
     try:
         for log_entry in it_log_entries:
             # Replay this revision from source_url into target_url
-            pull_svn_rev(log_entry, source_repos_url, source_url, target_url, keep_author)
+            pull_svn_rev(log_entry, source_repos_url, source_repos_uuid, source_url, target_url, keep_author)
             # Update our target working-copy, to ensure everything says it's at the new HEAD revision
             run_svn(["up", dup_wc])
 
index 2671b1524365202c4dfba8f01b564e71c1b0e746..a1f582e6d081b93228bb0d61a5496869d0dcd924 100755 (executable)
@@ -12,6 +12,83 @@ rm -rf $REPO _dup_wc
 # Init repo
 echo "Creating _repo_replay..."
 svnadmin create $REPO
+# Add pre-revprop-change hook script, which is required by svn2svn
+cat > $REPO/hooks/pre-revprop-change << EOF
+#!/bin/sh
+
+# PRE-REVPROP-CHANGE HOOK
+
+# The pre-revprop-change hook is invoked before a revision property
+# is added, modified or deleted.  Subversion runs this hook by invoking
+# a program (script, executable, binary, etc.) named 'pre-revprop-change'
+# (for which this file is a template), with the following ordered
+# arguments:
+#
+#   [1] REPOS-PATH   (the path to this repository)
+#   [2] REVISION     (the revision being tweaked)
+#   [3] USER         (the username of the person tweaking the property)
+#   [4] PROPNAME     (the property being set on the revision)
+#   [5] ACTION       (the property is being 'A'dded, 'M'odified, or 'D'eleted)
+#
+#   [STDIN] PROPVAL  ** the new property value is passed via STDIN.
+#
+# If the hook program exits with success, the propchange happens; but
+# if it exits with failure (non-zero), the propchange doesn't happen.
+# The hook program can use the 'svnlook' utility to examine the
+# existing value of the revision property.
+#
+# WARNING: unlike other hooks, this hook MUST exist for revision
+# properties to be changed.  If the hook does not exist, Subversion
+# will behave as if the hook were present, but failed.  The reason
+# for this is that revision properties are UNVERSIONED, meaning that
+# a successful propchange is destructive;  the old value is gone
+# forever.  We recommend the hook back up the old value somewhere.
+#
+# On a Unix system, the normal procedure is to have 'pre-revprop-change'
+# invoke other programs to do the real work, though it may do the
+# work itself too.
+#
+# Note that 'pre-revprop-change' must be executable by the user(s) who will
+# invoke it (typically the user httpd runs as), and that user must
+# have filesystem-level permission to access the repository.
+#
+# On a Windows system, you should name the hook program
+# 'pre-revprop-change.bat' or 'pre-revprop-change.exe',
+# but the basic idea is the same.
+#
+# The hook program typically does not inherit the environment of
+# its parent process.  For example, a common problem is for the
+# PATH environment variable to not be set to its usual value, so
+# that subprograms fail to launch unless invoked via absolute path.
+# If you're having unexpected problems with a hook program, the
+# culprit may be unusual (or missing) environment variables.
+#
+# Here is an example hook script, for a Unix /bin/sh interpreter.
+# For more examples and pre-written hooks, see those in
+# the Subversion repository at
+# http://svn.apache.org/repos/asf/subversion/trunk/tools/hook-scripts/ and
+# http://svn.apache.org/repos/asf/subversion/trunk/contrib/hook-scripts/
+
+REPOS="\$1"
+REV="\$2"
+USER="\$3"
+PROPNAME="\$4"
+ACTION="\$5"
+
+echo "pre-revprop-change: REPOS=\$1 REV=\$2 USER=\$3 PROPNAME=\$4 ACTION=\$5" >&2
+
+if [ "\$ACTION" = "M" -a "\$PROPNAME" = "svn:log" ]; then exit 0; fi
+if [ "\$ACTION" = "A" -a "\$PROPNAME" = "svn2svn:source_uuid" ]; then exit 0; fi
+if [ "\$ACTION" = "M" -a "\$PROPNAME" = "svn2svn:source_uuid" ]; then exit 0; fi
+if [ "\$ACTION" = "A" -a "\$PROPNAME" = "svn2svn:source_url" ]; then exit 0; fi
+if [ "\$ACTION" = "M" -a "\$PROPNAME" = "svn2svn:source_url" ]; then exit 0; fi
+if [ "\$ACTION" = "A" -a "\$PROPNAME" = "svn2svn:source_rev" ]; then exit 0; fi
+if [ "\$ACTION" = "M" -a "\$PROPNAME" = "svn2svn:source_rev" ]; then exit 0; fi
+
+echo "Changing revision property \$PROPNAME is prohibited" >&2
+exit 1
+EOF
+chmod 755 $REPO/hooks/pre-revprop-change
 svn mkdir -q -m "Add /trunk" $REPOURL/trunk
 
 # svn2svn