threads / patch / 11910

patchgitk: properly deal with tag names containing / (slash)

Subject: [PATCH] gitk: properly deal with tag names containing / (slash)

## tl;dr

5 messages between Feb 6, 2008 and Feb 12, 2008. Diffs are folded; open one to read it.

replies: 4people: 3as markdown or json

Gerrit Pape· Feb 6, 2008, 07:06 UTC · lore

When creating a tag through gitk, and the tag name includes a slash (or slashes), gitk errors out in a popup window. This patch makes gitk create the necessary subdirectory(s) to successfully create the tag, and also catches an error if a directory with the tag name to be created already exists.

The problem was reported by Fr�d�ric Bri�re through
 http://bugs.debian.org/464104
Signed-off-by: Gerrit Pape <pape@smarden.org>
---
 gitk-git/gitk |   11 +++++++++--
 1 files changed, 9 insertions(+), 2 deletions(-)
Show changes to gitk-git/gitk +9 −2
diff --git a/gitk-git/gitk b/gitk-git/gitk
index 5560e4d..56a8792 100644
--- a/gitk-git/gitk
+++ b/gitk-git/gitk
@@ -6136,9 +6136,16 @@ proc domktag {} {
 	error_popup [mc "Tag \"%s\" already exists" $tag]
 	return
     }
+    set dir [gitdir]
+    set fname [file join $dir "refs/tags" $tag]
+    if {[file isdirectory $fname]} {
+	error_popup [mc "A directory with the name \"%s\" exists in \"refs/tags\"" $tag]
+	return
+    }
     if {[catch {
-	set dir [gitdir]
-	set fname [file join $dir "refs/tags" $tag]
+	if {[file dirname $tag] != "."} {
+	    file mkdir [file dirname $fname]
+	}
 	set f [open $fname w]
 	puts $f $id
 	close $f
-- 
1.5.4
Junio C Hamano· Feb 6, 2008, 07:34 UTC · re: Gerrit Pape · lore

Re: [PATCH] gitk: properly deal with tag names containing / (slash)

Gerrit Pape <pape@smarden.org> writes:
Show 26 quoted lines
> When creating a tag through gitk, and the tag name includes a slash (or
> slashes), gitk errors out in a popup window.  This patch makes gitk create
> the necessary subdirectory(s) to successfully create the tag, and also
> catches an error if a directory with the tag name to be created already
> exists.
> ...
> diff --git a/gitk-git/gitk b/gitk-git/gitk
> index 5560e4d..56a8792 100644
> --- a/gitk-git/gitk
> +++ b/gitk-git/gitk
> @@ -6136,9 +6136,16 @@ proc domktag {} {
>  	error_popup [mc "Tag \"%s\" already exists" $tag]
>  	return
>      }
> +    set dir [gitdir]
> +    set fname [file join $dir "refs/tags" $tag]
> +    if {[file isdirectory $fname]} {
> +	error_popup [mc "A directory with the name \"%s\" exists in \"refs/tags\"" $tag]
> +	return
> +    }
>      if {[catch {
> -	set dir [gitdir]
> -	set fname [file join $dir "refs/tags" $tag]
> +	if {[file dirname $tag] != "."} {
> +	    file mkdir [file dirname $fname]
> +	}

That's wrong. If your refs are packed and you have an existing tag 'foo', you should error out on a request to create 'foo/bar' (and vice versa --- existing foo/bar should prevent foo from being created).

You should be calling out "git tag" instead of futzing with files under gitdir by hand.

Gerrit Pape· Feb 7, 2008, 09:34 UTC · re: Junio C Hamano · lore

When creating a tag through gitk, and the tag name includes a slash (or slashes), gitk errors out in a popup window. This patch makes gitk use 'git tag' to create the tag instead of modifying files in refs/tags/, which fixes the issue; if 'git tag' throws an error, gitk pops up with the error message.

The problem was reported by Fr�d�ric Bri�re through
 http://bugs.debian.org/464104
Signed-off-by: Gerrit Pape <pape@smarden.org>
---
On Tue, Feb 05, 2008 at 11:34:50PM -0800, Junio C Hamano wrote:
Show 7 quoted lines
> That's wrong.  If your refs are packed and you have an existing
> tag 'foo', you should error out on a request to create 'foo/bar'
> (and vice versa --- existing foo/bar should prevent foo from
> being created).
>
> You should be calling out "git tag" instead of futzing with
> files under gitdir by hand.
Done so.
 gitk-git/gitk |    6 +-----
 1 files changed, 1 insertions(+), 5 deletions(-)
Show changes to gitk-git/gitk +1 −5
diff --git a/gitk-git/gitk b/gitk-git/gitk
index 5560e4d..00d791f 100644
--- a/gitk-git/gitk
+++ b/gitk-git/gitk
@@ -6137,11 +6137,7 @@ proc domktag {} {
 	return
     }
     if {[catch {
-	set dir [gitdir]
-	set fname [file join $dir "refs/tags" $tag]
-	set f [open $fname w]
-	puts $f $id
-	close $f
+	exec git tag $tag $id
     } err]} {
 	error_popup "[mc "Error creating tag:"] $err"
 	return
-- 
1.5.4
Gerrit Pape· Feb 11, 2008, 10:57 UTC · re: Gerrit Pape · lore

[PATCH/UTF-8] gitk: properly deal with tag names containing / (slash)

When creating a tag through gitk, and the tag name includes a slash (or slashes), gitk errors out in a popup window. This patch makes gitk use 'git tag' to create the tag instead of modifying files in refs/tags/, which fixes the issue; if 'git tag' throws an error, gitk pops up with the error message.

The problem was reported by Fr�d�ric Bri�re through
 http://bugs.debian.org/464104
Signed-off-by: Gerrit Pape <pape@smarden.org>
---
 gitk-git/gitk |    6 +-----
 1 files changed, 1 insertions(+), 5 deletions(-)
Show changes to gitk-git/gitk +1 −5
diff --git a/gitk-git/gitk b/gitk-git/gitk
index 5560e4d..00d791f 100644
--- a/gitk-git/gitk
+++ b/gitk-git/gitk
@@ -6137,11 +6137,7 @@ proc domktag {} {
 	return
     }
     if {[catch {
-	set dir [gitdir]
-	set fname [file join $dir "refs/tags" $tag]
-	set f [open $fname w]
-	puts $f $id
-	close $f
+	exec git tag $tag $id
     } err]} {
 	error_popup "[mc "Error creating tag:"] $err"
 	return
-- 
1.5.4
Paul Mackerras· Feb 12, 2008, 02:21 UTC · re: Gerrit Pape · lore

Re: [PATCH/UTF-8] gitk: properly deal with tag names containing / (slash)

Gerrit Pape writes:
Show 5 quoted lines
> When creating a tag through gitk, and the tag name includes a slash (or
> slashes), gitk errors out in a popup window.  This patch makes gitk use
> 'git tag' to create the tag instead of modifying files in refs/tags/,
> which fixes the issue; if 'git tag' throws an error, gitk pops up with
> the error message.
Thanks, applied.
Paul.

← back to recent threads