Skip to contentSkip to conversation

Fix incorrect ref namespace check

PATCH New Nguyễn Thái Ngọc Duy 3 participants 5 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix incorrect ref namespace check

The reason why the trailing slash is needed is obvious. refs/stash is not a namespace, but a single ref. Do full string compare on it.

---
 builtin/fetch.c  |    2 +-
 builtin/remote.c |    2 +-
 log-tree.c       |    2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
builtin/fetch.c +1 -1
index 33ad3aa..daa68d2 100644
@@ -573,7 +573,7 @@ static void find_non_local_tags(struct transport *transport,
 
 	for_each_ref(add_existing, &existing_refs);
 	for (ref = transport_get_remote_refs(transport); ref; ref = ref->next) {
-		if (prefixcmp(ref->name, "refs/tags"))
+		if (prefixcmp(ref->name, "refs/tags/"))
 			continue;
 
 		/*
builtin/remote.c +1 -1
index 583eec9..f54a89a 100644
@@ -534,7 +534,7 @@ static int add_branch_for_removal(const char *refname,
 	}
 
 	/* don't delete non-remote-tracking refs */
-	if (prefixcmp(refname, "refs/remotes")) {
+	if (prefixcmp(refname, "refs/remotes/")) {
 		/* advise user how to delete local branches */
 		if (!prefixcmp(refname, "refs/heads/"))
 			string_list_append(branches->skipped,
log-tree.c +1 -1
index 319bd31..9a88fcc 100644
@@ -119,7 +119,7 @@ static int add_ref_decoration(const char *refname, const unsigned char *sha1, in
 		type = DECORATION_REF_REMOTE;
 	else if (!prefixcmp(refname, "refs/tags/"))
 		type = DECORATION_REF_TAG;
-	else if (!prefixcmp(refname, "refs/stash"))
+	else if (!strcmp(refname, "refs/stash"))
 		type = DECORATION_REF_STASH;
 	else if (!prefixcmp(refname, "HEAD"))
 		type = DECORATION_REF_HEAD;
Signature · 1 line
1.7.8.36.g69ee2
#1 lore raw

PATCH 1/1 Fix incorrect ref namespace check

The reason why the trailing slash is needed is obvious. refs/stash and HEAD are not namespace, but complete refs. Do full string compare on them.

---
I missed prefixcmp(..., "HEAD") right below prefixcmp(..., "refs/stash")

 builtin/fetch.c  |    2 +-
 builtin/remote.c |    2 +-
 log-tree.c       |    4 ++--
 3 files changed, 4 insertions(+), 4 deletions(-)
builtin/fetch.c +1 -1
index 33ad3aa..daa68d2 100644
@@ -573,7 +573,7 @@ static void find_non_local_tags(struct transport *transport,
 
 	for_each_ref(add_existing, &existing_refs);
 	for (ref = transport_get_remote_refs(transport); ref; ref = ref->next) {
-		if (prefixcmp(ref->name, "refs/tags"))
+		if (prefixcmp(ref->name, "refs/tags/"))
 			continue;
 
 		/*
builtin/remote.c +1 -1
index 583eec9..f54a89a 100644
@@ -534,7 +534,7 @@ static int add_branch_for_removal(const char *refname,
 	}
 
 	/* don't delete non-remote-tracking refs */
-	if (prefixcmp(refname, "refs/remotes")) {
+	if (prefixcmp(refname, "refs/remotes/")) {
 		/* advise user how to delete local branches */
 		if (!prefixcmp(refname, "refs/heads/"))
 			string_list_append(branches->skipped,
log-tree.c +2 -2
index 319bd31..535b905 100644
@@ -119,9 +119,9 @@ static int add_ref_decoration(const char *refname, const unsigned char *sha1, in
 		type = DECORATION_REF_REMOTE;
 	else if (!prefixcmp(refname, "refs/tags/"))
 		type = DECORATION_REF_TAG;
-	else if (!prefixcmp(refname, "refs/stash"))
+	else if (!strcmp(refname, "refs/stash"))
 		type = DECORATION_REF_STASH;
-	else if (!prefixcmp(refname, "HEAD"))
+	else if (!strcmp(refname, "HEAD"))
 		type = DECORATION_REF_HEAD;
 
 	if (!cb_data || *(int *)cb_data == DECORATE_SHORT_REFS)
Signature · 1 line
1.7.8.36.g69ee2
#2 lore raw
Quoted 6 lines · Nguyễn Thái Ngọc Duy

The reason why the trailing slash is needed is obvious. refs/stash and HEAD are not namespace, but complete refs. Do full string compare on them.

---
I missed prefixcmp(..., "HEAD") right below prefixcmp(..., "refs/stash")

As Michael has been actively showing interest in cleaning up the area, he should have been CC'ed, I would think.

Quoted 48 lines
 builtin/fetch.c  |    2 +-
 builtin/remote.c |    2 +-
 log-tree.c       |    4 ++--
 3 files changed, 4 insertions(+), 4 deletions(-)
builtin/fetch.c +1 -1
index 33ad3aa..daa68d2 100644
@@ -573,7 +573,7 @@ static void find_non_local_tags(struct transport *transport,
 
 	for_each_ref(add_existing, &existing_refs);
 	for (ref = transport_get_remote_refs(transport); ref; ref = ref->next) {
-		if (prefixcmp(ref->name, "refs/tags"))
+		if (prefixcmp(ref->name, "refs/tags/"))
 			continue;
 
 		/*
builtin/remote.c +1 -1
index 583eec9..f54a89a 100644
@@ -534,7 +534,7 @@ static int add_branch_for_removal(const char *refname,
 	}
 
 	/* don't delete non-remote-tracking refs */
-	if (prefixcmp(refname, "refs/remotes")) {
+	if (prefixcmp(refname, "refs/remotes/")) {
 		/* advise user how to delete local branches */
 		if (!prefixcmp(refname, "refs/heads/"))
 			string_list_append(branches->skipped,
log-tree.c +2 -2
index 319bd31..535b905 100644
@@ -119,9 +119,9 @@ static int add_ref_decoration(const char *refname, const unsigned char *sha1, in
 		type = DECORATION_REF_REMOTE;
 	else if (!prefixcmp(refname, "refs/tags/"))
 		type = DECORATION_REF_TAG;
-	else if (!prefixcmp(refname, "refs/stash"))
+	else if (!strcmp(refname, "refs/stash"))
 		type = DECORATION_REF_STASH;
-	else if (!prefixcmp(refname, "HEAD"))
+	else if (!strcmp(refname, "HEAD"))
 		type = DECORATION_REF_HEAD;
 
 	if (!cb_data || *(int *)cb_data == DECORATE_SHORT_REFS)
#3 lore raw

Any comments Mike?

2012/1/5 Junio C Hamano <[email protected]>:

Quoted 60 lines
Quoted 6 lines · Nguyễn Thái Ngọc Duy

The reason why the trailing slash is needed is obvious. refs/stash and HEAD are not namespace, but complete refs. Do full string compare on them.

---
 I missed prefixcmp(..., "HEAD") right below prefixcmp(..., "refs/stash")

As Michael has been actively showing interest in cleaning up the area, he should have been CC'ed, I would think.

Quoted 48 lines

 builtin/fetch.c  |    2 +-
 builtin/remote.c |    2 +-
 log-tree.c       |    4 ++--

 3 files changed, 4 insertions(+), 4 deletions(-)
builtin/fetch.c +1 -1
index 33ad3aa..daa68d2 100644
@@ -573,7 +573,7 @@ static void find_non_local_tags(struct transport *transport,
 
       for_each_ref(add_existing, &existing_refs);
       for (ref = transport_get_remote_refs(transport); ref; ref = ref->next) {
-             if (prefixcmp(ref->name, "refs/tags"))
+             if (prefixcmp(ref->name, "refs/tags/"))
                       continue;
 
               /*
builtin/remote.c +1 -1
index 583eec9..f54a89a 100644
@@ -534,7 +534,7 @@ static int add_branch_for_removal(const char *refname,
       }
 
       /* don't delete non-remote-tracking refs */
-     if (prefixcmp(refname, "refs/remotes")) {
+     if (prefixcmp(refname, "refs/remotes/")) {
               /* advise user how to delete local branches */
               if (!prefixcmp(refname, "refs/heads/"))
                       string_list_append(branches->skipped,
log-tree.c +2 -2
index 319bd31..535b905 100644
@@ -119,9 +119,9 @@ static int add_ref_decoration(const char *refname, const unsigned char *sha1, in
               type = DECORATION_REF_REMOTE;
       else if (!prefixcmp(refname, "refs/tags/"))
               type = DECORATION_REF_TAG;
-     else if (!prefixcmp(refname, "refs/stash"))
+     else if (!strcmp(refname, "refs/stash"))
               type = DECORATION_REF_STASH;
-     else if (!prefixcmp(refname, "HEAD"))
+     else if (!strcmp(refname, "HEAD"))
               type = DECORATION_REF_HEAD;
 
       if (!cb_data || *(int *)cb_data == DECORATE_SHORT_REFS)
Signature · 1 line
Duy
#4 lore raw
Quoted 1 line · Nguyen Thai Ngoc Duy

Any comments Mike?

Looks fine to me.

Theoretically, we could add an API for iterating over references *excluding* a particular namespace, which (after hierarchical refs is accepted) could be implemented a bit more efficiently than iterating over all references and then excluding those in the unwanted namespace.
But I think it would be far more trouble than it's worth.

Michael

Quoted 64 lines

2012/1/5 Junio C Hamano <[email protected]>:

Quoted 60 lines
Quoted 6 lines · Nguyễn Thái Ngọc Duy

The reason why the trailing slash is needed is obvious. refs/stash and HEAD are not namespace, but complete refs. Do full string compare on them.

---
I missed prefixcmp(..., "HEAD") right below prefixcmp(..., "refs/stash")

As Michael has been actively showing interest in cleaning up the area, he should have been CC'ed, I would think.

Quoted 48 lines
 builtin/fetch.c  |    2 +-
 builtin/remote.c |    2 +-
 log-tree.c       |    4 ++--
 3 files changed, 4 insertions(+), 4 deletions(-)
builtin/fetch.c +1 -1
index 33ad3aa..daa68d2 100644
@@ -573,7 +573,7 @@ static void find_non_local_tags(struct transport *transport,
 
      for_each_ref(add_existing, &existing_refs);
      for (ref = transport_get_remote_refs(transport); ref; ref = ref->next) {
-             if (prefixcmp(ref->name, "refs/tags"))
+             if (prefixcmp(ref->name, "refs/tags/"))
                      continue;
 
              /*
builtin/remote.c +1 -1
index 583eec9..f54a89a 100644
@@ -534,7 +534,7 @@ static int add_branch_for_removal(const char *refname,
      }
 
      /* don't delete non-remote-tracking refs */
-     if (prefixcmp(refname, "refs/remotes")) {
+     if (prefixcmp(refname, "refs/remotes/")) {
              /* advise user how to delete local branches */
              if (!prefixcmp(refname, "refs/heads/"))
                      string_list_append(branches->skipped,
log-tree.c +2 -2
index 319bd31..535b905 100644
@@ -119,9 +119,9 @@ static int add_ref_decoration(const char *refname, const unsigned char *sha1, in
              type = DECORATION_REF_REMOTE;
      else if (!prefixcmp(refname, "refs/tags/"))
              type = DECORATION_REF_TAG;
-     else if (!prefixcmp(refname, "refs/stash"))
+     else if (!strcmp(refname, "refs/stash"))
              type = DECORATION_REF_STASH;
-     else if (!prefixcmp(refname, "HEAD"))
+     else if (!strcmp(refname, "HEAD"))
              type = DECORATION_REF_HEAD;
 
      if (!cb_data || *(int *)cb_data == DECORATE_SHORT_REFS)
Signature · 3 lines
Michael Haggerty
[email protected]
http://softwareswirl.blogspot.com/