Package: git
Version: 1:1.7.1-1
Severity: wishlist
A few months ago, I needed to rewrite a repo by moving it to a
subdirectory; I ended up (crudely) patching git-filter-branch to add a
--prefix option, doing the opposite of --subdirectory-filter. I think
this could be useful to other people as well.
I'm attaging the diff for archeological purposes, in case this could be
of help to someone. It's not a suitable patch, as I lazily removed
git-read-tree's "-m" option (which is incompatible with --prefix)
instead of properly adding yet another if() level. It was a one-time
job, so I didn't strive for correctness. :)
-- System Information:
Debian Release: squeeze/sid
APT prefers unstable
APT policy: (500, 'unstable')
Architecture: i386 (i686)
Kernel: Linux 2.6.33 (SMP w/1 CPU core)
Locale: LANG=en_CA.UTF-8, LC_CTYPE=en_CA.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Versions of packages git depends on:
ii libc6 2.10.2-9 Embedded GNU C Library: Shared lib
ii libcurl3-gnutls 7.20.1-2 Multi-protocol file transfer libra
ii libdigest-sha1-perl 2.12-1 NIST SHA-1 message digest algorith
ii liberror-perl 0.17-1 Perl module for error/exception ha
ii libexpat1 2.0.1-7 XML parsing C library - runtime li
ii perl-modules 5.10.1-12 Core Perl modules
ii zlib1g 1:1.2.3.4.dfsg-3 compression library - runtime
Versions of packages git recommends:
ii less 436-1 pager program similar to more
ii openssh-client [ssh-client] 1:5.5p1-4 secure shell (SSH) client, for sec
ii patch 2.6-2 Apply a diff file to an original
ii rsync 3.0.7-2 fast remote file copy program (lik
Versions of packages git suggests:
pn git-arch <none> (no description available)
ii git-cvs 1:1.7.1-1 fast, scalable, distributed revisi
pn git-daemon-run <none> (no description available)
pn git-doc <none> (no description available)
ii git-email 1:1.7.1-1 fast, scalable, distributed revisi
pn git-gui <none> (no description available)
ii git-svn 1:1.7.1-1 fast, scalable, distributed revisi
ii gitk 1:1.7.1-1 fast, scalable, distributed revisi
pn gitweb <none> (no description available)
-- no debconf information
diff --git a/git-filter-branch b/git-filter-branch
index 1f7f2d6..563d123 100755
--- a/git-filter-branch
+++ b/git-filter-branch
@@ -101,6 +101,7 @@ USAGE="[--env-filter <command>] [--tree-filter <command>]
[--index-filter <command>] [--parent-filter <command>]
[--msg-filter <command>] [--commit-filter <command>]
[--tag-name-filter <command>] [--subdirectory-filter <directory>]
+ [--prefix <prefix>]
[--original <namespace>] [-d <directory>] [-f | --force]
[<rev-list options>...]"
@@ -122,6 +123,7 @@ filter_msg=cat
filter_commit=
filter_tag_name=
filter_subdir=
+prefix=
orig_namespace=refs/original/
force=
prune_empty=
@@ -190,6 +192,9 @@ do
filter_subdir="$OPTARG"
remap_to_ancestor=t
;;
+ --prefix)
+ prefix="$OPTARG"
+ ;;
--original)
orig_namespace=$(expr "$OPTARG/" : '\(.*[^/]\)/*$')/
;;
@@ -292,13 +297,17 @@ while read commit parents; do
git_filter_branch__commit_count=$(($git_filter_branch__commit_count+1))
printf "\rRewrite $commit ($git_filter_branch__commit_count/$commits)"
+ if [ "$prefix" ]; then
+ rm -f "$GIT_INDEX_FILE"
+ fi
+
case "$filter_subdir" in
"")
- git read-tree -i -m $commit
+ git read-tree -i --prefix "$prefix" $commit
;;
*)
# The commit may not have the subdirectory at all
- err=$(git read-tree -i -m $commit:"$filter_subdir" 2>&1) || {
+ err=$(git read-tree -i --prefix "$prefix" $commit:"$filter_subdir" 2>&1) || {
if ! git rev-parse -q --verify $commit:"$filter_subdir"
then
rm -f "$GIT_INDEX_FILE"