fast-export: refactor get_tags_and_duplicates()
Split into a separate helper function get_commit() so that the part that finds the relevant commit, and the part that does something with it (handle tag object, etc.) are in different places. No functional changes. Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Felipe Contreras committed
Sep 1, 2013 at 02:05 UTC
3e9b9cb117feb6e3c942aab4c8e756568f4f0f06
1 file changed
+38
-30
builtin/fast-export.c
+38
-30
@@ -485,9 +485,32 @@ static void handle_tag(const char *name, struct tag *tag)
485
(int)message_size, (int)message_size, message ? message : "");
486
}
487
488
+static struct commit *get_commit(struct rev_cmdline_entry *e, char *full_name)
489
+{
490
+ switch (e->item->type) {
491
+ case OBJ_COMMIT:
492
+ return (struct commit *)e->item;
493
+ case OBJ_TAG: {
494
+ struct tag *tag = (struct tag *)e->item;
495
+
496
+ /* handle nested tags */
497
+ while (tag && tag->object.type == OBJ_TAG) {
498
+ parse_object(tag->object.sha1);
499
+ string_list_append(&extra_refs, full_name)->util = tag;
500
+ tag = (struct tag *)tag->tagged;
501
+ }
502
+ if (!tag)
503
+ die("Tag %s points nowhere?", e->name);
504
+ return (struct commit *)tag;
505
+ break;
506
+ }
507
+ default:
508
+ return NULL;
509
+ }
510
+}
511
+
512
static void get_tags_and_duplicates(struct rev_cmdline_info *info)
513
{
490
- struct tag *tag;
514
int i;
515
516
for (i = 0; i < info->nr; i++) {
@@ -502,41 +525,26 @@ static void get_tags_and_duplicates(struct rev_cmdline_info *info)
525
if (dwim_ref(e->name, strlen(e->name), sha1, &full_name) != 1)
526
continue;
527
505
- switch (e->item->type) {
506
- case OBJ_COMMIT:
507
- commit = (struct commit *)e->item;
508
- break;
509
- case OBJ_TAG:
510
- tag = (struct tag *)e->item;
511
-
512
- /* handle nested tags */
513
- while (tag && tag->object.type == OBJ_TAG) {
514
- parse_object(tag->object.sha1);
515
- string_list_append(&extra_refs, full_name)->util = tag;
516
- tag = (struct tag *)tag->tagged;
517
- }
518
- if (!tag)
519
- die ("Tag %s points nowhere?", e->name);
520
- switch(tag->object.type) {
521
- case OBJ_COMMIT:
522
- commit = (struct commit *)tag;
523
- break;
524
- case OBJ_BLOB:
525
- export_blob(tag->object.sha1);
526
- continue;
527
- default: /* OBJ_TAG (nested tags) is already handled */
528
- warning("Tag points to object of unexpected type %s, skipping.",
529
- typename(tag->object.type));
530
- continue;
531
- }
532
- break;
533
- default:
528
+ commit = get_commit(e, full_name);
529
+ if (!commit) {
530
warning("%s: Unexpected object of type %s, skipping.",
531
e->name,
532
typename(e->item->type));
533
continue;
534
}
535
536
+ switch(commit->object.type) {
537
+ case OBJ_COMMIT:
538
+ break;
539
+ case OBJ_BLOB:
540
+ export_blob(commit->object.sha1);
541
+ continue;
542
+ default: /* OBJ_TAG (nested tags) is already handled */
543
+ warning("Tag points to object of unexpected type %s, skipping.",
544
+ typename(commit->object.type));
545
+ continue;
546
+ }
547
+
548
/*
549
* This ref will not be updated through a commit, lets make
550
* sure it gets properly updated eventually.