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

5 messages from 2012-10-02 to 2012-10-12. Participants: Andrew Wong.
Thread: https://gitlist.dev/t/31715

## Andrew Wong, 2012-10-02 16:25

Subject: [PATCH] git-gui: Few issues with using full path name
Message-ID: <1349195115-15494-1-git-send-email-andrew.kw.w@gmail.com>
URL: https://gitlist.dev/e/1349195115-15494-1-git-send-email-andrew.kw.w%40gmail.com

```
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, 2012-10-02 16:25

Subject: [PATCH 1/2] git-gui: Detect full path when parsing arguments
Message-ID: <1349195115-15494-2-git-send-email-andrew.kw.w@gmail.com>
URL: https://gitlist.dev/e/1349195115-15494-2-git-send-email-andrew.kw.w%40gmail.com
In-Reply-To: <1349195115-15494-1-git-send-email-andrew.kw.w@gmail.com>

```
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(-)

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, 2012-10-02 16:25

Subject: [PATCH 2/2] git-gui: Don't prepend the prefix if value looks like a full path
Message-ID: <1349195115-15494-3-git-send-email-andrew.kw.w@gmail.com>
URL: https://gitlist.dev/e/1349195115-15494-3-git-send-email-andrew.kw.w%40gmail.com
In-Reply-To: <1349195115-15494-1-git-send-email-andrew.kw.w@gmail.com>

```
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(-)

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, 2012-10-07 21:25

Subject: Re: [PATCH] git-gui: Few issues with using full path name
Message-ID: <5071F340.6030206@gmail.com>
URL: https://gitlist.dev/e/5071F340.6030206%40gmail.com
In-Reply-To: <1349195115-15494-1-git-send-email-andrew.kw.w@gmail.com>

```
Could we look into getting these two patches into git/git-gui?

On 10/02/12 12:25, Andrew Wong wrote:
> 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, 2012-10-12 14:08

Subject: Re: [PATCH] git-gui: Few issues with using full path name
Message-ID: <50782442.2060407@gmail.com>
URL: https://gitlist.dev/e/50782442.2060407%40gmail.com
In-Reply-To: <1349195115-15494-1-git-send-email-andrew.kw.w@gmail.com>

```
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:
> 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(-)
>

```
