threads / patch / 18334

patchtg-patch: fix invocation in sub working tree directory

Subject: [TopGit PATCH] tg-patch: fix invocation in sub working tree directory

## tl;dr

6 messages between Mar 16, 2009 and Mar 17, 2009. Diffs are folded; open one to read it.

replies: 5people: 3as markdown or json

Bert Wesarg· Mar 16, 2009, 22:08 UTC · lore

tg patch won't work in a sub directory of the working tree, because 'git diff --name-only' prints the names relative to the top working tree.

This is only a quick fix which prefixes all file names with 'git rev-parse --show-cdup'. The right solution would be to cd into the top working tree somewhere in tg.sh.

Signed-off-by: Bert Wesarg <bert.wesarg@googlemail.com>
---
 tg-patch.sh |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)
Show changes to tg-patch.sh +6 −1
diff --git a/tg-patch.sh b/tg-patch.sh
index d701c54..e33bab2 100644
--- a/tg-patch.sh
+++ b/tg-patch.sh
@@ -50,13 +50,18 @@ cat_file "$topic:.topmsg"
 echo
 [ -n "$(git grep $diff_opts '^[-]--' ${diff_committed_only:+"$name"} -- ".topmsg")" ] || echo '---'
 
+# if we are in a sub working tree dir, we need to prefix all file names from
+# git diff --name-only with this cdup
+cdup=$(git rev-parse --show-cdup)
+
 # Evil obnoxious hack to work around the lack of git diff --exclude
 git_is_stupid="$(mktemp -t tg-patch-changes.XXXXXX)"
 git diff --name-only $diff_opts "$base_rev" ${diff_committed_only:+"$name"} -- |
 	fgrep -vx ".topdeps" |
 	fgrep -vx ".topmsg" >"$git_is_stupid" || : # fgrep likes to fail randomly?
 if [ -s "$git_is_stupid" ]; then
-	cat "$git_is_stupid" | xargs git diff --patch-with-stat $diff_opts "$base_rev" ${diff_committed_only:+"$name"} --
+	sed -e "s#^#$cdup#" "$git_is_stupid" |
+		xargs git diff --patch-with-stat $diff_opts "$base_rev" ${diff_committed_only:+"$name"} --
 else
 	echo "No changes."
 fi
-- 
tg: (d145a7b..) bw/fix-tg-patch-in-sub-dir (depends on: master)
Junio C Hamano· Mar 16, 2009, 22:33 UTC · re: Bert Wesarg · lore

Re: [TopGit PATCH] tg-patch: fix invocation in sub working tree directory

Bert Wesarg <bert.wesarg@googlemail.com> writes:
> tg patch won't work in a sub directory of the working tree, because 'git diff
> --name-only' prints the names relative to the top working tree.
"diff --relative --name-only"?
Show 23 quoted lines
> This is only a quick fix which prefixes all file names with 'git rev-parse
> --show-cdup'. The right solution would be to cd into the top working tree
> somewhere in tg.sh.
>
> Signed-off-by: Bert Wesarg <bert.wesarg@googlemail.com>
>
> ---
>  tg-patch.sh |    7 ++++++-
>  1 files changed, 6 insertions(+), 1 deletions(-)
>
> diff --git a/tg-patch.sh b/tg-patch.sh
> index d701c54..e33bab2 100644
> --- a/tg-patch.sh
> +++ b/tg-patch.sh
> @@ -50,13 +50,18 @@ cat_file "$topic:.topmsg"
>  echo
>  [ -n "$(git grep $diff_opts '^[-]--' ${diff_committed_only:+"$name"} -- ".topmsg")" ] || echo '---'
>  
> +# if we are in a sub working tree dir, we need to prefix all file names from
> +# git diff --name-only with this cdup
> +cdup=$(git rev-parse --show-cdup)
> ...
> +	sed -e "s#^#$cdup#" "$git_is_stupid" |
Do TopGit folks care about special characters in pathnames?
Bert Wesarg· Mar 16, 2009, 23:25 UTC · re: Junio C Hamano · lore

Re: [TopGit PATCH] tg-patch: fix invocation in sub working tree directory

On Mon, Mar 16, 2009 at 23:33, Junio C Hamano <gitster@pobox.com> wrote:
Show 6 quoted lines
> Bert Wesarg <bert.wesarg@googlemail.com> writes:
>
>> tg patch won't work in a sub directory of the working tree, because 'git diff
>> --name-only' prints the names relative to the top working tree.
>
> "diff --relative --name-only"?

No, unfortunately. In my bug case the changed file was in another subtree, and --relative restricts the output to only files under the current subtree.

Show 26 quoted lines
>
>> This is only a quick fix which prefixes all file names with 'git rev-parse
>> --show-cdup'. The right solution would be to cd into the top working tree
>> somewhere in tg.sh.
>>
>> Signed-off-by: Bert Wesarg <bert.wesarg@googlemail.com>
>>
>> ---
>>  tg-patch.sh |    7 ++++++-
>>  1 files changed, 6 insertions(+), 1 deletions(-)
>>
>> diff --git a/tg-patch.sh b/tg-patch.sh
>> index d701c54..e33bab2 100644
>> --- a/tg-patch.sh
>> +++ b/tg-patch.sh
>> @@ -50,13 +50,18 @@ cat_file "$topic:.topmsg"
>>  echo
>>  [ -n "$(git grep $diff_opts '^[-]--' ${diff_committed_only:+"$name"} -- ".topmsg")" ] || echo '---'
>>
>> +# if we are in a sub working tree dir, we need to prefix all file names from
>> +# git diff --name-only with this cdup
>> +cdup=$(git rev-parse --show-cdup)
>> ...
>> +     sed -e "s#^#$cdup#" "$git_is_stupid" |
>
> Do TopGit folks care about special characters in pathnames?
Do 'git rev-parse --show-cdup' return anything other than slashes and dots?
Bert
Junio C Hamano· Mar 17, 2009, 00:24 UTC · re: Bert Wesarg · lore

Re: [TopGit PATCH] tg-patch: fix invocation in sub working tree directory

Bert Wesarg <bert.wesarg@googlemail.com> writes:
Show 11 quoted lines
> On Mon, Mar 16, 2009 at 23:33, Junio C Hamano <gitster@pobox.com> wrote:
>> Bert Wesarg <bert.wesarg@googlemail.com> writes:
>>
>>> tg patch won't work in a sub directory of the working tree, because 'git diff
>>> --name-only' prints the names relative to the top working tree.
>>
>> "diff --relative --name-only"?
>
> No, unfortunately. In my bug case the changed file was in another
> subtree, and --relative restricts the output to only files under the
> current subtree.

Ah, Ok, then insertion of cdup output does make sense (after all cdup was designed to be used that way).

Uwe Kleine-König· Mar 17, 2009, 08:02 UTC · re: Bert Wesarg · lore

Re: [TopGit PATCH] tg-patch: fix invocation in sub working tree directory

On Mon, Mar 16, 2009 at 11:08:19PM +0100, Bert Wesarg wrote:
> tg patch won't work in a sub directory of the working tree, because 'git diff
> --name-only' prints the names relative to the top working tree.
Hhhm, that's not exactly the problem.
	git diff --patch-with-stat 45c82b5 t/trivial/typo-kernel -- $path
expects $path to be relative to the top working tree.

IMHO this is a strange behaviour of core git when comparing two trees (and not a tree and the wc). Moreover as the output uses "absolute" paths:

	ukleinek@cassiopeia:~/gsrc/linux-2.6/fs$ git diff --patch-with-stat 45c82b5 t/trivial/typo-kernel -- proc/nommu.c | diffstat -p0
 b/fs/proc/nommu.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Best regards Uwe

-- 
Pengutronix e.K.                              | Uwe Kleine-König            |
Industrial Linux Solutions                    | http://www.pengutronix.de/  |
Uwe Kleine-König· Mar 17, 2009, 08:33 UTC · re: Bert Wesarg · lore

Re: [TopGit PATCH] tg-patch: fix invocation in sub working tree directory

Hello again,
On Mon, Mar 16, 2009 at 11:08:19PM +0100, Bert Wesarg wrote:
Show 19 quoted lines
> --- a/tg-patch.sh
> +++ b/tg-patch.sh
> @@ -50,13 +50,18 @@ cat_file "$topic:.topmsg"
>  echo
>  [ -n "$(git grep $diff_opts '^[-]--' ${diff_committed_only:+"$name"} -- ".topmsg")" ] || echo '---'
>  
> +# if we are in a sub working tree dir, we need to prefix all file names from
> +# git diff --name-only with this cdup
> +cdup=$(git rev-parse --show-cdup)
> +
>  # Evil obnoxious hack to work around the lack of git diff --exclude
>  git_is_stupid="$(mktemp -t tg-patch-changes.XXXXXX)"
>  git diff --name-only $diff_opts "$base_rev" ${diff_committed_only:+"$name"} -- |
>  	fgrep -vx ".topdeps" |
>  	fgrep -vx ".topmsg" >"$git_is_stupid" || : # fgrep likes to fail randomly?
>  if [ -s "$git_is_stupid" ]; then
> -	cat "$git_is_stupid" | xargs git diff --patch-with-stat $diff_opts "$base_rev" ${diff_committed_only:+"$name"} --
> +	sed -e "s#^#$cdup#" "$git_is_stupid" |
> +		xargs git diff --patch-with-stat $diff_opts "$base_rev" ${diff_committed_only:+"$name"} --

My not move pretty_tree from tg-export.sh to tg.sh and use that. i.e.

	git diff $someopts "$(pretty_tree "$base_rev")" "$(pretty_tree "...")"

then we wouldn't need that git_is_stupid-hack and the relative path name thinggy wouldn hurt us.

Best regards Uwe

-- 
Pengutronix e.K.                              | Uwe Kleine-König            |
Industrial Linux Solutions                    | http://www.pengutronix.de/  |

← back to recent threads