builtin/fetch.c: reorder function definitions
Reorder function definitions to avoid the need for a forward declaration of function find_non_local_tags(). Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Michael Haggerty committed
Oct 30, 2013 at 06:32 UTC
a0fbb5a329ea138e02698312f14ac1aea4b9b4c9
1 file changed
+97
-101
builtin/fetch.c
+97
-101
@@ -160,9 +160,105 @@ static void add_merge_config(struct ref **head,
160
}
161
}
162
163
+static int add_existing(const char *refname, const unsigned char *sha1,
164
+ int flag, void *cbdata)
165
+{
166
+ struct string_list *list = (struct string_list *)cbdata;
167
+ struct string_list_item *item = string_list_insert(list, refname);
168
+ item->util = xmalloc(20);
169
+ hashcpy(item->util, sha1);
170
+ return 0;
171
+}
172
+
173
+static int will_fetch(struct ref **head, const unsigned char *sha1)
174
+{
175
+ struct ref *rm = *head;
176
+ while (rm) {
177
+ if (!hashcmp(rm->old_sha1, sha1))
178
+ return 1;
179
+ rm = rm->next;
180
+ }
181
+ return 0;
182
+}
183
+
184
static void find_non_local_tags(struct transport *transport,
185
struct ref **head,
165
- struct ref ***tail);
186
+ struct ref ***tail)
187
+{
188
+ struct string_list existing_refs = STRING_LIST_INIT_DUP;
189
+ struct string_list remote_refs = STRING_LIST_INIT_NODUP;
190
+ const struct ref *ref;
191
+ struct string_list_item *item = NULL;
192
+
193
+ for_each_ref(add_existing, &existing_refs);
194
+ for (ref = transport_get_remote_refs(transport); ref; ref = ref->next) {
195
+ if (prefixcmp(ref->name, "refs/tags/"))
196
+ continue;
197
+
198
+ /*
199
+ * The peeled ref always follows the matching base
200
+ * ref, so if we see a peeled ref that we don't want
201
+ * to fetch then we can mark the ref entry in the list
202
+ * as one to ignore by setting util to NULL.
203
+ */
204
+ if (!suffixcmp(ref->name, "^{}")) {
205
+ if (item && !has_sha1_file(ref->old_sha1) &&
206
+ !will_fetch(head, ref->old_sha1) &&
207
+ !has_sha1_file(item->util) &&
208
+ !will_fetch(head, item->util))
209
+ item->util = NULL;
210
+ item = NULL;
211
+ continue;
212
+ }
213
+
214
+ /*
215
+ * If item is non-NULL here, then we previously saw a
216
+ * ref not followed by a peeled reference, so we need
217
+ * to check if it is a lightweight tag that we want to
218
+ * fetch.
219
+ */
220
+ if (item && !has_sha1_file(item->util) &&
221
+ !will_fetch(head, item->util))
222
+ item->util = NULL;
223
+
224
+ item = NULL;
225
+
226
+ /* skip duplicates and refs that we already have */
227
+ if (string_list_has_string(&remote_refs, ref->name) ||
228
+ string_list_has_string(&existing_refs, ref->name))
229
+ continue;
230
+
231
+ item = string_list_insert(&remote_refs, ref->name);
232
+ item->util = (void *)ref->old_sha1;
233
+ }
234
+ string_list_clear(&existing_refs, 1);
235
+
236
+ /*
237
+ * We may have a final lightweight tag that needs to be
238
+ * checked to see if it needs fetching.
239
+ */
240
+ if (item && !has_sha1_file(item->util) &&
241
+ !will_fetch(head, item->util))
242
+ item->util = NULL;
243
+
244
+ /*
245
+ * For all the tags in the remote_refs string list,
246
+ * add them to the list of refs to be fetched
247
+ */
248
+ for_each_string_list_item(item, &remote_refs) {
249
+ /* Unless we have already decided to ignore this item... */
250
+ if (item->util)
251
+ {
252
+ struct ref *rm = alloc_ref(item->string);
253
+ rm->peer_ref = alloc_ref(item->string);
254
+ hashcpy(rm->old_sha1, item->util);
255
+ **tail = rm;
256
+ *tail = &rm->next;
257
+ }
258
+ }
259
+
260
+ string_list_clear(&remote_refs, 0);
261
+}
262
263
static struct ref *get_ref_map(struct transport *transport,
264
struct refspec *refspecs, int refspec_count,
@@ -612,106 +708,6 @@ static int prune_refs(struct refspec *refs, int ref_count, struct ref *ref_map)
708
return result;
709
}
710
615
-static int add_existing(const char *refname, const unsigned char *sha1,
616
- int flag, void *cbdata)
617
-{
618
- struct string_list *list = (struct string_list *)cbdata;
619
- struct string_list_item *item = string_list_insert(list, refname);
620
- item->util = xmalloc(20);
621
- hashcpy(item->util, sha1);
622
- return 0;
623
-}
624
-
625
-static int will_fetch(struct ref **head, const unsigned char *sha1)
626
-{
627
- struct ref *rm = *head;
628
- while (rm) {
629
- if (!hashcmp(rm->old_sha1, sha1))
630
- return 1;
631
- rm = rm->next;
632
- }
633
- return 0;
634
-}
635
-
636
-static void find_non_local_tags(struct transport *transport,
637
- struct ref **head,
638
- struct ref ***tail)
639
-{
640
- struct string_list existing_refs = STRING_LIST_INIT_DUP;
641
- struct string_list remote_refs = STRING_LIST_INIT_NODUP;
642
- const struct ref *ref;
643
- struct string_list_item *item = NULL;
644
-
645
- for_each_ref(add_existing, &existing_refs);
646
- for (ref = transport_get_remote_refs(transport); ref; ref = ref->next) {
647
- if (prefixcmp(ref->name, "refs/tags/"))
648
- continue;
649
-
650
- /*
651
- * The peeled ref always follows the matching base
652
- * ref, so if we see a peeled ref that we don't want
653
- * to fetch then we can mark the ref entry in the list
654
- * as one to ignore by setting util to NULL.
655
- */
656
- if (!suffixcmp(ref->name, "^{}")) {
657
- if (item && !has_sha1_file(ref->old_sha1) &&
658
- !will_fetch(head, ref->old_sha1) &&
659
- !has_sha1_file(item->util) &&
660
- !will_fetch(head, item->util))
661
- item->util = NULL;
662
- item = NULL;
663
- continue;
664
- }
665
-
666
- /*
667
- * If item is non-NULL here, then we previously saw a
668
- * ref not followed by a peeled reference, so we need
669
- * to check if it is a lightweight tag that we want to
670
- * fetch.
671
- */
672
- if (item && !has_sha1_file(item->util) &&
673
- !will_fetch(head, item->util))
674
- item->util = NULL;
675
-
676
- item = NULL;
677
-
678
- /* skip duplicates and refs that we already have */
679
- if (string_list_has_string(&remote_refs, ref->name) ||
680
- string_list_has_string(&existing_refs, ref->name))
681
- continue;
682
-
683
- item = string_list_insert(&remote_refs, ref->name);
684
- item->util = (void *)ref->old_sha1;
685
- }
686
- string_list_clear(&existing_refs, 1);
687
-
688
- /*
689
- * We may have a final lightweight tag that needs to be
690
- * checked to see if it needs fetching.
691
- */
692
- if (item && !has_sha1_file(item->util) &&
693
- !will_fetch(head, item->util))
694
- item->util = NULL;
695
-
696
- /*
697
- * For all the tags in the remote_refs string list,
698
- * add them to the list of refs to be fetched
699
- */
700
- for_each_string_list_item(item, &remote_refs) {
701
- /* Unless we have already decided to ignore this item... */
702
- if (item->util)
703
- {
704
- struct ref *rm = alloc_ref(item->string);
705
- rm->peer_ref = alloc_ref(item->string);
706
- hashcpy(rm->old_sha1, item->util);
707
- **tail = rm;
708
- *tail = &rm->next;
709
- }
710
- }
711
-
712
- string_list_clear(&remote_refs, 0);
713
-}
714
-
711
static void check_not_current_branch(struct ref *ref_map)
712
{
713
struct branch *current_branch = branch_get(NULL);