Code

Merge branch 'maint'
[git.git] / builtin-fast-export.c
index 76f3167276d55f1ffae2b0070d3adef738328bad..e9ee2c79ac0395fde30de329d181733d7be88d40 100644 (file)
@@ -13,7 +13,7 @@
 #include "log-tree.h"
 #include "revision.h"
 #include "decorate.h"
-#include "path-list.h"
+#include "string-list.h"
 #include "utf8.h"
 #include "parse-options.h"
 
@@ -24,6 +24,7 @@ static const char *fast_export_usage[] = {
 
 static int progress;
 static enum { VERBATIM, WARN, STRIP, ABORT } signed_tag_mode = ABORT;
+static int fake_missing_tagger;
 
 static int parse_opt_signed_tag_mode(const struct option *opt,
                                     const char *arg, int unset)
@@ -132,13 +133,46 @@ static void show_filemodify(struct diff_queue_struct *q,
 {
        int i;
        for (i = 0; i < q->nr; i++) {
+               struct diff_filespec *ospec = q->queue[i]->one;
                struct diff_filespec *spec = q->queue[i]->two;
-               if (is_null_sha1(spec->sha1))
+
+               switch (q->queue[i]->status) {
+               case DIFF_STATUS_DELETED:
                        printf("D %s\n", spec->path);
-               else {
-                       struct object *object = lookup_object(spec->sha1);
-                       printf("M %06o :%d %s\n", spec->mode,
-                              get_object_mark(object), spec->path);
+                       break;
+
+               case DIFF_STATUS_COPIED:
+               case DIFF_STATUS_RENAMED:
+                       printf("%c \"%s\" \"%s\"\n", q->queue[i]->status,
+                              ospec->path, spec->path);
+
+                       if (!hashcmp(ospec->sha1, spec->sha1) &&
+                           ospec->mode == spec->mode)
+                               break;
+                       /* fallthrough */
+
+               case DIFF_STATUS_TYPE_CHANGED:
+               case DIFF_STATUS_MODIFIED:
+               case DIFF_STATUS_ADDED:
+                       /*
+                        * Links refer to objects in another repositories;
+                        * output the SHA-1 verbatim.
+                        */
+                       if (S_ISGITLINK(spec->mode))
+                               printf("M %06o %s %s\n", spec->mode,
+                                      sha1_to_hex(spec->sha1), spec->path);
+                       else {
+                               struct object *object = lookup_object(spec->sha1);
+                               printf("M %06o :%d %s\n", spec->mode,
+                                      get_object_mark(object), spec->path);
+                       }
+                       break;
+
+               default:
+                       die("Unexpected comparison status '%c' for %s, %s",
+                               q->queue[i]->status,
+                               ospec->path ? ospec->path : "none",
+                               spec->path ? spec->path : "none");
                }
        }
 }
@@ -196,8 +230,10 @@ static void handle_commit(struct commit *commit, struct rev_info *rev)
                diff_root_tree_sha1(commit->tree->object.sha1,
                                    "", &rev->diffopt);
 
+       /* Export the referenced blobs, and remember the marks. */
        for (i = 0; i < diff_queued_diff.nr; i++)
-               handle_object(diff_queued_diff.queue[i]->two->sha1);
+               if (!S_ISGITLINK(diff_queued_diff.queue[i]->two->mode))
+                       handle_object(diff_queued_diff.queue[i]->two->sha1);
 
        mark_next_object(&commit->object);
        if (!is_encoding_utf8(encoding))
@@ -262,10 +298,17 @@ static void handle_tag(const char *name, struct tag *tag)
                message_size = strlen(message);
        }
        tagger = memmem(buf, message ? message - buf : size, "\ntagger ", 8);
-       if (!tagger)
-               die ("No tagger for tag %s", sha1_to_hex(tag->object.sha1));
-       tagger++;
-       tagger_end = strchrnul(tagger, '\n');
+       if (!tagger) {
+               if (fake_missing_tagger)
+                       tagger = "tagger Unspecified Tagger "
+                               "<unspecified-tagger> 0 +0000";
+               else
+                       tagger = "";
+               tagger_end = tagger + strlen(tagger);
+       } else {
+               tagger++;
+               tagger_end = strchrnul(tagger, '\n');
+       }
 
        /* handle signed tags */
        if (message) {
@@ -291,14 +334,15 @@ static void handle_tag(const char *name, struct tag *tag)
 
        if (!prefixcmp(name, "refs/tags/"))
                name += 10;
-       printf("tag %s\nfrom :%d\n%.*s\ndata %d\n%.*s\n",
+       printf("tag %s\nfrom :%d\n%.*s%sdata %d\n%.*s\n",
               name, get_object_mark(tag->tagged),
               (int)(tagger_end - tagger), tagger,
+              tagger == tagger_end ? "" : "\n",
               (int)message_size, (int)message_size, message ? message : "");
 }
 
 static void get_tags_and_duplicates(struct object_array *pending,
-                                   struct path_list *extra_refs)
+                                   struct string_list *extra_refs)
 {
        struct tag *tag;
        int i;
@@ -319,7 +363,7 @@ static void get_tags_and_duplicates(struct object_array *pending,
                case OBJ_TAG:
                        tag = (struct tag *)e->item;
                        while (tag && tag->object.type == OBJ_TAG) {
-                               path_list_insert(full_name, extra_refs)->util = tag;
+                               string_list_append(full_name, extra_refs)->util = tag;
                                tag = (struct tag *)tag->tagged;
                        }
                        if (!tag)
@@ -339,19 +383,19 @@ static void get_tags_and_duplicates(struct object_array *pending,
                }
                if (commit->util)
                        /* more than one name for the same object */
-                       path_list_insert(full_name, extra_refs)->util = commit;
+                       string_list_append(full_name, extra_refs)->util = commit;
                else
                        commit->util = full_name;
        }
 }
 
-static void handle_tags_and_duplicates(struct path_list *extra_refs)
+static void handle_tags_and_duplicates(struct string_list *extra_refs)
 {
        struct commit *commit;
        int i;
 
        for (i = extra_refs->nr - 1; i >= 0; i--) {
-               const char *name = extra_refs->items[i].path;
+               const char *name = extra_refs->items[i].string;
                struct object *object = extra_refs->items[i].util;
                switch (object->type) {
                case OBJ_TAG:
@@ -382,7 +426,8 @@ static void export_marks(char *file)
        for (i = 0; i < idnums.size; i++) {
                if (deco->base && deco->base->type == 1) {
                        mark = ptr_to_mark(deco->decoration);
-                       fprintf(f, ":%u %s\n", mark, sha1_to_hex(deco->base->sha1));
+                       fprintf(f, ":%"PRIu32" %s\n", mark,
+                               sha1_to_hex(deco->base->sha1));
                }
                deco++;
        }
@@ -434,7 +479,7 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix)
 {
        struct rev_info revs;
        struct object_array commits = { 0, 0, NULL };
-       struct path_list extra_refs = { NULL, 0, 0, 0 };
+       struct string_list extra_refs = { NULL, 0, 0, 0 };
        struct commit *commit;
        char *export_filename = NULL, *import_filename = NULL;
        struct option options[] = {
@@ -447,9 +492,14 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix)
                             "Dump marks to this file"),
                OPT_STRING(0, "import-marks", &import_filename, "FILE",
                             "Import marks from this file"),
+               OPT_BOOLEAN(0, "fake-missing-tagger", &fake_missing_tagger,
+                            "Fake a tagger when tags lack one"),
                OPT_END()
        };
 
+       if (argc == 1)
+               usage_with_options (fast_export_usage, options);
+
        /* we handle encodings */
        git_config(git_default_config, NULL);