From a8363b57193ea3e881367ff06035d4a2fe021d59 Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Mon, 3 Jun 2019 21:13:28 -0500 Subject: fetch: trivial cleanup Create a helper function to clear an item. The way items are cleared has changed, and will change again soon. No functional changes. Signed-off-by: Felipe Contreras Signed-off-by: Junio C Hamano --- builtin/fetch.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'builtin') diff --git a/builtin/fetch.c b/builtin/fetch.c index aee1d9bf21..547b25d206 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -285,6 +285,11 @@ static int refname_hash_exists(struct hashmap *map, const char *refname) return !!hashmap_get_from_hash(map, strhash(refname), refname); } +static void clear_item(struct refname_hash_entry *item) +{ + oidclr(&item->oid); +} + static void find_non_local_tags(const struct ref *refs, struct ref **head, struct ref ***tail) @@ -318,7 +323,7 @@ static void find_non_local_tags(const struct ref *refs, !has_sha1_file_with_flags(item->oid.hash, OBJECT_INFO_QUICK) && !will_fetch(head, item->oid.hash)) - oidclr(&item->oid); + clear_item(item); item = NULL; continue; } @@ -332,7 +337,7 @@ static void find_non_local_tags(const struct ref *refs, if (item && !has_sha1_file_with_flags(item->oid.hash, OBJECT_INFO_QUICK) && !will_fetch(head, item->oid.hash)) - oidclr(&item->oid); + clear_item(item); item = NULL; @@ -353,7 +358,7 @@ static void find_non_local_tags(const struct ref *refs, if (item && !has_sha1_file_with_flags(item->oid.hash, OBJECT_INFO_QUICK) && !will_fetch(head, item->oid.hash)) - oidclr(&item->oid); + clear_item(item); /* * For all the tags in the remote_refs_list, -- cgit v1.2.3 From 9528b80b1a269540e12c95346f0c4b06a27dc37c Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Mon, 3 Jun 2019 21:13:29 -0500 Subject: fetch: make the code more understandable The comment makes it seem as if the condition is the other way around. The exception is when the oid is null, so check for that. Signed-off-by: Felipe Contreras Signed-off-by: Junio C Hamano --- builtin/fetch.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'builtin') diff --git a/builtin/fetch.c b/builtin/fetch.c index 547b25d206..0bf8fa7030 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -366,19 +366,21 @@ static void find_non_local_tags(const struct ref *refs, */ for_each_string_list_item(remote_ref_item, &remote_refs_list) { const char *refname = remote_ref_item->string; + struct ref *rm; item = hashmap_get_from_hash(&remote_refs, strhash(refname), refname); if (!item) BUG("unseen remote ref?"); /* Unless we have already decided to ignore this item... */ - if (!is_null_oid(&item->oid)) { - struct ref *rm = alloc_ref(item->refname); - rm->peer_ref = alloc_ref(item->refname); - oidcpy(&rm->old_oid, &item->oid); - **tail = rm; - *tail = &rm->next; - } + if (is_null_oid(&item->oid)) + continue; + + rm = alloc_ref(item->refname); + rm->peer_ref = alloc_ref(item->refname); + oidcpy(&rm->old_oid, &item->oid); + **tail = rm; + *tail = &rm->next; } hashmap_free(&remote_refs, 1); string_list_clear(&remote_refs_list, 0); -- cgit v1.2.3 From f80d922355302abf07bf0cf9a2135c2eaa61f502 Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Mon, 3 Jun 2019 21:13:30 -0500 Subject: fetch: fix regression with transport helpers Commit e198b3a740 changed the behavior of fetch with regards to tags. Before, null oids where not ignored, now they are, regardless of whether the refs have been explicitly cleared or not. e198b3a740 (fetch: replace string-list used as a look-up table with a hashmap) When using a transport helper the oids can certainly be null. So now tags are ignored and fetching them is impossible. This patch fixes that by having a specific flag that is set only when we explicitly want to ignore the refs, restoring the original behavior. Signed-off-by: Felipe Contreras Signed-off-by: Junio C Hamano --- builtin/fetch.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'builtin') diff --git a/builtin/fetch.c b/builtin/fetch.c index 0bf8fa7030..e485d429c9 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -237,6 +237,7 @@ static int will_fetch(struct ref **head, const unsigned char *sha1) struct refname_hash_entry { struct hashmap_entry ent; /* must be the first member */ struct object_id oid; + int ignore; char refname[FLEX_ARRAY]; }; @@ -287,7 +288,7 @@ static int refname_hash_exists(struct hashmap *map, const char *refname) static void clear_item(struct refname_hash_entry *item) { - oidclr(&item->oid); + item->ignore = 1; } static void find_non_local_tags(const struct ref *refs, @@ -373,7 +374,7 @@ static void find_non_local_tags(const struct ref *refs, BUG("unseen remote ref?"); /* Unless we have already decided to ignore this item... */ - if (is_null_oid(&item->oid)) + if (item->ignore) continue; rm = alloc_ref(item->refname); -- cgit v1.2.3