# [RFC/PATCH] tag: display original sha1 of deleted/overwritten tag

4 messages from 2009-12-10 to 2009-12-10. Participants: Zoltán Füzesi.
Thread: https://gitlist.dev/t/21928

## Zoltán Füzesi, 2009-12-10 12:34

Subject: [RFC/PATCH] tag: display original sha1 of deleted/overwritten tag
Message-ID: <1260448496-527-1-git-send-email-zfuzesi@eaglet.hu>
URL: https://gitlist.dev/e/1260448496-527-1-git-send-email-zfuzesi%40eaglet.hu

```
It makes possible to undo accidental tag deletion and overwriting.

Signed-off-by: Zoltán Füzesi <zfuzesi@eaglet.hu>
---
This patch was created in response to this feature request:
http://article.gmane.org/gmane.comp.version-control.git/135016
I named it "RFC" because of the overwriting part.

 builtin-tag.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/builtin-tag.c b/builtin-tag.c
index c479018..8dca364 100644
--- a/builtin-tag.c
+++ b/builtin-tag.c
@@ -140,7 +140,7 @@ static int delete_tag(const char *name, const char *ref,
 {
 	if (delete_ref(ref, sha1, 0))
 		return 1;
-	printf("Deleted tag '%s'\n", name);
+	printf("Deleted tag '%s' %s\n", name, sha1_to_hex(sha1));
 	return 0;
 }
 
@@ -479,6 +479,8 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
 		die("%s: cannot lock the ref", ref);
 	if (write_ref_sha1(lock, object, NULL) < 0)
 		die("%s: cannot update the ref", ref);
+	else if (force && hashcmp(object, prev))
+		printf("Overwritten tag '%s' (%s)\n", ref, sha1_to_hex(prev));
 
 	strbuf_release(&buf);
 	return 0;
-- 
1.6.6.rc2

```

## Zoltán Füzesi, 2009-12-10 13:26

Subject: [RFC/PATCH v2] tag: display original sha1 of deleted/overwritten tag
Message-ID: <1260451579-4400-1-git-send-email-zfuzesi@eaglet.hu>
URL: https://gitlist.dev/e/1260451579-4400-1-git-send-email-zfuzesi%40eaglet.hu
In-Reply-To: <1260448496-527-1-git-send-email-zfuzesi@eaglet.hu>

```
It makes possible to undo accidental tag deletion and overwriting.

Signed-off-by: Zoltán Füzesi <zfuzesi@eaglet.hu>
---
This patch was created in response to this feature request:
http://article.gmane.org/gmane.comp.version-control.git/135016
I named it "RFC" because of the overwriting part.

v2: works when tag object is created.

 builtin-tag.c |    8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/builtin-tag.c b/builtin-tag.c
index c479018..1265b84 100644
--- a/builtin-tag.c
+++ b/builtin-tag.c
@@ -140,7 +140,7 @@ static int delete_tag(const char *name, const char *ref,
 {
 	if (delete_ref(ref, sha1, 0))
 		return 1;
-	printf("Deleted tag '%s'\n", name);
+	printf("Deleted tag '%s' %s\n", name, sha1_to_hex(sha1));
 	return 0;
 }
 
@@ -363,7 +363,7 @@ static int parse_msg_arg(const struct option *opt, const char *arg, int unset)
 int cmd_tag(int argc, const char **argv, const char *prefix)
 {
 	struct strbuf buf = STRBUF_INIT;
-	unsigned char object[20], prev[20];
+	unsigned char object[20], prev[20], tag_object[20];
 	char ref[PATH_MAX];
 	const char *object_ref, *tag;
 	struct ref_lock *lock;
@@ -472,13 +472,15 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
 
 	if (annotate)
 		create_tag(object, tag, &buf, msg.given || msgfile,
-			   sign, prev, object);
+			   sign, prev, tag_object);
 
 	lock = lock_any_ref_for_update(ref, prev, 0);
 	if (!lock)
 		die("%s: cannot lock the ref", ref);
 	if (write_ref_sha1(lock, object, NULL) < 0)
 		die("%s: cannot update the ref", ref);
+	else if (force && hashcmp(object, prev))
+		printf("Overwritten tag '%s' (%s)\n", ref, sha1_to_hex(prev));
 
 	strbuf_release(&buf);
 	return 0;
-- 
1.6.6.rc2

```

## Zoltán Füzesi, 2009-12-10 13:58

Subject: [RFC/PATCH v3] tag: display original sha1 of deleted/overwritten tag
Message-ID: <1260453537-6156-1-git-send-email-zfuzesi@eaglet.hu>
URL: https://gitlist.dev/e/1260453537-6156-1-git-send-email-zfuzesi%40eaglet.hu
In-Reply-To: <1260451579-4400-1-git-send-email-zfuzesi@eaglet.hu>

```
It makes possible to undo accidental tag deletion and overwriting.

Signed-off-by: Zoltán Füzesi <zfuzesi@eaglet.hu>
---
This patch was created in response to this feature request:
http://article.gmane.org/gmane.comp.version-control.git/135016
I named it "RFC" because of the overwriting part.

v3: works when tag object is created (I should slow down...)

 builtin-tag.c |   10 ++++++----
 1 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/builtin-tag.c b/builtin-tag.c
index c479018..1404a0e 100644
--- a/builtin-tag.c
+++ b/builtin-tag.c
@@ -140,7 +140,7 @@ static int delete_tag(const char *name, const char *ref,
 {
 	if (delete_ref(ref, sha1, 0))
 		return 1;
-	printf("Deleted tag '%s'\n", name);
+	printf("Deleted tag '%s' %s\n", name, sha1_to_hex(sha1));
 	return 0;
 }
 
@@ -363,7 +363,7 @@ static int parse_msg_arg(const struct option *opt, const char *arg, int unset)
 int cmd_tag(int argc, const char **argv, const char *prefix)
 {
 	struct strbuf buf = STRBUF_INIT;
-	unsigned char object[20], prev[20];
+	unsigned char object[20], prev[20], tag_object[20];
 	char ref[PATH_MAX];
 	const char *object_ref, *tag;
 	struct ref_lock *lock;
@@ -472,13 +472,15 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
 
 	if (annotate)
 		create_tag(object, tag, &buf, msg.given || msgfile,
-			   sign, prev, object);
+			   sign, prev, tag_object);
 
 	lock = lock_any_ref_for_update(ref, prev, 0);
 	if (!lock)
 		die("%s: cannot lock the ref", ref);
-	if (write_ref_sha1(lock, object, NULL) < 0)
+	if (write_ref_sha1(lock, annotate ? tag_object : object, NULL) < 0)
 		die("%s: cannot update the ref", ref);
+	else if (force && hashcmp(object, prev))
+		printf("Overwritten tag '%s' (%s)\n", ref, sha1_to_hex(prev));
 
 	strbuf_release(&buf);
 	return 0;
-- 
1.6.6.rc2

```

## Zoltán Füzesi, 2009-12-10 14:09

Subject: Re: [RFC/PATCH v3] tag: display original sha1 of deleted/overwritten tag
Message-ID: <9ab80d150912100609m29bf4862yc7b1abd680c96c54@mail.gmail.com>
URL: https://gitlist.dev/e/9ab80d150912100609m29bf4862yc7b1abd680c96c54%40mail.gmail.com
In-Reply-To: <1260453537-6156-1-git-send-email-zfuzesi@eaglet.hu>

```
Forget v2 and v3, v1 is the good one. Sorry.

2009/12/10 Zoltán Füzesi <zfuzesi@eaglet.hu>:
> It makes possible to undo accidental tag deletion and overwriting.
>
> Signed-off-by: Zoltán Füzesi <zfuzesi@eaglet.hu>
> ---
> This patch was created in response to this feature request:
> http://article.gmane.org/gmane.comp.version-control.git/135016
> I named it "RFC" because of the overwriting part.
>
> v3: works when tag object is created (I should slow down...)
>
>  builtin-tag.c |   10 ++++++----
>  1 files changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/builtin-tag.c b/builtin-tag.c
> index c479018..1404a0e 100644
> --- a/builtin-tag.c
> +++ b/builtin-tag.c
> @@ -140,7 +140,7 @@ static int delete_tag(const char *name, const char *ref,
>  {
>        if (delete_ref(ref, sha1, 0))
>                return 1;
> -       printf("Deleted tag '%s'\n", name);
> +       printf("Deleted tag '%s' %s\n", name, sha1_to_hex(sha1));
>        return 0;
>  }
>
> @@ -363,7 +363,7 @@ static int parse_msg_arg(const struct option *opt, const char *arg, int unset)
>  int cmd_tag(int argc, const char **argv, const char *prefix)
>  {
>        struct strbuf buf = STRBUF_INIT;
> -       unsigned char object[20], prev[20];
> +       unsigned char object[20], prev[20], tag_object[20];
>        char ref[PATH_MAX];
>        const char *object_ref, *tag;
>        struct ref_lock *lock;
> @@ -472,13 +472,15 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
>
>        if (annotate)
>                create_tag(object, tag, &buf, msg.given || msgfile,
> -                          sign, prev, object);
> +                          sign, prev, tag_object);
>
>        lock = lock_any_ref_for_update(ref, prev, 0);
>        if (!lock)
>                die("%s: cannot lock the ref", ref);
> -       if (write_ref_sha1(lock, object, NULL) < 0)
> +       if (write_ref_sha1(lock, annotate ? tag_object : object, NULL) < 0)
>                die("%s: cannot update the ref", ref);
> +       else if (force && hashcmp(object, prev))
> +               printf("Overwritten tag '%s' (%s)\n", ref, sha1_to_hex(prev));
>
>        strbuf_release(&buf);
>        return 0;
> --
> 1.6.6.rc2
>
>

```
