git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [RFC PATCH 3/3] filter-branch: support --submodule-filter

From
Junio C Hamano <gitster@pobox.com>
Date
Jan 4, 2011, 19:18 UTC
Message-ID
<7vfwt8fpfb.fsf@alter.siamese.dyndns.org>
In-Reply-To
<201101041414.19587.trast@student.ethz.ch>
Thomas Rast <trast@student.ethz.ch> writes:
Show 6 quoted lines
> 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:
The patch from a cursory look feels sane.
Show 8 quoted lines
> @@ -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=
Just a style, but I find
	if test -n "$split_submodule"
        then
        	sub_differs= sub_parents= sub_commit=

easier to read. Not a biggie, as the neighbourhood in the script already is infested in the other style, but I thought I'd mention it.

> +		submodule="$(git rev-parse --verify $commit:$split_submodule 2>/dev/null)"
Do we need double quotes around it?
Show 5 quoted lines
> +		if test -z "$parents"; then
> +			if test -n "$submodule"; then
> +				sub_differs=t
> +			fi
> +		fi
	if test -z "$parents" && test -n "$submodule"
        then
        	sub_differs=t
	fi
> +		for parent in $parents; do
> +			if ! test "$(git rev-parse --verify $parent:$split_submodule 2>/dev/null)" = "$submodule"; then
> +				sub_differs=t
> +			fi
If even one of the parents is different, we say "differs"...
Show 7 quoted lines
> +		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

... so we can just pick from the first parent and know all of them are the same (could be empty which also is fine). Good.

Previous: Thomas RastNext: Johannes Sixt
Message 10 of 11 in “Submodule filtering for filter-branch”
  1. 0/3 Submodule filtering for filter-branchThomas Rast, Dec 31, 2010
  2. 1/3 filter-branch: optionally dump all mappings at the endThomas Rast, Dec 31, 2010
  3. Johannes SixtDec 31, 2010
  4. 2/3 filter-branch: optionally load existing mappings prior to filteringThomas Rast, Dec 31, 2010
  5. Johannes SixtDec 31, 2010
  6. 3/3 filter-branch: support --submodule-filterThomas Rast, Dec 31, 2010
  7. Johannes SixtDec 31, 2010
  8. Jeffrey Phillips FreemanJan 3, 2011
  9. Thomas RastJan 4, 2011
  10. Junio C HamanoJan 4, 2011
  11. Johannes SixtDec 31, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.