From: "Jukka Zitting" <jukka.zitting@gmail.com>
To: git@vger.kernel.org
Subject: git-svn and "svn move" of an entire project
Date: Mon, 15 Dec 2008 00:14:37 +0100 [thread overview]
Message-ID: <510143ac0812141514k28f6dcd4y57bc50600205cd7c@mail.gmail.com> (raw)
Hi,
I'm hosting git-svn mirrors of many Apache projects [1] and every now
and then I need to deal with cases where an entire project (trunk,
tags, branches, everything) is moved from one location to another
within the svn server. For example in revision 723328 [2] the Apache
Abdera project was moved from incubator/abdera to just abdera.
At [3] I found instructions on how to cope with such situations when
git-svn is used to follow only the svn trunk of a project. Based on
that I came up with the bash script below that allows me to update a
full (init -s) git-svn mirror to point to a new location in svn.
The script seems to work fine but I'm wondering if there's an easier
way to achieve this (and if there are any obvious mistakes in my
script). One alternative is of course to recreate the full git-svn
mirror, but that risks breaking the git history if someone has
meanwhile modified a commit message in svn or changed an author name.
Ideally I'd just run "git svn init" again with the new location and
let git-svn take care of the rest. Unfortunately that doesn't seem to
work and I'm not familiar enough with git-svn internals to know where
to start implementing something like this.
[1] http://jukka.zitting.name/git/
[2] http://svn.apache.org/viewvc?view=rev&revision=723328
[3] http://duncan.mac-vicar.com/blog/archives/282
BR,
Jukka Zitting
----
#!/bin/bash
# Location of the authors file
AUTHORS=/home/jukka/git/authors.txt
# Example:
# move-svn-project.sh /var/git/abdera.git 723328 incubator/abdera abdera
DIR=$1
REV=$2
OLD=$3
NEW=$4
# Set GIT_DIR so all git commands know which repo to use
export GIT_DIR=$DIR
# This function is the main workhorse of this script.
# It takes an existing git-svn branch and updates it
# to point to the first corresponding post-move revision
# in svn. If the branch no longer exists in svn, it is
# removed from here as well.
map() {
REF=$1
URL=$2
echo "Mapping $REF to $URL"
# Keep a backup copy of the original git-svn metadata
cp "$GIT_DIR/svn/.metadata" "$GIT_DIR/svn/.metadata.bak"
# Set up a temporary git-svn remote for just this subtree
git svn init -R tmp -i tmp-git-svn-map-branch "$URL"
# Get the first post-move version of this subtree and modify the branch
git svn fetch -r "$REV" --authors-file "$AUTHORS" tmp
if git rev-parse --verify --quiet refs/remotes/tmp-git-svn-map-branch; then
git update-ref "$REF" refs/remotes/tmp-git-svn-map-branch
else
git update-ref -d "$REF"
fi
# Remove all the temporary git-svn settings
git update-ref -d refs/remotes/tmp-git-svn-map-branch
git config --remove-section svn-remote.tmp
rm -rf $GIT_DIR/svn/tmp-git-svn-map-branch
mv $GIT_DIR/svn/.metadata.bak $GIT_DIR/svn/.metadata
}
# Map all git-svn branches to corresponding new URLs
BASE=$(git config svn-remote.svn.url)
git for-each-ref refs/remotes | cut -d / -f 3- | while read REF; do
case "$REF" in
*@*)
echo "Skipping $REF"
;;
trunk)
map "refs/remotes/trunk" "$BASE/$NEW/trunk"
;;
tags/*)
map "refs/remotes/$REF" "$BASE/$NEW/$REF"
;;
*)
map "refs/remotes/$REF" "$BASE/$NEW/branches/$REF"
;;
esac
done
# Update git-svn configuration to point to the new URLs
for NAME in fetch branches tags; do
VALUE="$(git config svn-remote.svn.$NAME)"
git config "svn-remote.svn.$NAME" "${VALUE/#$OLD/$NEW}"
done
# Clean the old git-svn directory, it'll be regenerated on next update
rm -r "$GIT_DIR/svn"
reply other threads:[~2008-12-14 23:16 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=510143ac0812141514k28f6dcd4y57bc50600205cd7c@mail.gmail.com \
--to=jukka.zitting@gmail.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).