]> git.ipfire.org Git - thirdparty/git.git/blobdiff - builtin/fast-export.c
hashmap_get{,_from_hash} return "struct hashmap_entry *"
[thirdparty/git.git] / builtin / fast-export.c
index 9e283482efcfa6de0376cc9306061cea149b12df..25195badd4341bfe311c62550c73324e12c21df6 100644 (file)
@@ -33,6 +33,7 @@ static const char *fast_export_usage[] = {
 static int progress;
 static enum { SIGNED_TAG_ABORT, VERBATIM, WARN, WARN_STRIP, STRIP } signed_tag_mode = SIGNED_TAG_ABORT;
 static enum { TAG_FILTERING_ABORT, DROP, REWRITE } tag_of_filtered_mode = TAG_FILTERING_ABORT;
+static enum { REENCODE_ABORT, REENCODE_YES, REENCODE_NO } reencode_mode = REENCODE_ABORT;
 static int fake_missing_tagger;
 static int use_done_feature;
 static int no_data;
@@ -77,6 +78,31 @@ static int parse_opt_tag_of_filtered_mode(const struct option *opt,
        return 0;
 }
 
+static int parse_opt_reencode_mode(const struct option *opt,
+                                  const char *arg, int unset)
+{
+       if (unset) {
+               reencode_mode = REENCODE_ABORT;
+               return 0;
+       }
+
+       switch (git_parse_maybe_bool(arg)) {
+       case 0:
+               reencode_mode = REENCODE_NO;
+               break;
+       case 1:
+               reencode_mode = REENCODE_YES;
+               break;
+       default:
+               if (!strcasecmp(arg, "abort"))
+                       reencode_mode = REENCODE_ABORT;
+               else
+                       return error("Unknown reencoding mode: %s", arg);
+       }
+
+       return 0;
+}
+
 static struct decoration idnums;
 static uint32_t last_idnum;
 
@@ -122,10 +148,10 @@ static const void *anonymize_mem(struct hashmap *map,
        if (!map->cmpfn)
                hashmap_init(map, anonymized_entry_cmp, NULL, 0);
 
-       hashmap_entry_init(&key, memhash(orig, *len));
+       hashmap_entry_init(&key.hash, memhash(orig, *len));
        key.orig = orig;
        key.orig_len = *len;
-       ret = hashmap_get(map, &key, NULL);
+       ret = hashmap_get_entry(map, &key, NULL, struct anonymized_entry, hash);
 
        if (!ret) {
                ret = xmalloc(sizeof(*ret));
@@ -134,7 +160,7 @@ static const void *anonymize_mem(struct hashmap *map,
                ret->orig_len = *len;
                ret->anon = generate(orig, len);
                ret->anon_len = *len;
-               hashmap_put(map, ret);
+               hashmap_put(map, &ret->hash);
        }
 
        *len = ret->anon_len;
@@ -249,7 +275,7 @@ static void export_blob(const struct object_id *oid)
        if (is_null_oid(oid))
                return;
 
-       object = lookup_object(the_repository, oid->hash);
+       object = lookup_object(the_repository, oid);
        if (object && object->flags & SHOWN)
                return;
 
@@ -427,7 +453,7 @@ static void show_filemodify(struct diff_queue_struct *q,
                                                  &spec->oid));
                        else {
                                struct object *object = lookup_object(the_repository,
-                                                                     spec->oid.hash);
+                                                                     &spec->oid);
                                printf("M %06o :%d ", spec->mode,
                                       get_object_mark(object));
                        }
@@ -453,7 +479,7 @@ static const char *find_encoding(const char *begin, const char *end)
        bol = memmem(begin, end ? end - begin : strlen(begin),
                     needle, strlen(needle));
        if (!bol)
-               return git_commit_encoding;
+               return NULL;
        bol += strlen(needle);
        eol = strchrnul(bol, '\n');
        *eol = '\0';
@@ -633,18 +659,32 @@ static void handle_commit(struct commit *commit, struct rev_info *rev,
        }
 
        mark_next_object(&commit->object);
-       if (anonymize)
+       if (anonymize) {
                reencoded = anonymize_commit_message(message);
-       else if (!is_encoding_utf8(encoding))
-               reencoded = reencode_string(message, "UTF-8", encoding);
+       } else if (encoding) {
+               switch(reencode_mode) {
+               case REENCODE_YES:
+                       reencoded = reencode_string(message, "UTF-8", encoding);
+                       break;
+               case REENCODE_NO:
+                       break;
+               case REENCODE_ABORT:
+                       die("Encountered commit-specific encoding %s in commit "
+                           "%s; use --reencode=[yes|no] to handle it",
+                           encoding, oid_to_hex(&commit->object.oid));
+               }
+       }
        if (!commit->parents)
                printf("reset %s\n", refname);
        printf("commit %s\nmark :%"PRIu32"\n", refname, last_idnum);
        if (show_original_ids)
                printf("original-oid %s\n", oid_to_hex(&commit->object.oid));
-       printf("%.*s\n%.*s\ndata %u\n%s",
+       printf("%.*s\n%.*s\n",
               (int)(author_end - author), author,
-              (int)(committer_end - committer), committer,
+              (int)(committer_end - committer), committer);
+       if (!reencoded && encoding)
+               printf("encoding %s\n", encoding);
+       printf("data %u\n%s",
               (unsigned)(reencoded
                          ? strlen(reencoded) : message
                          ? strlen(message) : 0),
@@ -1088,6 +1128,9 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix)
                OPT_CALLBACK(0, "tag-of-filtered-object", &tag_of_filtered_mode, N_("mode"),
                             N_("select handling of tags that tag filtered objects"),
                             parse_opt_tag_of_filtered_mode),
+               OPT_CALLBACK(0, "reencode", &reencode_mode, N_("mode"),
+                            N_("select handling of commit messages in an alternate encoding"),
+                            parse_opt_reencode_mode),
                OPT_STRING(0, "export-marks", &export_filename, N_("file"),
                             N_("Dump marks to this file")),
                OPT_STRING(0, "import-marks", &import_filename, N_("file"),