threads / patch / 31715

patch, 2 partsgit-gui: Don't prepend the prefix if value looks like a full path

Subject: [PATCH 2/2] git-gui: Don't prepend the prefix if value looks like a full path

## tl;dr

5 messages between Oct 2, 2012 and Oct 12, 2012. Diffs are folded; open one to read it.

replies: 4people: 1as markdown or json

Andrew Wong· Oct 2, 2012, 16:25 UTC · lore

[PATCH] git-gui: Few issues with using full path name

I ran into a file name parsing issue in git-gui. If I'm in a subfolder and try to pass a full path to "git-gui blame", then "git-gui" will fail to detect the argument as a valid path. The first patch will handle this scenario.

The second patch just another issue that I noticed when "git-gui" fails to detect the file name. It'll then try to use the previously detected "head" as the file name, while prepending it with "prefix". This is incorrect if "head" is actually a full path.

There is also an issue when using a full path along with a rev argument, but I don't have time to look it right now. I'll try to get to that issue another time.

Andrew Wong (2):
  git-gui: Detect full path when parsing arguments
  git-gui: Don't prepend the prefix if value looks like a full path
 git-gui.sh | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)
-- 
1.7.12.1.382.gb0576a6
Andrew Wong· Oct 2, 2012, 16:25 UTC · re: Andrew Wong · lore

[PATCH 1/2] git-gui: Detect full path when parsing arguments

When running "git-gui blame" from a subfolder (which means prefix is non-empty), if we pass a full path as argument, the argument parsing will fail to recognize the argument as a file name, because prefix is prepended to the argument.

This patch handles that scenario by adding an additional branch that checks the file name without using the prefix.

Signed-off-by: Andrew Wong <andrew.kw.w@gmail.com>
---
 git-gui.sh | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
Show changes to git-gui.sh +10 −1
diff --git a/git-gui.sh b/git-gui.sh
index 5d035d5..5d7894b 100755
--- a/git-gui.sh
+++ b/git-gui.sh
@@ -3003,10 +3003,19 @@ blame {
 	set jump_spec {}
 	set is_path 0
 	foreach a $argv {
-		if {$is_path || [file exists $_prefix$a]} {
+		if {[file exists $a]} {
+			if {$path ne {}} usage
+			set path [normalize_relpath $a]
+			break
+		} elseif {[file exists $_prefix$a]} {
 			if {$path ne {}} usage
 			set path [normalize_relpath $_prefix$a]
 			break
+		}
+
+		if {$is_path} {
+			if {$path ne {}} usage
+			break
 		} elseif {$a eq {--}} {
 			if {$path ne {}} {
 				if {$head ne {}} usage
-- 
1.7.12.1.382.gb0576a6
Andrew Wong· Oct 2, 2012, 16:25 UTC · re: Andrew Wong · lore

When argument parsing fails to detect a file name, "git-gui" will try to use the previously detected "head" as the file name. We should avoid prepending the prefix if "head" looks like a full path.

Signed-off-by: Andrew Wong <andrew.kw.w@gmail.com>
---
 git-gui.sh | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
Show changes to git-gui.sh +7 −2
diff --git a/git-gui.sh b/git-gui.sh
index 5d7894b..89f636f 100755
--- a/git-gui.sh
+++ b/git-gui.sh
@@ -3037,8 +3037,13 @@ blame {
 	unset is_path
 
 	if {$head ne {} && $path eq {}} {
-		set path [normalize_relpath $_prefix$head]
-		set head {}
+		if {[string index $head 0] eq {/}} {
+			set path [normalize_relpath $head]
+			set head {}
+		} else {
+			set path [normalize_relpath $_prefix$head]
+			set head {}
+		}
 	}
 
 	if {$head eq {}} {
-- 
1.7.12.1.382.gb0576a6
Andrew Wong· Oct 7, 2012, 21:25 UTC · re: Andrew Wong · lore

Re: [PATCH] git-gui: Few issues with using full path name

Could we look into getting these two patches into git/git-gui?
On 10/02/12 12:25, Andrew Wong wrote:
Show 20 quoted lines
> I ran into a file name parsing issue in git-gui. If I'm in a subfolder and try
> to pass a full path to "git-gui blame", then "git-gui" will fail to detect the
> argument as a valid path. The first patch will handle this scenario.
>
> The second patch just another issue that I noticed when "git-gui" fails to
> detect the file name. It'll then try to use the previously detected "head" as
> the file name, while prepending it with "prefix". This is incorrect if "head"
> is actually a full path.
>
> There is also an issue when using a full path along with a rev argument, but I
> don't have time to look it right now. I'll try to get to that issue another
> time.
>
> Andrew Wong (2):
>   git-gui: Detect full path when parsing arguments
>   git-gui: Don't prepend the prefix if value looks like a full path
>
>  git-gui.sh | 20 +++++++++++++++++---
>  1 file changed, 17 insertions(+), 3 deletions(-)
>
Andrew Wong· Oct 12, 2012, 14:08 UTC · re: Andrew Wong · lore

Re: [PATCH] git-gui: Few issues with using full path name

Can I get some feedback on these two patches? It'd be great to have them merged into git-gui. Thanks.

On 10/02/2012 12:25 PM, Andrew Wong wrote:
Show 20 quoted lines
> I ran into a file name parsing issue in git-gui. If I'm in a subfolder and try
> to pass a full path to "git-gui blame", then "git-gui" will fail to detect the
> argument as a valid path. The first patch will handle this scenario.
>
> The second patch just another issue that I noticed when "git-gui" fails to
> detect the file name. It'll then try to use the previously detected "head" as
> the file name, while prepending it with "prefix". This is incorrect if "head"
> is actually a full path.
>
> There is also an issue when using a full path along with a rev argument, but I
> don't have time to look it right now. I'll try to get to that issue another
> time.
>
> Andrew Wong (2):
>    git-gui: Detect full path when parsing arguments
>    git-gui: Don't prepend the prefix if value looks like a full path
>
>   git-gui.sh | 20 +++++++++++++++++---
>   1 file changed, 17 insertions(+), 3 deletions(-)
>

← back to recent threads