git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Thomas Rast <trast@student.ethz.ch>
To: Jeffrey Phillips Freeman <jeffrey.freeman@syncleus.com>
Cc: <git@vger.kernel.org>, Johannes Sixt <j6t@kdbg.org>,
	Jens Lehmann <Jens.Lehmann@web.de>
Subject: Re: [RFC PATCH 3/3] filter-branch: support --submodule-filter
Date: Tue, 4 Jan 2011 14:14:19 +0100	[thread overview]
Message-ID: <201101041414.19587.trast@student.ethz.ch> (raw)
In-Reply-To: <4D225F63.1040502@syncleus.com>

Please don't top-post.  (There's nothing wrong with snipping the whole
message if it does not really relate, as in this case.)

Ccs for the patch at the end; I don't really care much but I could
roll all of it into a sort of "submodule tools" series for g-f-b, so
if you like it, speak up.

Jeffrey Phillips Freeman wrote:
> So im kinda new with all this so bare with me guys. I wanted to figure 
> out how to apply these patches, now i know i can use git to do this with 
> its patch command and such. However i was curious does this exist as a 
> branch somewhere official or semi-official?

Not really.

You can dig through the mailing list archives and also e.g.
gitworkflows to see how Junio handles incoming patches, but for series
like this you usually have to apply them yourself.  I deliberately
flagged it RFC because I wanted to get some feedback ... and because I
would have had to spend more time on it for docs&tests.

> I currently seem to be using
> --split-submodule which is itself in a git repo i have (which i want to 
> also find its source repo so i can keep up to date with it).

For others reading this, I wrote --split-submodule also based on an
IRC request from Jeffrey.  The patch is at the end.  But it's way less
thought through than the --{dump,load}-map feature.  In particular
I've been wondering whether it's possible to use the latter to
implement --split-submodule as a fairly concise index filter.

> So applying 
> the patch itself might be somewhat troubling due to conflicts, therefore 
> id like to actually merge in a remote branch to keep things easy. So can 
> you guys point me to which repo would be best for me to keep up to date 
> with this would be?

You'll get the same conflicts from merging two little branches with
the features on them as with a 'git am -3'.

Many patches are never pushed to a public repo (there are some notable
exceptions in longer-running work).  The hassle of sending and
applying email is far outweighed by the ease of review.  Many reviews
happen without applying the series at all.  That I pushed both of them
to a public repo was an exception for your convenience.


--- 8< ---
Subject: TOY PATCH: filter-branch --split-submodule

Sometimes it makes sense to split out a path not as a subdirectory
(that would be merged by subtree-merge), but as a submodule.  Since
git objects are just shaped in the right way, this is actually quite
easy to do in a way that maintains the correct history relations:

When splitting out DIR in commit C, the submodule commit has tree
C:DIR and the rewritten superproject commit C' gets a submodule entry
at C:DIR instead.

Parent rewriting is done in the obvious way: submodule commits have
their corresponding submodule-changing ancestors as parents.  These
are easy to fetch since we can basically use $(map C^):DIR.

This is a toy patch because of its terrible interface: you will still
have to put the submodule in place.  As a start, you can

  git clone . DIR
  ( cd DIR && git reset --hard $(git rev-parse :DIR) )

to get a sub-repo set to the correct commit.

Signed-off-by: Thomas Rast <trast@student.ethz.ch>

diff --git a/git-filter-branch.sh b/git-filter-branch.sh
index 962a93b..329d85c 100755
--- a/git-filter-branch.sh
+++ b/git-filter-branch.sh
@@ -191,6 +191,9 @@ do
 		filter_subdir="$OPTARG"
 		remap_to_ancestor=t
 		;;
+	--split-submodule)
+		split_submodule="$OPTARG"
+		;;
 	--original)
 		orig_namespace=$(expr "$OPTARG/" : '\(.*[^/]\)/*$')/
 		;;
@@ -349,6 +352,43 @@ while read commit parents; do
 	eval "$filter_index" < /dev/null ||
 		die "index filter failed: $filter_index"
 
+	if test -n "$split_submodule"; then
+		sub_differs=
+		sub_parents=
+		sub_commit=
+		submodule="$(git rev-parse --verify $commit:$split_submodule 2>/dev/null)"
+		if test -z "$parents"; then
+			if test -n "$submodule"; then
+				sub_differs=t
+			fi
+		fi
+		for parent in $parents; do
+			if ! test "$(git rev-parse --verify $parent:$split_submodule 2>/dev/null)" = "$submodule"; then
+				sub_differs=t
+			fi
+			for reparent in $(map "$parent"); do
+				p="$(git rev-parse --verify $reparent:$split_submodule 2>/dev/null)"
+				if test -n "$p"; then
+					sub_parents="$sub_parents -p $p"
+				fi
+			done
+		done
+		if test -n "$sub_differs"; then
+			sub_commit="$(sed -e '1,/^$/d' <../commit |
+				      git commit-tree $submodule $sub_parents)" || exit
+		else
+			for parent in $parents; do
+				sub_commit="$(git rev-parse --verify "$(map "$parent")":$split_submodule 2>/dev/null)"
+				break
+			done
+		fi
+		if test -n "$sub_commit"; then
+			git update-index --add --replace --cacheinfo 160000 $sub_commit "$split_submodule" || exit
+		else
+			git update-index --remove "$split_submodule"
+		fi
+	fi
+
 	parentstr=
 	for parent in $parents; do
 		for reparent in $(map "$parent"); do

-- 
Thomas Rast
trast@{inf,student}.ethz.ch

  reply	other threads:[~2011-01-04 13:14 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-12-31 15:29 [RFC PATCH 0/3] Submodule filtering for filter-branch Thomas Rast
2010-12-31 15:29 ` [RFC PATCH 1/3] filter-branch: optionally dump all mappings at the end Thomas Rast
2010-12-31 17:09   ` Johannes Sixt
2010-12-31 15:29 ` [RFC PATCH 2/3] filter-branch: optionally load existing mappings prior to filtering Thomas Rast
2010-12-31 17:10   ` Johannes Sixt
2010-12-31 15:29 ` [RFC PATCH 3/3] filter-branch: support --submodule-filter Thomas Rast
2010-12-31 17:31   ` Johannes Sixt
2011-01-03 23:44   ` Jeffrey Phillips Freeman
2011-01-04 13:14     ` Thomas Rast [this message]
2011-01-04 19:18       ` Junio C Hamano
2010-12-31 17:20 ` [RFC PATCH 0/3] Submodule filtering for filter-branch Johannes Sixt

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=201101041414.19587.trast@student.ethz.ch \
    --to=trast@student.ethz.ch \
    --cc=Jens.Lehmann@web.de \
    --cc=git@vger.kernel.org \
    --cc=j6t@kdbg.org \
    --cc=jeffrey.freeman@syncleus.com \
    /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).