Johannes Schindelin | f2dc849 | 2007-12-02 14:14:13 +0000 | [diff] [blame] | 1 | /* |
| 2 | * "git fast-export" builtin command |
| 3 | * |
| 4 | * Copyright (C) 2007 Johannes E. Schindelin |
| 5 | */ |
| 6 | #include "builtin.h" |
| 7 | #include "cache.h" |
Brandon Williams | b2141fc | 2017-06-14 11:07:36 -0700 | [diff] [blame] | 8 | #include "config.h" |
Michael Haggerty | fb58c8d | 2015-06-22 16:03:05 +0200 | [diff] [blame] | 9 | #include "refs.h" |
Johannes Schindelin | f2dc849 | 2007-12-02 14:14:13 +0000 | [diff] [blame] | 10 | #include "commit.h" |
| 11 | #include "object.h" |
| 12 | #include "tag.h" |
| 13 | #include "diff.h" |
| 14 | #include "diffcore.h" |
| 15 | #include "log-tree.h" |
| 16 | #include "revision.h" |
| 17 | #include "decorate.h" |
Johannes Schindelin | c455c87 | 2008-07-21 19:03:49 +0100 | [diff] [blame] | 18 | #include "string-list.h" |
Johannes Schindelin | f2dc849 | 2007-12-02 14:14:13 +0000 | [diff] [blame] | 19 | #include "utf8.h" |
| 20 | #include "parse-options.h" |
Jeff King | 6280dfd | 2011-08-05 16:36:22 -0600 | [diff] [blame] | 21 | #include "quote.h" |
Felipe Contreras | 03e9010 | 2014-04-20 13:59:24 -0500 | [diff] [blame] | 22 | #include "remote.h" |
Jeff King | a872275 | 2014-08-27 13:01:28 -0400 | [diff] [blame] | 23 | #include "blob.h" |
Johannes Schindelin | f2dc849 | 2007-12-02 14:14:13 +0000 | [diff] [blame] | 24 | |
| 25 | static const char *fast_export_usage[] = { |
Nguyễn Thái Ngọc Duy | 3b787b9 | 2012-08-20 19:32:08 +0700 | [diff] [blame] | 26 | N_("git fast-export [rev-list-opts]"), |
Johannes Schindelin | f2dc849 | 2007-12-02 14:14:13 +0000 | [diff] [blame] | 27 | NULL |
| 28 | }; |
| 29 | |
| 30 | static int progress; |
John Keeping | cd16c59 | 2013-04-14 11:57:06 +0100 | [diff] [blame] | 31 | static enum { ABORT, VERBATIM, WARN, WARN_STRIP, STRIP } signed_tag_mode = ABORT; |
Ævar Arnfjörð Bjarmason | d7a10c3 | 2011-12-21 01:18:19 +0000 | [diff] [blame] | 32 | static enum { ERROR, DROP, REWRITE } tag_of_filtered_mode = ERROR; |
Johannes Schindelin | 4e46a8d | 2008-12-20 01:00:27 +0100 | [diff] [blame] | 33 | static int fake_missing_tagger; |
Sverre Rabbelier | 82670a5 | 2011-07-16 15:03:33 +0200 | [diff] [blame] | 34 | static int use_done_feature; |
Geoffrey Irving | 79559f2 | 2009-07-27 22:20:22 -0400 | [diff] [blame] | 35 | static int no_data; |
Elijah Newren | 7f40ab0 | 2010-07-17 11:00:51 -0600 | [diff] [blame] | 36 | static int full_tree; |
Felipe Contreras | 1d844ee | 2013-09-01 02:05:47 -0500 | [diff] [blame] | 37 | static struct string_list extra_refs = STRING_LIST_INIT_NODUP; |
Felipe Contreras | 03e9010 | 2014-04-20 13:59:24 -0500 | [diff] [blame] | 38 | static struct refspec *refspecs; |
| 39 | static int refspecs_nr; |
Jeff King | a872275 | 2014-08-27 13:01:28 -0400 | [diff] [blame] | 40 | static int anonymize; |
Johannes Schindelin | f2dc849 | 2007-12-02 14:14:13 +0000 | [diff] [blame] | 41 | |
| 42 | static int parse_opt_signed_tag_mode(const struct option *opt, |
| 43 | const char *arg, int unset) |
| 44 | { |
| 45 | if (unset || !strcmp(arg, "abort")) |
| 46 | signed_tag_mode = ABORT; |
Johannes Schindelin | ee4bc37 | 2007-12-03 22:44:39 +0000 | [diff] [blame] | 47 | else if (!strcmp(arg, "verbatim") || !strcmp(arg, "ignore")) |
| 48 | signed_tag_mode = VERBATIM; |
Johannes Schindelin | f2dc849 | 2007-12-02 14:14:13 +0000 | [diff] [blame] | 49 | else if (!strcmp(arg, "warn")) |
| 50 | signed_tag_mode = WARN; |
John Keeping | cd16c59 | 2013-04-14 11:57:06 +0100 | [diff] [blame] | 51 | else if (!strcmp(arg, "warn-strip")) |
| 52 | signed_tag_mode = WARN_STRIP; |
Johannes Schindelin | f2dc849 | 2007-12-02 14:14:13 +0000 | [diff] [blame] | 53 | else if (!strcmp(arg, "strip")) |
| 54 | signed_tag_mode = STRIP; |
| 55 | else |
Paul Price | 04a74b6 | 2013-04-12 10:05:55 -0400 | [diff] [blame] | 56 | return error("Unknown signed-tags mode: %s", arg); |
Johannes Schindelin | f2dc849 | 2007-12-02 14:14:13 +0000 | [diff] [blame] | 57 | return 0; |
| 58 | } |
| 59 | |
Elijah Newren | 2d8ad46 | 2009-06-25 22:48:31 -0600 | [diff] [blame] | 60 | static int parse_opt_tag_of_filtered_mode(const struct option *opt, |
| 61 | const char *arg, int unset) |
| 62 | { |
| 63 | if (unset || !strcmp(arg, "abort")) |
Ævar Arnfjörð Bjarmason | d7a10c3 | 2011-12-21 01:18:19 +0000 | [diff] [blame] | 64 | tag_of_filtered_mode = ERROR; |
Elijah Newren | 2d8ad46 | 2009-06-25 22:48:31 -0600 | [diff] [blame] | 65 | else if (!strcmp(arg, "drop")) |
| 66 | tag_of_filtered_mode = DROP; |
| 67 | else if (!strcmp(arg, "rewrite")) |
| 68 | tag_of_filtered_mode = REWRITE; |
| 69 | else |
| 70 | return error("Unknown tag-of-filtered mode: %s", arg); |
| 71 | return 0; |
| 72 | } |
| 73 | |
Johannes Schindelin | f2dc849 | 2007-12-02 14:14:13 +0000 | [diff] [blame] | 74 | static struct decoration idnums; |
| 75 | static uint32_t last_idnum; |
| 76 | |
| 77 | static int has_unshown_parent(struct commit *commit) |
| 78 | { |
| 79 | struct commit_list *parent; |
| 80 | |
| 81 | for (parent = commit->parents; parent; parent = parent->next) |
| 82 | if (!(parent->item->object.flags & SHOWN) && |
| 83 | !(parent->item->object.flags & UNINTERESTING)) |
| 84 | return 1; |
| 85 | return 0; |
| 86 | } |
| 87 | |
Jeff King | a872275 | 2014-08-27 13:01:28 -0400 | [diff] [blame] | 88 | struct anonymized_entry { |
| 89 | struct hashmap_entry hash; |
| 90 | const char *orig; |
| 91 | size_t orig_len; |
| 92 | const char *anon; |
| 93 | size_t anon_len; |
| 94 | }; |
| 95 | |
Stefan Beller | 7663cdc | 2017-06-30 12:14:05 -0700 | [diff] [blame] | 96 | static int anonymized_entry_cmp(const void *unused_cmp_data, |
| 97 | const void *va, const void *vb, |
| 98 | const void *unused_keydata) |
Jeff King | a872275 | 2014-08-27 13:01:28 -0400 | [diff] [blame] | 99 | { |
| 100 | const struct anonymized_entry *a = va, *b = vb; |
| 101 | return a->orig_len != b->orig_len || |
| 102 | memcmp(a->orig, b->orig, a->orig_len); |
| 103 | } |
| 104 | |
| 105 | /* |
| 106 | * Basically keep a cache of X->Y so that we can repeatedly replace |
| 107 | * the same anonymized string with another. The actual generation |
| 108 | * is farmed out to the generate function. |
| 109 | */ |
| 110 | static const void *anonymize_mem(struct hashmap *map, |
| 111 | void *(*generate)(const void *, size_t *), |
| 112 | const void *orig, size_t *len) |
| 113 | { |
| 114 | struct anonymized_entry key, *ret; |
| 115 | |
| 116 | if (!map->cmpfn) |
Stefan Beller | 7663cdc | 2017-06-30 12:14:05 -0700 | [diff] [blame] | 117 | hashmap_init(map, anonymized_entry_cmp, NULL, 0); |
Jeff King | a872275 | 2014-08-27 13:01:28 -0400 | [diff] [blame] | 118 | |
| 119 | hashmap_entry_init(&key, memhash(orig, *len)); |
| 120 | key.orig = orig; |
| 121 | key.orig_len = *len; |
| 122 | ret = hashmap_get(map, &key, NULL); |
| 123 | |
| 124 | if (!ret) { |
| 125 | ret = xmalloc(sizeof(*ret)); |
| 126 | hashmap_entry_init(&ret->hash, key.hash.hash); |
| 127 | ret->orig = xstrdup(orig); |
| 128 | ret->orig_len = *len; |
| 129 | ret->anon = generate(orig, len); |
| 130 | ret->anon_len = *len; |
| 131 | hashmap_put(map, ret); |
| 132 | } |
| 133 | |
| 134 | *len = ret->anon_len; |
| 135 | return ret->anon; |
| 136 | } |
| 137 | |
| 138 | /* |
| 139 | * We anonymize each component of a path individually, |
| 140 | * so that paths a/b and a/c will share a common root. |
| 141 | * The paths are cached via anonymize_mem so that repeated |
| 142 | * lookups for "a" will yield the same value. |
| 143 | */ |
| 144 | static void anonymize_path(struct strbuf *out, const char *path, |
| 145 | struct hashmap *map, |
| 146 | void *(*generate)(const void *, size_t *)) |
| 147 | { |
| 148 | while (*path) { |
| 149 | const char *end_of_component = strchrnul(path, '/'); |
| 150 | size_t len = end_of_component - path; |
| 151 | const char *c = anonymize_mem(map, generate, path, &len); |
| 152 | strbuf_add(out, c, len); |
| 153 | path = end_of_component; |
| 154 | if (*path) |
| 155 | strbuf_addch(out, *path++); |
| 156 | } |
| 157 | } |
| 158 | |
Johannes Schindelin | f2dc849 | 2007-12-02 14:14:13 +0000 | [diff] [blame] | 159 | /* Since intptr_t is C99, we do not use it here */ |
Pieter de Bie | df6a7ff | 2008-06-11 13:17:04 +0200 | [diff] [blame] | 160 | static inline uint32_t *mark_to_ptr(uint32_t mark) |
Johannes Schindelin | f2dc849 | 2007-12-02 14:14:13 +0000 | [diff] [blame] | 161 | { |
Pieter de Bie | df6a7ff | 2008-06-11 13:17:04 +0200 | [diff] [blame] | 162 | return ((uint32_t *)NULL) + mark; |
| 163 | } |
| 164 | |
| 165 | static inline uint32_t ptr_to_mark(void * mark) |
| 166 | { |
| 167 | return (uint32_t *)mark - (uint32_t *)NULL; |
| 168 | } |
| 169 | |
| 170 | static inline void mark_object(struct object *object, uint32_t mark) |
| 171 | { |
| 172 | add_decoration(&idnums, object, mark_to_ptr(mark)); |
| 173 | } |
| 174 | |
| 175 | static inline void mark_next_object(struct object *object) |
| 176 | { |
| 177 | mark_object(object, ++last_idnum); |
Johannes Schindelin | f2dc849 | 2007-12-02 14:14:13 +0000 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | static int get_object_mark(struct object *object) |
| 181 | { |
| 182 | void *decoration = lookup_decoration(&idnums, object); |
| 183 | if (!decoration) |
| 184 | return 0; |
Pieter de Bie | df6a7ff | 2008-06-11 13:17:04 +0200 | [diff] [blame] | 185 | return ptr_to_mark(decoration); |
Johannes Schindelin | f2dc849 | 2007-12-02 14:14:13 +0000 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | static void show_progress(void) |
| 189 | { |
| 190 | static int counter = 0; |
| 191 | if (!progress) |
| 192 | return; |
| 193 | if ((++counter % progress) == 0) |
| 194 | printf("progress %d objects\n", counter); |
| 195 | } |
| 196 | |
Jeff King | a872275 | 2014-08-27 13:01:28 -0400 | [diff] [blame] | 197 | /* |
| 198 | * Ideally we would want some transformation of the blob data here |
| 199 | * that is unreversible, but would still be the same size and have |
| 200 | * the same data relationship to other blobs (so that we get the same |
| 201 | * delta and packing behavior as the original). But the first and last |
| 202 | * requirements there are probably mutually exclusive, so let's take |
| 203 | * the easy way out for now, and just generate arbitrary content. |
| 204 | * |
| 205 | * There's no need to cache this result with anonymize_mem, since |
| 206 | * we already handle blob content caching with marks. |
| 207 | */ |
| 208 | static char *anonymize_blob(unsigned long *size) |
| 209 | { |
| 210 | static int counter; |
| 211 | struct strbuf out = STRBUF_INIT; |
| 212 | strbuf_addf(&out, "anonymous blob %d", counter++); |
| 213 | *size = out.len; |
| 214 | return strbuf_detach(&out, NULL); |
| 215 | } |
| 216 | |
brian m. carlson | 273f8ee | 2017-02-21 23:47:23 +0000 | [diff] [blame] | 217 | static void export_blob(const struct object_id *oid) |
Johannes Schindelin | f2dc849 | 2007-12-02 14:14:13 +0000 | [diff] [blame] | 218 | { |
| 219 | unsigned long size; |
| 220 | enum object_type type; |
| 221 | char *buf; |
| 222 | struct object *object; |
Jeff King | 30b939c | 2013-03-17 04:38:57 -0400 | [diff] [blame] | 223 | int eaten; |
Johannes Schindelin | f2dc849 | 2007-12-02 14:14:13 +0000 | [diff] [blame] | 224 | |
Geoffrey Irving | 79559f2 | 2009-07-27 22:20:22 -0400 | [diff] [blame] | 225 | if (no_data) |
| 226 | return; |
| 227 | |
brian m. carlson | 273f8ee | 2017-02-21 23:47:23 +0000 | [diff] [blame] | 228 | if (is_null_oid(oid)) |
Johannes Schindelin | f2dc849 | 2007-12-02 14:14:13 +0000 | [diff] [blame] | 229 | return; |
| 230 | |
brian m. carlson | 273f8ee | 2017-02-21 23:47:23 +0000 | [diff] [blame] | 231 | object = lookup_object(oid->hash); |
Jeff King | 30b939c | 2013-03-17 04:38:57 -0400 | [diff] [blame] | 232 | if (object && object->flags & SHOWN) |
Johannes Schindelin | f2dc849 | 2007-12-02 14:14:13 +0000 | [diff] [blame] | 233 | return; |
| 234 | |
Jeff King | a872275 | 2014-08-27 13:01:28 -0400 | [diff] [blame] | 235 | if (anonymize) { |
| 236 | buf = anonymize_blob(&size); |
brian m. carlson | 3aca1fc | 2017-05-06 22:10:14 +0000 | [diff] [blame] | 237 | object = (struct object *)lookup_blob(oid); |
Jeff King | a872275 | 2014-08-27 13:01:28 -0400 | [diff] [blame] | 238 | eaten = 0; |
| 239 | } else { |
brian m. carlson | 273f8ee | 2017-02-21 23:47:23 +0000 | [diff] [blame] | 240 | buf = read_sha1_file(oid->hash, &type, &size); |
Jeff King | a872275 | 2014-08-27 13:01:28 -0400 | [diff] [blame] | 241 | if (!buf) |
brian m. carlson | 273f8ee | 2017-02-21 23:47:23 +0000 | [diff] [blame] | 242 | die ("Could not read blob %s", oid_to_hex(oid)); |
| 243 | if (check_sha1_signature(oid->hash, buf, size, typename(type)) < 0) |
| 244 | die("sha1 mismatch in blob %s", oid_to_hex(oid)); |
brian m. carlson | c251c83 | 2017-05-06 22:10:38 +0000 | [diff] [blame] | 245 | object = parse_object_buffer(oid, type, size, buf, &eaten); |
Jeff King | a872275 | 2014-08-27 13:01:28 -0400 | [diff] [blame] | 246 | } |
| 247 | |
Jeff King | 30b939c | 2013-03-17 04:38:57 -0400 | [diff] [blame] | 248 | if (!object) |
brian m. carlson | 273f8ee | 2017-02-21 23:47:23 +0000 | [diff] [blame] | 249 | die("Could not read blob %s", oid_to_hex(oid)); |
Johannes Schindelin | f2dc849 | 2007-12-02 14:14:13 +0000 | [diff] [blame] | 250 | |
Pieter de Bie | df6a7ff | 2008-06-11 13:17:04 +0200 | [diff] [blame] | 251 | mark_next_object(object); |
Johannes Schindelin | f2dc849 | 2007-12-02 14:14:13 +0000 | [diff] [blame] | 252 | |
Ramsay Jones | 6e1c234 | 2008-07-03 16:52:09 +0100 | [diff] [blame] | 253 | printf("blob\nmark :%"PRIu32"\ndata %lu\n", last_idnum, size); |
Alex Riesen | b0fe0d7 | 2007-12-11 23:01:28 +0100 | [diff] [blame] | 254 | if (size && fwrite(buf, size, 1, stdout) != 1) |
brian m. carlson | 273f8ee | 2017-02-21 23:47:23 +0000 | [diff] [blame] | 255 | die_errno ("Could not write blob '%s'", oid_to_hex(oid)); |
Johannes Schindelin | f2dc849 | 2007-12-02 14:14:13 +0000 | [diff] [blame] | 256 | printf("\n"); |
| 257 | |
| 258 | show_progress(); |
| 259 | |
| 260 | object->flags |= SHOWN; |
Jeff King | 30b939c | 2013-03-17 04:38:57 -0400 | [diff] [blame] | 261 | if (!eaten) |
| 262 | free(buf); |
Johannes Schindelin | f2dc849 | 2007-12-02 14:14:13 +0000 | [diff] [blame] | 263 | } |
| 264 | |
Elijah Newren | 060df62 | 2010-07-09 07:10:55 -0600 | [diff] [blame] | 265 | static int depth_first(const void *a_, const void *b_) |
| 266 | { |
| 267 | const struct diff_filepair *a = *((const struct diff_filepair **)a_); |
| 268 | const struct diff_filepair *b = *((const struct diff_filepair **)b_); |
| 269 | const char *name_a, *name_b; |
| 270 | int len_a, len_b, len; |
| 271 | int cmp; |
| 272 | |
| 273 | name_a = a->one ? a->one->path : a->two->path; |
| 274 | name_b = b->one ? b->one->path : b->two->path; |
| 275 | |
| 276 | len_a = strlen(name_a); |
| 277 | len_b = strlen(name_b); |
| 278 | len = (len_a < len_b) ? len_a : len_b; |
| 279 | |
| 280 | /* strcmp will sort 'd' before 'd/e', we want 'd/e' before 'd' */ |
| 281 | cmp = memcmp(name_a, name_b, len); |
| 282 | if (cmp) |
| 283 | return cmp; |
Johannes Sixt | 4ce6fb8 | 2010-09-07 21:33:02 +0200 | [diff] [blame] | 284 | cmp = len_b - len_a; |
| 285 | if (cmp) |
| 286 | return cmp; |
| 287 | /* |
| 288 | * Move 'R'ename entries last so that all references of the file |
| 289 | * appear in the output before it is renamed (e.g., when a file |
| 290 | * was copied and renamed in the same commit). |
| 291 | */ |
| 292 | return (a->status == 'R') - (b->status == 'R'); |
Elijah Newren | 060df62 | 2010-07-09 07:10:55 -0600 | [diff] [blame] | 293 | } |
| 294 | |
Jeff King | a872275 | 2014-08-27 13:01:28 -0400 | [diff] [blame] | 295 | static void print_path_1(const char *path) |
Jeff King | 6280dfd | 2011-08-05 16:36:22 -0600 | [diff] [blame] | 296 | { |
| 297 | int need_quote = quote_c_style(path, NULL, NULL, 0); |
| 298 | if (need_quote) |
| 299 | quote_c_style(path, NULL, stdout, 0); |
Jay Soffian | ff59f6d | 2012-06-27 17:58:01 -0400 | [diff] [blame] | 300 | else if (strchr(path, ' ')) |
| 301 | printf("\"%s\"", path); |
Jeff King | 6280dfd | 2011-08-05 16:36:22 -0600 | [diff] [blame] | 302 | else |
| 303 | printf("%s", path); |
| 304 | } |
| 305 | |
Jeff King | a872275 | 2014-08-27 13:01:28 -0400 | [diff] [blame] | 306 | static void *anonymize_path_component(const void *path, size_t *len) |
| 307 | { |
| 308 | static int counter; |
| 309 | struct strbuf out = STRBUF_INIT; |
| 310 | strbuf_addf(&out, "path%d", counter++); |
| 311 | return strbuf_detach(&out, len); |
| 312 | } |
| 313 | |
| 314 | static void print_path(const char *path) |
| 315 | { |
| 316 | if (!anonymize) |
| 317 | print_path_1(path); |
| 318 | else { |
| 319 | static struct hashmap paths; |
| 320 | static struct strbuf anon = STRBUF_INIT; |
| 321 | |
| 322 | anonymize_path(&anon, path, &paths, anonymize_path_component); |
| 323 | print_path_1(anon.buf); |
| 324 | strbuf_reset(&anon); |
| 325 | } |
| 326 | } |
| 327 | |
brian m. carlson | 273f8ee | 2017-02-21 23:47:23 +0000 | [diff] [blame] | 328 | static void *generate_fake_oid(const void *old, size_t *len) |
Jeff King | a872275 | 2014-08-27 13:01:28 -0400 | [diff] [blame] | 329 | { |
| 330 | static uint32_t counter = 1; /* avoid null sha1 */ |
brian m. carlson | 273f8ee | 2017-02-21 23:47:23 +0000 | [diff] [blame] | 331 | unsigned char *out = xcalloc(GIT_SHA1_RAWSZ, 1); |
| 332 | put_be32(out + GIT_SHA1_RAWSZ - 4, counter++); |
Jeff King | a872275 | 2014-08-27 13:01:28 -0400 | [diff] [blame] | 333 | return out; |
| 334 | } |
| 335 | |
brian m. carlson | 273f8ee | 2017-02-21 23:47:23 +0000 | [diff] [blame] | 336 | static const unsigned char *anonymize_sha1(const struct object_id *oid) |
Jeff King | a872275 | 2014-08-27 13:01:28 -0400 | [diff] [blame] | 337 | { |
| 338 | static struct hashmap sha1s; |
brian m. carlson | 273f8ee | 2017-02-21 23:47:23 +0000 | [diff] [blame] | 339 | size_t len = GIT_SHA1_RAWSZ; |
| 340 | return anonymize_mem(&sha1s, generate_fake_oid, oid, &len); |
Jeff King | a872275 | 2014-08-27 13:01:28 -0400 | [diff] [blame] | 341 | } |
| 342 | |
Johannes Schindelin | f2dc849 | 2007-12-02 14:14:13 +0000 | [diff] [blame] | 343 | static void show_filemodify(struct diff_queue_struct *q, |
| 344 | struct diff_options *options, void *data) |
| 345 | { |
| 346 | int i; |
Jonathan Tan | b3e8ca8 | 2017-09-20 16:55:02 -0700 | [diff] [blame] | 347 | struct string_list *changed = data; |
Elijah Newren | 060df62 | 2010-07-09 07:10:55 -0600 | [diff] [blame] | 348 | |
| 349 | /* |
| 350 | * Handle files below a directory first, in case they are all deleted |
| 351 | * and the directory changes to a file or symlink. |
| 352 | */ |
René Scharfe | 9ed0d8d | 2016-09-29 17:27:31 +0200 | [diff] [blame] | 353 | QSORT(q->queue, q->nr, depth_first); |
Elijah Newren | 060df62 | 2010-07-09 07:10:55 -0600 | [diff] [blame] | 354 | |
Johannes Schindelin | f2dc849 | 2007-12-02 14:14:13 +0000 | [diff] [blame] | 355 | for (i = 0; i < q->nr; i++) { |
Alexander Gavrilov | ae7c5dc | 2008-07-27 00:52:54 +0400 | [diff] [blame] | 356 | struct diff_filespec *ospec = q->queue[i]->one; |
Johannes Schindelin | f2dc849 | 2007-12-02 14:14:13 +0000 | [diff] [blame] | 357 | struct diff_filespec *spec = q->queue[i]->two; |
Alexander Gavrilov | ae7c5dc | 2008-07-27 00:52:54 +0400 | [diff] [blame] | 358 | |
| 359 | switch (q->queue[i]->status) { |
| 360 | case DIFF_STATUS_DELETED: |
Jeff King | 6280dfd | 2011-08-05 16:36:22 -0600 | [diff] [blame] | 361 | printf("D "); |
| 362 | print_path(spec->path); |
Jonathan Tan | b3e8ca8 | 2017-09-20 16:55:02 -0700 | [diff] [blame] | 363 | string_list_insert(changed, spec->path); |
Jeff King | 6280dfd | 2011-08-05 16:36:22 -0600 | [diff] [blame] | 364 | putchar('\n'); |
Alexander Gavrilov | ae7c5dc | 2008-07-27 00:52:54 +0400 | [diff] [blame] | 365 | break; |
| 366 | |
| 367 | case DIFF_STATUS_COPIED: |
| 368 | case DIFF_STATUS_RENAMED: |
Jonathan Tan | b3e8ca8 | 2017-09-20 16:55:02 -0700 | [diff] [blame] | 369 | /* |
| 370 | * If a change in the file corresponding to ospec->path |
| 371 | * has been observed, we cannot trust its contents |
| 372 | * because the diff is calculated based on the prior |
| 373 | * contents, not the current contents. So, declare a |
| 374 | * copy or rename only if there was no change observed. |
| 375 | */ |
| 376 | if (!string_list_has_string(changed, ospec->path)) { |
| 377 | printf("%c ", q->queue[i]->status); |
| 378 | print_path(ospec->path); |
| 379 | putchar(' '); |
| 380 | print_path(spec->path); |
| 381 | string_list_insert(changed, spec->path); |
| 382 | putchar('\n'); |
Alexander Gavrilov | ae7c5dc | 2008-07-27 00:52:54 +0400 | [diff] [blame] | 383 | |
Jonathan Tan | b3e8ca8 | 2017-09-20 16:55:02 -0700 | [diff] [blame] | 384 | if (!oidcmp(&ospec->oid, &spec->oid) && |
| 385 | ospec->mode == spec->mode) |
| 386 | break; |
| 387 | } |
Alexander Gavrilov | ae7c5dc | 2008-07-27 00:52:54 +0400 | [diff] [blame] | 388 | /* fallthrough */ |
| 389 | |
| 390 | case DIFF_STATUS_TYPE_CHANGED: |
| 391 | case DIFF_STATUS_MODIFIED: |
| 392 | case DIFF_STATUS_ADDED: |
Alexander Gavrilov | 03db452 | 2008-07-19 16:21:24 +0400 | [diff] [blame] | 393 | /* |
| 394 | * Links refer to objects in another repositories; |
| 395 | * output the SHA-1 verbatim. |
| 396 | */ |
Geoffrey Irving | 79559f2 | 2009-07-27 22:20:22 -0400 | [diff] [blame] | 397 | if (no_data || S_ISGITLINK(spec->mode)) |
Jeff King | 6280dfd | 2011-08-05 16:36:22 -0600 | [diff] [blame] | 398 | printf("M %06o %s ", spec->mode, |
Jeff King | a872275 | 2014-08-27 13:01:28 -0400 | [diff] [blame] | 399 | sha1_to_hex(anonymize ? |
brian m. carlson | 273f8ee | 2017-02-21 23:47:23 +0000 | [diff] [blame] | 400 | anonymize_sha1(&spec->oid) : |
brian m. carlson | a0d12c4 | 2016-06-24 23:09:23 +0000 | [diff] [blame] | 401 | spec->oid.hash)); |
Alexander Gavrilov | 03db452 | 2008-07-19 16:21:24 +0400 | [diff] [blame] | 402 | else { |
brian m. carlson | a0d12c4 | 2016-06-24 23:09:23 +0000 | [diff] [blame] | 403 | struct object *object = lookup_object(spec->oid.hash); |
Jeff King | 6280dfd | 2011-08-05 16:36:22 -0600 | [diff] [blame] | 404 | printf("M %06o :%d ", spec->mode, |
| 405 | get_object_mark(object)); |
Alexander Gavrilov | 03db452 | 2008-07-19 16:21:24 +0400 | [diff] [blame] | 406 | } |
Jeff King | 6280dfd | 2011-08-05 16:36:22 -0600 | [diff] [blame] | 407 | print_path(spec->path); |
Jonathan Tan | b3e8ca8 | 2017-09-20 16:55:02 -0700 | [diff] [blame] | 408 | string_list_insert(changed, spec->path); |
Jeff King | 6280dfd | 2011-08-05 16:36:22 -0600 | [diff] [blame] | 409 | putchar('\n'); |
Alexander Gavrilov | ae7c5dc | 2008-07-27 00:52:54 +0400 | [diff] [blame] | 410 | break; |
| 411 | |
| 412 | default: |
| 413 | die("Unexpected comparison status '%c' for %s, %s", |
| 414 | q->queue[i]->status, |
| 415 | ospec->path ? ospec->path : "none", |
| 416 | spec->path ? spec->path : "none"); |
Johannes Schindelin | f2dc849 | 2007-12-02 14:14:13 +0000 | [diff] [blame] | 417 | } |
| 418 | } |
| 419 | } |
| 420 | |
| 421 | static const char *find_encoding(const char *begin, const char *end) |
| 422 | { |
| 423 | const char *needle = "\nencoding "; |
| 424 | char *bol, *eol; |
| 425 | |
| 426 | bol = memmem(begin, end ? end - begin : strlen(begin), |
| 427 | needle, strlen(needle)); |
| 428 | if (!bol) |
| 429 | return git_commit_encoding; |
| 430 | bol += strlen(needle); |
| 431 | eol = strchrnul(bol, '\n'); |
| 432 | *eol = '\0'; |
| 433 | return bol; |
| 434 | } |
| 435 | |
Jeff King | a872275 | 2014-08-27 13:01:28 -0400 | [diff] [blame] | 436 | static void *anonymize_ref_component(const void *old, size_t *len) |
| 437 | { |
| 438 | static int counter; |
| 439 | struct strbuf out = STRBUF_INIT; |
| 440 | strbuf_addf(&out, "ref%d", counter++); |
| 441 | return strbuf_detach(&out, len); |
| 442 | } |
| 443 | |
| 444 | static const char *anonymize_refname(const char *refname) |
| 445 | { |
| 446 | /* |
| 447 | * If any of these prefixes is found, we will leave it intact |
| 448 | * so that tags remain tags and so forth. |
| 449 | */ |
| 450 | static const char *prefixes[] = { |
| 451 | "refs/heads/", |
| 452 | "refs/tags/", |
| 453 | "refs/remotes/", |
| 454 | "refs/" |
| 455 | }; |
| 456 | static struct hashmap refs; |
| 457 | static struct strbuf anon = STRBUF_INIT; |
| 458 | int i; |
| 459 | |
| 460 | /* |
| 461 | * We also leave "master" as a special case, since it does not reveal |
| 462 | * anything interesting. |
| 463 | */ |
| 464 | if (!strcmp(refname, "refs/heads/master")) |
| 465 | return refname; |
| 466 | |
| 467 | strbuf_reset(&anon); |
| 468 | for (i = 0; i < ARRAY_SIZE(prefixes); i++) { |
| 469 | if (skip_prefix(refname, prefixes[i], &refname)) { |
| 470 | strbuf_addstr(&anon, prefixes[i]); |
| 471 | break; |
| 472 | } |
| 473 | } |
| 474 | |
| 475 | anonymize_path(&anon, refname, &refs, anonymize_ref_component); |
| 476 | return anon.buf; |
| 477 | } |
| 478 | |
| 479 | /* |
| 480 | * We do not even bother to cache commit messages, as they are unlikely |
| 481 | * to be repeated verbatim, and it is not that interesting when they are. |
| 482 | */ |
| 483 | static char *anonymize_commit_message(const char *old) |
| 484 | { |
| 485 | static int counter; |
| 486 | return xstrfmt("subject %d\n\nbody\n", counter++); |
| 487 | } |
| 488 | |
| 489 | static struct hashmap idents; |
| 490 | static void *anonymize_ident(const void *old, size_t *len) |
| 491 | { |
| 492 | static int counter; |
| 493 | struct strbuf out = STRBUF_INIT; |
| 494 | strbuf_addf(&out, "User %d <user%d@example.com>", counter, counter); |
| 495 | counter++; |
| 496 | return strbuf_detach(&out, len); |
| 497 | } |
| 498 | |
| 499 | /* |
| 500 | * Our strategy here is to anonymize the names and email addresses, |
| 501 | * but keep timestamps intact, as they influence things like traversal |
| 502 | * order (and by themselves should not be too revealing). |
| 503 | */ |
| 504 | static void anonymize_ident_line(const char **beg, const char **end) |
| 505 | { |
| 506 | static struct strbuf buffers[] = { STRBUF_INIT, STRBUF_INIT }; |
| 507 | static unsigned which_buffer; |
| 508 | |
| 509 | struct strbuf *out; |
| 510 | struct ident_split split; |
| 511 | const char *end_of_header; |
| 512 | |
| 513 | out = &buffers[which_buffer++]; |
| 514 | which_buffer %= ARRAY_SIZE(buffers); |
| 515 | strbuf_reset(out); |
| 516 | |
| 517 | /* skip "committer", "author", "tagger", etc */ |
| 518 | end_of_header = strchr(*beg, ' '); |
| 519 | if (!end_of_header) |
| 520 | die("BUG: malformed line fed to anonymize_ident_line: %.*s", |
| 521 | (int)(*end - *beg), *beg); |
| 522 | end_of_header++; |
| 523 | strbuf_add(out, *beg, end_of_header - *beg); |
| 524 | |
| 525 | if (!split_ident_line(&split, end_of_header, *end - end_of_header) && |
| 526 | split.date_begin) { |
| 527 | const char *ident; |
| 528 | size_t len; |
| 529 | |
| 530 | len = split.mail_end - split.name_begin; |
| 531 | ident = anonymize_mem(&idents, anonymize_ident, |
| 532 | split.name_begin, &len); |
| 533 | strbuf_add(out, ident, len); |
| 534 | strbuf_addch(out, ' '); |
| 535 | strbuf_add(out, split.date_begin, split.tz_end - split.date_begin); |
| 536 | } else { |
| 537 | strbuf_addstr(out, "Malformed Ident <malformed@example.com> 0 -0000"); |
| 538 | } |
| 539 | |
| 540 | *beg = out->buf; |
| 541 | *end = out->buf + out->len; |
| 542 | } |
| 543 | |
Jonathan Tan | b3e8ca8 | 2017-09-20 16:55:02 -0700 | [diff] [blame] | 544 | static void handle_commit(struct commit *commit, struct rev_info *rev, |
| 545 | struct string_list *paths_of_changed_objects) |
Johannes Schindelin | f2dc849 | 2007-12-02 14:14:13 +0000 | [diff] [blame] | 546 | { |
| 547 | int saved_output_format = rev->diffopt.output_format; |
Jeff King | bc6b8fc | 2014-06-10 17:41:51 -0400 | [diff] [blame] | 548 | const char *commit_buffer; |
Johannes Schindelin | f2dc849 | 2007-12-02 14:14:13 +0000 | [diff] [blame] | 549 | const char *author, *author_end, *committer, *committer_end; |
| 550 | const char *encoding, *message; |
| 551 | char *reencoded = NULL; |
| 552 | struct commit_list *p; |
Jeff King | a872275 | 2014-08-27 13:01:28 -0400 | [diff] [blame] | 553 | const char *refname; |
Johannes Schindelin | f2dc849 | 2007-12-02 14:14:13 +0000 | [diff] [blame] | 554 | int i; |
| 555 | |
| 556 | rev->diffopt.output_format = DIFF_FORMAT_CALLBACK; |
| 557 | |
Jeff King | 683ff88 | 2013-10-24 04:53:46 -0400 | [diff] [blame] | 558 | parse_commit_or_die(commit); |
Jeff King | 8597ea3 | 2014-06-10 17:44:13 -0400 | [diff] [blame] | 559 | commit_buffer = get_commit_buffer(commit, NULL); |
Jeff King | bc6b8fc | 2014-06-10 17:41:51 -0400 | [diff] [blame] | 560 | author = strstr(commit_buffer, "\nauthor "); |
Johannes Schindelin | f2dc849 | 2007-12-02 14:14:13 +0000 | [diff] [blame] | 561 | if (!author) |
| 562 | die ("Could not find author in commit %s", |
brian m. carlson | f2fd076 | 2015-11-10 02:22:28 +0000 | [diff] [blame] | 563 | oid_to_hex(&commit->object.oid)); |
Johannes Schindelin | f2dc849 | 2007-12-02 14:14:13 +0000 | [diff] [blame] | 564 | author++; |
| 565 | author_end = strchrnul(author, '\n'); |
| 566 | committer = strstr(author_end, "\ncommitter "); |
| 567 | if (!committer) |
| 568 | die ("Could not find committer in commit %s", |
brian m. carlson | f2fd076 | 2015-11-10 02:22:28 +0000 | [diff] [blame] | 569 | oid_to_hex(&commit->object.oid)); |
Johannes Schindelin | f2dc849 | 2007-12-02 14:14:13 +0000 | [diff] [blame] | 570 | committer++; |
| 571 | committer_end = strchrnul(committer, '\n'); |
| 572 | message = strstr(committer_end, "\n\n"); |
| 573 | encoding = find_encoding(committer_end, message); |
| 574 | if (message) |
| 575 | message += 2; |
| 576 | |
Elijah Newren | ebeec7d | 2009-03-25 17:53:23 -0600 | [diff] [blame] | 577 | if (commit->parents && |
Elijah Newren | 4087a02 | 2010-07-17 11:00:50 -0600 | [diff] [blame] | 578 | get_object_mark(&commit->parents->item->object) != 0 && |
| 579 | !full_tree) { |
Jeff King | 683ff88 | 2013-10-24 04:53:46 -0400 | [diff] [blame] | 580 | parse_commit_or_die(commit->parents->item); |
Brandon Williams | 66f414f | 2017-05-30 10:31:03 -0700 | [diff] [blame] | 581 | diff_tree_oid(&commit->parents->item->tree->object.oid, |
| 582 | &commit->tree->object.oid, "", &rev->diffopt); |
Johannes Schindelin | f2dc849 | 2007-12-02 14:14:13 +0000 | [diff] [blame] | 583 | } |
| 584 | else |
Brandon Williams | 7b8dea0 | 2017-05-30 10:30:57 -0700 | [diff] [blame] | 585 | diff_root_tree_oid(&commit->tree->object.oid, |
| 586 | "", &rev->diffopt); |
Johannes Schindelin | f2dc849 | 2007-12-02 14:14:13 +0000 | [diff] [blame] | 587 | |
Alexander Gavrilov | 03db452 | 2008-07-19 16:21:24 +0400 | [diff] [blame] | 588 | /* Export the referenced blobs, and remember the marks. */ |
Johannes Schindelin | f2dc849 | 2007-12-02 14:14:13 +0000 | [diff] [blame] | 589 | for (i = 0; i < diff_queued_diff.nr; i++) |
Alexander Gavrilov | 03db452 | 2008-07-19 16:21:24 +0400 | [diff] [blame] | 590 | if (!S_ISGITLINK(diff_queued_diff.queue[i]->two->mode)) |
brian m. carlson | 273f8ee | 2017-02-21 23:47:23 +0000 | [diff] [blame] | 591 | export_blob(&diff_queued_diff.queue[i]->two->oid); |
Johannes Schindelin | f2dc849 | 2007-12-02 14:14:13 +0000 | [diff] [blame] | 592 | |
Jeff King | a872275 | 2014-08-27 13:01:28 -0400 | [diff] [blame] | 593 | refname = commit->util; |
| 594 | if (anonymize) { |
| 595 | refname = anonymize_refname(refname); |
| 596 | anonymize_ident_line(&committer, &committer_end); |
| 597 | anonymize_ident_line(&author, &author_end); |
| 598 | } |
| 599 | |
Pieter de Bie | df6a7ff | 2008-06-11 13:17:04 +0200 | [diff] [blame] | 600 | mark_next_object(&commit->object); |
Jeff King | a872275 | 2014-08-27 13:01:28 -0400 | [diff] [blame] | 601 | if (anonymize) |
| 602 | reencoded = anonymize_commit_message(message); |
| 603 | else if (!is_encoding_utf8(encoding)) |
Johannes Schindelin | f2dc849 | 2007-12-02 14:14:13 +0000 | [diff] [blame] | 604 | reencoded = reencode_string(message, "UTF-8", encoding); |
Shawn O. Pearce | d8933f0 | 2008-06-13 00:38:55 -0400 | [diff] [blame] | 605 | if (!commit->parents) |
Jeff King | a872275 | 2014-08-27 13:01:28 -0400 | [diff] [blame] | 606 | printf("reset %s\n", refname); |
Ramsay Jones | 6e1c234 | 2008-07-03 16:52:09 +0100 | [diff] [blame] | 607 | printf("commit %s\nmark :%"PRIu32"\n%.*s\n%.*s\ndata %u\n%s", |
Jeff King | a872275 | 2014-08-27 13:01:28 -0400 | [diff] [blame] | 608 | refname, last_idnum, |
Johannes Schindelin | f2dc849 | 2007-12-02 14:14:13 +0000 | [diff] [blame] | 609 | (int)(author_end - author), author, |
| 610 | (int)(committer_end - committer), committer, |
| 611 | (unsigned)(reencoded |
| 612 | ? strlen(reencoded) : message |
| 613 | ? strlen(message) : 0), |
| 614 | reencoded ? reencoded : message ? message : ""); |
Jim Meyering | 8e0f700 | 2008-01-31 18:26:32 +0100 | [diff] [blame] | 615 | free(reencoded); |
Jeff King | bc6b8fc | 2014-06-10 17:41:51 -0400 | [diff] [blame] | 616 | unuse_commit_buffer(commit, commit_buffer); |
Johannes Schindelin | f2dc849 | 2007-12-02 14:14:13 +0000 | [diff] [blame] | 617 | |
| 618 | for (i = 0, p = commit->parents; p; p = p->next) { |
| 619 | int mark = get_object_mark(&p->item->object); |
| 620 | if (!mark) |
| 621 | continue; |
| 622 | if (i == 0) |
| 623 | printf("from :%d\n", mark); |
Johannes Schindelin | f2dc849 | 2007-12-02 14:14:13 +0000 | [diff] [blame] | 624 | else |
Pieter de Bie | 5070b49 | 2008-05-25 01:21:53 +0200 | [diff] [blame] | 625 | printf("merge :%d\n", mark); |
Johannes Schindelin | f2dc849 | 2007-12-02 14:14:13 +0000 | [diff] [blame] | 626 | i++; |
| 627 | } |
Johannes Schindelin | f2dc849 | 2007-12-02 14:14:13 +0000 | [diff] [blame] | 628 | |
Elijah Newren | 4087a02 | 2010-07-17 11:00:50 -0600 | [diff] [blame] | 629 | if (full_tree) |
| 630 | printf("deleteall\n"); |
Johannes Schindelin | f2dc849 | 2007-12-02 14:14:13 +0000 | [diff] [blame] | 631 | log_tree_diff_flush(rev); |
Jonathan Tan | b3e8ca8 | 2017-09-20 16:55:02 -0700 | [diff] [blame] | 632 | string_list_clear(paths_of_changed_objects, 0); |
Johannes Schindelin | f2dc849 | 2007-12-02 14:14:13 +0000 | [diff] [blame] | 633 | rev->diffopt.output_format = saved_output_format; |
| 634 | |
| 635 | printf("\n"); |
| 636 | |
| 637 | show_progress(); |
| 638 | } |
| 639 | |
Jeff King | a872275 | 2014-08-27 13:01:28 -0400 | [diff] [blame] | 640 | static void *anonymize_tag(const void *old, size_t *len) |
| 641 | { |
| 642 | static int counter; |
| 643 | struct strbuf out = STRBUF_INIT; |
| 644 | strbuf_addf(&out, "tag message %d", counter++); |
| 645 | return strbuf_detach(&out, len); |
| 646 | } |
| 647 | |
Jonathan Tan | b3e8ca8 | 2017-09-20 16:55:02 -0700 | [diff] [blame] | 648 | static void handle_tail(struct object_array *commits, struct rev_info *revs, |
| 649 | struct string_list *paths_of_changed_objects) |
Johannes Schindelin | f2dc849 | 2007-12-02 14:14:13 +0000 | [diff] [blame] | 650 | { |
| 651 | struct commit *commit; |
| 652 | while (commits->nr) { |
Martin Ågren | 7199203 | 2017-09-23 01:34:53 +0200 | [diff] [blame] | 653 | commit = (struct commit *)object_array_pop(commits); |
Johannes Schindelin | f2dc849 | 2007-12-02 14:14:13 +0000 | [diff] [blame] | 654 | if (has_unshown_parent(commit)) |
| 655 | return; |
Jonathan Tan | b3e8ca8 | 2017-09-20 16:55:02 -0700 | [diff] [blame] | 656 | handle_commit(commit, revs, paths_of_changed_objects); |
Johannes Schindelin | f2dc849 | 2007-12-02 14:14:13 +0000 | [diff] [blame] | 657 | } |
| 658 | } |
| 659 | |
| 660 | static void handle_tag(const char *name, struct tag *tag) |
| 661 | { |
| 662 | unsigned long size; |
| 663 | enum object_type type; |
| 664 | char *buf; |
| 665 | const char *tagger, *tagger_end, *message; |
| 666 | size_t message_size = 0; |
Elijah Newren | 02c48cd | 2009-06-25 22:48:28 -0600 | [diff] [blame] | 667 | struct object *tagged; |
Elijah Newren | 2d8ad46 | 2009-06-25 22:48:31 -0600 | [diff] [blame] | 668 | int tagged_mark; |
| 669 | struct commit *p; |
Elijah Newren | 02c48cd | 2009-06-25 22:48:28 -0600 | [diff] [blame] | 670 | |
Ondřej Bílka | 98e023d | 2013-07-29 10:18:21 +0200 | [diff] [blame] | 671 | /* Trees have no identifier in fast-export output, thus we have no way |
Elijah Newren | 02c48cd | 2009-06-25 22:48:28 -0600 | [diff] [blame] | 672 | * to output tags of trees, tags of tags of trees, etc. Simply omit |
| 673 | * such tags. |
| 674 | */ |
| 675 | tagged = tag->tagged; |
| 676 | while (tagged->type == OBJ_TAG) { |
| 677 | tagged = ((struct tag *)tagged)->tagged; |
| 678 | } |
| 679 | if (tagged->type == OBJ_TREE) { |
| 680 | warning("Omitting tag %s,\nsince tags of trees (or tags of tags of trees, etc.) are not supported.", |
brian m. carlson | f2fd076 | 2015-11-10 02:22:28 +0000 | [diff] [blame] | 681 | oid_to_hex(&tag->object.oid)); |
Elijah Newren | 02c48cd | 2009-06-25 22:48:28 -0600 | [diff] [blame] | 682 | return; |
| 683 | } |
Johannes Schindelin | f2dc849 | 2007-12-02 14:14:13 +0000 | [diff] [blame] | 684 | |
brian m. carlson | ed1c997 | 2015-11-10 02:22:29 +0000 | [diff] [blame] | 685 | buf = read_sha1_file(tag->object.oid.hash, &type, &size); |
Johannes Schindelin | f2dc849 | 2007-12-02 14:14:13 +0000 | [diff] [blame] | 686 | if (!buf) |
brian m. carlson | f2fd076 | 2015-11-10 02:22:28 +0000 | [diff] [blame] | 687 | die ("Could not read tag %s", oid_to_hex(&tag->object.oid)); |
Johannes Schindelin | f2dc849 | 2007-12-02 14:14:13 +0000 | [diff] [blame] | 688 | message = memmem(buf, size, "\n\n", 2); |
| 689 | if (message) { |
| 690 | message += 2; |
| 691 | message_size = strlen(message); |
| 692 | } |
| 693 | tagger = memmem(buf, message ? message - buf : size, "\ntagger ", 8); |
Johannes Schindelin | 4e46a8d | 2008-12-20 01:00:27 +0100 | [diff] [blame] | 694 | if (!tagger) { |
| 695 | if (fake_missing_tagger) |
| 696 | tagger = "tagger Unspecified Tagger " |
| 697 | "<unspecified-tagger> 0 +0000"; |
| 698 | else |
| 699 | tagger = ""; |
| 700 | tagger_end = tagger + strlen(tagger); |
| 701 | } else { |
| 702 | tagger++; |
| 703 | tagger_end = strchrnul(tagger, '\n'); |
Jeff King | a872275 | 2014-08-27 13:01:28 -0400 | [diff] [blame] | 704 | if (anonymize) |
| 705 | anonymize_ident_line(&tagger, &tagger_end); |
| 706 | } |
| 707 | |
| 708 | if (anonymize) { |
| 709 | name = anonymize_refname(name); |
| 710 | if (message) { |
| 711 | static struct hashmap tags; |
| 712 | message = anonymize_mem(&tags, anonymize_tag, |
| 713 | message, &message_size); |
| 714 | } |
Johannes Schindelin | 4e46a8d | 2008-12-20 01:00:27 +0100 | [diff] [blame] | 715 | } |
Johannes Schindelin | f2dc849 | 2007-12-02 14:14:13 +0000 | [diff] [blame] | 716 | |
| 717 | /* handle signed tags */ |
| 718 | if (message) { |
| 719 | const char *signature = strstr(message, |
| 720 | "\n-----BEGIN PGP SIGNATURE-----\n"); |
| 721 | if (signature) |
| 722 | switch(signed_tag_mode) { |
| 723 | case ABORT: |
| 724 | die ("Encountered signed tag %s; use " |
Paul Price | 04a74b6 | 2013-04-12 10:05:55 -0400 | [diff] [blame] | 725 | "--signed-tags=<mode> to handle it.", |
brian m. carlson | f2fd076 | 2015-11-10 02:22:28 +0000 | [diff] [blame] | 726 | oid_to_hex(&tag->object.oid)); |
Johannes Schindelin | f2dc849 | 2007-12-02 14:14:13 +0000 | [diff] [blame] | 727 | case WARN: |
| 728 | warning ("Exporting signed tag %s", |
brian m. carlson | f2fd076 | 2015-11-10 02:22:28 +0000 | [diff] [blame] | 729 | oid_to_hex(&tag->object.oid)); |
Johannes Schindelin | f2dc849 | 2007-12-02 14:14:13 +0000 | [diff] [blame] | 730 | /* fallthru */ |
Johannes Schindelin | ee4bc37 | 2007-12-03 22:44:39 +0000 | [diff] [blame] | 731 | case VERBATIM: |
Johannes Schindelin | f2dc849 | 2007-12-02 14:14:13 +0000 | [diff] [blame] | 732 | break; |
John Keeping | cd16c59 | 2013-04-14 11:57:06 +0100 | [diff] [blame] | 733 | case WARN_STRIP: |
| 734 | warning ("Stripping signature from tag %s", |
brian m. carlson | f2fd076 | 2015-11-10 02:22:28 +0000 | [diff] [blame] | 735 | oid_to_hex(&tag->object.oid)); |
John Keeping | cd16c59 | 2013-04-14 11:57:06 +0100 | [diff] [blame] | 736 | /* fallthru */ |
Johannes Schindelin | f2dc849 | 2007-12-02 14:14:13 +0000 | [diff] [blame] | 737 | case STRIP: |
| 738 | message_size = signature + 1 - message; |
| 739 | break; |
| 740 | } |
| 741 | } |
| 742 | |
Elijah Newren | 2d8ad46 | 2009-06-25 22:48:31 -0600 | [diff] [blame] | 743 | /* handle tag->tagged having been filtered out due to paths specified */ |
| 744 | tagged = tag->tagged; |
| 745 | tagged_mark = get_object_mark(tagged); |
| 746 | if (!tagged_mark) { |
| 747 | switch(tag_of_filtered_mode) { |
| 748 | case ABORT: |
| 749 | die ("Tag %s tags unexported object; use " |
| 750 | "--tag-of-filtered-object=<mode> to handle it.", |
brian m. carlson | f2fd076 | 2015-11-10 02:22:28 +0000 | [diff] [blame] | 751 | oid_to_hex(&tag->object.oid)); |
Elijah Newren | 2d8ad46 | 2009-06-25 22:48:31 -0600 | [diff] [blame] | 752 | case DROP: |
| 753 | /* Ignore this tag altogether */ |
Johannes Schindelin | 1efb1e9 | 2017-05-04 15:57:33 +0200 | [diff] [blame] | 754 | free(buf); |
Elijah Newren | 2d8ad46 | 2009-06-25 22:48:31 -0600 | [diff] [blame] | 755 | return; |
| 756 | case REWRITE: |
| 757 | if (tagged->type != OBJ_COMMIT) { |
| 758 | die ("Tag %s tags unexported %s!", |
brian m. carlson | f2fd076 | 2015-11-10 02:22:28 +0000 | [diff] [blame] | 759 | oid_to_hex(&tag->object.oid), |
Elijah Newren | 2d8ad46 | 2009-06-25 22:48:31 -0600 | [diff] [blame] | 760 | typename(tagged->type)); |
| 761 | } |
| 762 | p = (struct commit *)tagged; |
| 763 | for (;;) { |
| 764 | if (p->parents && p->parents->next) |
| 765 | break; |
| 766 | if (p->object.flags & UNINTERESTING) |
| 767 | break; |
| 768 | if (!(p->object.flags & TREESAME)) |
| 769 | break; |
| 770 | if (!p->parents) |
| 771 | die ("Can't find replacement commit for tag %s\n", |
brian m. carlson | f2fd076 | 2015-11-10 02:22:28 +0000 | [diff] [blame] | 772 | oid_to_hex(&tag->object.oid)); |
Elijah Newren | 2d8ad46 | 2009-06-25 22:48:31 -0600 | [diff] [blame] | 773 | p = p->parents->item; |
| 774 | } |
| 775 | tagged_mark = get_object_mark(&p->object); |
| 776 | } |
| 777 | } |
| 778 | |
Christian Couder | 5955654 | 2013-11-30 21:55:40 +0100 | [diff] [blame] | 779 | if (starts_with(name, "refs/tags/")) |
Johannes Schindelin | f2dc849 | 2007-12-02 14:14:13 +0000 | [diff] [blame] | 780 | name += 10; |
Johannes Schindelin | 4e46a8d | 2008-12-20 01:00:27 +0100 | [diff] [blame] | 781 | printf("tag %s\nfrom :%d\n%.*s%sdata %d\n%.*s\n", |
Elijah Newren | 2d8ad46 | 2009-06-25 22:48:31 -0600 | [diff] [blame] | 782 | name, tagged_mark, |
Johannes Schindelin | f2dc849 | 2007-12-02 14:14:13 +0000 | [diff] [blame] | 783 | (int)(tagger_end - tagger), tagger, |
Johannes Schindelin | 4e46a8d | 2008-12-20 01:00:27 +0100 | [diff] [blame] | 784 | tagger == tagger_end ? "" : "\n", |
Johannes Schindelin | f2dc849 | 2007-12-02 14:14:13 +0000 | [diff] [blame] | 785 | (int)message_size, (int)message_size, message ? message : ""); |
Johannes Schindelin | 1efb1e9 | 2017-05-04 15:57:33 +0200 | [diff] [blame] | 786 | free(buf); |
Johannes Schindelin | f2dc849 | 2007-12-02 14:14:13 +0000 | [diff] [blame] | 787 | } |
| 788 | |
Felipe Contreras | 3e9b9cb | 2013-09-01 02:05:48 -0500 | [diff] [blame] | 789 | static struct commit *get_commit(struct rev_cmdline_entry *e, char *full_name) |
Johannes Schindelin | f2dc849 | 2007-12-02 14:14:13 +0000 | [diff] [blame] | 790 | { |
Felipe Contreras | 3e9b9cb | 2013-09-01 02:05:48 -0500 | [diff] [blame] | 791 | switch (e->item->type) { |
| 792 | case OBJ_COMMIT: |
| 793 | return (struct commit *)e->item; |
| 794 | case OBJ_TAG: { |
| 795 | struct tag *tag = (struct tag *)e->item; |
| 796 | |
| 797 | /* handle nested tags */ |
| 798 | while (tag && tag->object.type == OBJ_TAG) { |
brian m. carlson | c251c83 | 2017-05-06 22:10:38 +0000 | [diff] [blame] | 799 | parse_object(&tag->object.oid); |
Felipe Contreras | 3e9b9cb | 2013-09-01 02:05:48 -0500 | [diff] [blame] | 800 | string_list_append(&extra_refs, full_name)->util = tag; |
| 801 | tag = (struct tag *)tag->tagged; |
| 802 | } |
| 803 | if (!tag) |
| 804 | die("Tag %s points nowhere?", e->name); |
| 805 | return (struct commit *)tag; |
| 806 | break; |
| 807 | } |
| 808 | default: |
| 809 | return NULL; |
| 810 | } |
| 811 | } |
| 812 | |
Felipe Contreras | 1d844ee | 2013-09-01 02:05:47 -0500 | [diff] [blame] | 813 | static void get_tags_and_duplicates(struct rev_cmdline_info *info) |
Johannes Schindelin | f2dc849 | 2007-12-02 14:14:13 +0000 | [diff] [blame] | 814 | { |
Johannes Schindelin | f2dc849 | 2007-12-02 14:14:13 +0000 | [diff] [blame] | 815 | int i; |
| 816 | |
Felipe Contreras | 49266e8 | 2012-11-28 23:23:59 +0100 | [diff] [blame] | 817 | for (i = 0; i < info->nr; i++) { |
| 818 | struct rev_cmdline_entry *e = info->rev + i; |
brian m. carlson | 273f8ee | 2017-02-21 23:47:23 +0000 | [diff] [blame] | 819 | struct object_id oid; |
Felipe Contreras | 2d242de | 2012-11-28 23:11:08 +0100 | [diff] [blame] | 820 | struct commit *commit; |
Johannes Schindelin | f2dc849 | 2007-12-02 14:14:13 +0000 | [diff] [blame] | 821 | char *full_name; |
| 822 | |
Felipe Contreras | 49266e8 | 2012-11-28 23:23:59 +0100 | [diff] [blame] | 823 | if (e->flags & UNINTERESTING) |
| 824 | continue; |
| 825 | |
brian m. carlson | cca5fa6 | 2017-10-15 22:06:57 +0000 | [diff] [blame] | 826 | if (dwim_ref(e->name, strlen(e->name), &oid, &full_name) != 1) |
Johannes Schindelin | f2dc849 | 2007-12-02 14:14:13 +0000 | [diff] [blame] | 827 | continue; |
| 828 | |
Felipe Contreras | 03e9010 | 2014-04-20 13:59:24 -0500 | [diff] [blame] | 829 | if (refspecs) { |
| 830 | char *private; |
| 831 | private = apply_refspecs(refspecs, refspecs_nr, full_name); |
| 832 | if (private) { |
| 833 | free(full_name); |
| 834 | full_name = private; |
| 835 | } |
| 836 | } |
| 837 | |
Felipe Contreras | 3e9b9cb | 2013-09-01 02:05:48 -0500 | [diff] [blame] | 838 | commit = get_commit(e, full_name); |
| 839 | if (!commit) { |
Erik Faye-Lund | 2d07f6d | 2009-03-23 12:53:07 +0000 | [diff] [blame] | 840 | warning("%s: Unexpected object of type %s, skipping.", |
| 841 | e->name, |
| 842 | typename(e->item->type)); |
| 843 | continue; |
Johannes Schindelin | f2dc849 | 2007-12-02 14:14:13 +0000 | [diff] [blame] | 844 | } |
Felipe Contreras | f28e7c9 | 2012-11-28 23:24:00 +0100 | [diff] [blame] | 845 | |
Felipe Contreras | 3e9b9cb | 2013-09-01 02:05:48 -0500 | [diff] [blame] | 846 | switch(commit->object.type) { |
| 847 | case OBJ_COMMIT: |
| 848 | break; |
| 849 | case OBJ_BLOB: |
brian m. carlson | 273f8ee | 2017-02-21 23:47:23 +0000 | [diff] [blame] | 850 | export_blob(&commit->object.oid); |
Felipe Contreras | 3e9b9cb | 2013-09-01 02:05:48 -0500 | [diff] [blame] | 851 | continue; |
| 852 | default: /* OBJ_TAG (nested tags) is already handled */ |
| 853 | warning("Tag points to object of unexpected type %s, skipping.", |
| 854 | typename(commit->object.type)); |
| 855 | continue; |
| 856 | } |
| 857 | |
Felipe Contreras | f28e7c9 | 2012-11-28 23:24:00 +0100 | [diff] [blame] | 858 | /* |
| 859 | * This ref will not be updated through a commit, lets make |
| 860 | * sure it gets properly updated eventually. |
| 861 | */ |
| 862 | if (commit->util || commit->object.flags & SHOWN) |
Felipe Contreras | 1d844ee | 2013-09-01 02:05:47 -0500 | [diff] [blame] | 863 | string_list_append(&extra_refs, full_name)->util = commit; |
Felipe Contreras | f28e7c9 | 2012-11-28 23:24:00 +0100 | [diff] [blame] | 864 | if (!commit->util) |
Johannes Schindelin | f2dc849 | 2007-12-02 14:14:13 +0000 | [diff] [blame] | 865 | commit->util = full_name; |
| 866 | } |
| 867 | } |
| 868 | |
Felipe Contreras | 1d844ee | 2013-09-01 02:05:47 -0500 | [diff] [blame] | 869 | static void handle_tags_and_duplicates(void) |
Johannes Schindelin | f2dc849 | 2007-12-02 14:14:13 +0000 | [diff] [blame] | 870 | { |
| 871 | struct commit *commit; |
| 872 | int i; |
| 873 | |
Felipe Contreras | 1d844ee | 2013-09-01 02:05:47 -0500 | [diff] [blame] | 874 | for (i = extra_refs.nr - 1; i >= 0; i--) { |
| 875 | const char *name = extra_refs.items[i].string; |
| 876 | struct object *object = extra_refs.items[i].util; |
Johannes Schindelin | f2dc849 | 2007-12-02 14:14:13 +0000 | [diff] [blame] | 877 | switch (object->type) { |
| 878 | case OBJ_TAG: |
| 879 | handle_tag(name, (struct tag *)object); |
| 880 | break; |
| 881 | case OBJ_COMMIT: |
Jeff King | a872275 | 2014-08-27 13:01:28 -0400 | [diff] [blame] | 882 | if (anonymize) |
| 883 | name = anonymize_refname(name); |
Johannes Schindelin | f2dc849 | 2007-12-02 14:14:13 +0000 | [diff] [blame] | 884 | /* create refs pointing to already seen commits */ |
| 885 | commit = (struct commit *)object; |
| 886 | printf("reset %s\nfrom :%d\n\n", name, |
| 887 | get_object_mark(&commit->object)); |
| 888 | show_progress(); |
| 889 | break; |
| 890 | } |
| 891 | } |
| 892 | } |
| 893 | |
Pieter de Bie | df6a7ff | 2008-06-11 13:17:04 +0200 | [diff] [blame] | 894 | static void export_marks(char *file) |
| 895 | { |
| 896 | unsigned int i; |
| 897 | uint32_t mark; |
Jonathan Tan | ddd3e31 | 2017-12-07 16:14:24 -0800 | [diff] [blame] | 898 | struct decoration_entry *deco = idnums.entries; |
Pieter de Bie | df6a7ff | 2008-06-11 13:17:04 +0200 | [diff] [blame] | 899 | FILE *f; |
Matthias Andree | 96d69b5 | 2009-07-24 10:17:13 +0200 | [diff] [blame] | 900 | int e = 0; |
Pieter de Bie | df6a7ff | 2008-06-11 13:17:04 +0200 | [diff] [blame] | 901 | |
Johannes Schindelin | ea56518 | 2016-01-11 19:35:54 +0100 | [diff] [blame] | 902 | f = fopen_for_writing(file); |
Pieter de Bie | df6a7ff | 2008-06-11 13:17:04 +0200 | [diff] [blame] | 903 | if (!f) |
Sverre Rabbelier | bb6ad28 | 2010-03-28 00:42:48 -0500 | [diff] [blame] | 904 | die_errno("Unable to open marks file %s for writing.", file); |
Pieter de Bie | df6a7ff | 2008-06-11 13:17:04 +0200 | [diff] [blame] | 905 | |
Junio C Hamano | 6991357 | 2008-07-03 00:25:23 -0700 | [diff] [blame] | 906 | for (i = 0; i < idnums.size; i++) { |
| 907 | if (deco->base && deco->base->type == 1) { |
Pieter de Bie | df6a7ff | 2008-06-11 13:17:04 +0200 | [diff] [blame] | 908 | mark = ptr_to_mark(deco->decoration); |
Matthias Andree | 96d69b5 | 2009-07-24 10:17:13 +0200 | [diff] [blame] | 909 | if (fprintf(f, ":%"PRIu32" %s\n", mark, |
brian m. carlson | f2fd076 | 2015-11-10 02:22:28 +0000 | [diff] [blame] | 910 | oid_to_hex(&deco->base->oid)) < 0) { |
Matthias Andree | 96d69b5 | 2009-07-24 10:17:13 +0200 | [diff] [blame] | 911 | e = 1; |
| 912 | break; |
| 913 | } |
Pieter de Bie | df6a7ff | 2008-06-11 13:17:04 +0200 | [diff] [blame] | 914 | } |
Junio C Hamano | 6991357 | 2008-07-03 00:25:23 -0700 | [diff] [blame] | 915 | deco++; |
Pieter de Bie | df6a7ff | 2008-06-11 13:17:04 +0200 | [diff] [blame] | 916 | } |
| 917 | |
Matthias Andree | 96d69b5 | 2009-07-24 10:17:13 +0200 | [diff] [blame] | 918 | e |= ferror(f); |
| 919 | e |= fclose(f); |
| 920 | if (e) |
Pieter de Bie | df6a7ff | 2008-06-11 13:17:04 +0200 | [diff] [blame] | 921 | error("Unable to write marks file %s.", file); |
| 922 | } |
| 923 | |
Junio C Hamano | 6991357 | 2008-07-03 00:25:23 -0700 | [diff] [blame] | 924 | static void import_marks(char *input_file) |
Pieter de Bie | df6a7ff | 2008-06-11 13:17:04 +0200 | [diff] [blame] | 925 | { |
| 926 | char line[512]; |
Nguyễn Thái Ngọc Duy | 23a9e07 | 2017-05-03 17:16:46 +0700 | [diff] [blame] | 927 | FILE *f = xfopen(input_file, "r"); |
Pieter de Bie | df6a7ff | 2008-06-11 13:17:04 +0200 | [diff] [blame] | 928 | |
| 929 | while (fgets(line, sizeof(line), f)) { |
| 930 | uint32_t mark; |
| 931 | char *line_end, *mark_end; |
brian m. carlson | 273f8ee | 2017-02-21 23:47:23 +0000 | [diff] [blame] | 932 | struct object_id oid; |
Pieter de Bie | df6a7ff | 2008-06-11 13:17:04 +0200 | [diff] [blame] | 933 | struct object *object; |
Felipe Contreras | 47bd9bf | 2013-05-05 17:38:54 -0500 | [diff] [blame] | 934 | struct commit *commit; |
Felipe Contreras | e6812cf | 2013-05-05 17:38:53 -0500 | [diff] [blame] | 935 | enum object_type type; |
Pieter de Bie | df6a7ff | 2008-06-11 13:17:04 +0200 | [diff] [blame] | 936 | |
| 937 | line_end = strchr(line, '\n'); |
| 938 | if (line[0] != ':' || !line_end) |
| 939 | die("corrupt mark line: %s", line); |
Junio C Hamano | 6991357 | 2008-07-03 00:25:23 -0700 | [diff] [blame] | 940 | *line_end = '\0'; |
Pieter de Bie | df6a7ff | 2008-06-11 13:17:04 +0200 | [diff] [blame] | 941 | |
| 942 | mark = strtoumax(line + 1, &mark_end, 10); |
| 943 | if (!mark || mark_end == line + 1 |
brian m. carlson | 273f8ee | 2017-02-21 23:47:23 +0000 | [diff] [blame] | 944 | || *mark_end != ' ' || get_oid_hex(mark_end + 1, &oid)) |
Pieter de Bie | df6a7ff | 2008-06-11 13:17:04 +0200 | [diff] [blame] | 945 | die("corrupt mark line: %s", line); |
| 946 | |
Antoine Pelisse | c4458ec | 2013-04-06 19:04:31 +0200 | [diff] [blame] | 947 | if (last_idnum < mark) |
| 948 | last_idnum = mark; |
| 949 | |
brian m. carlson | 273f8ee | 2017-02-21 23:47:23 +0000 | [diff] [blame] | 950 | type = sha1_object_info(oid.hash, NULL); |
Felipe Contreras | e6812cf | 2013-05-05 17:38:53 -0500 | [diff] [blame] | 951 | if (type < 0) |
brian m. carlson | 273f8ee | 2017-02-21 23:47:23 +0000 | [diff] [blame] | 952 | die("object not found: %s", oid_to_hex(&oid)); |
Felipe Contreras | e6812cf | 2013-05-05 17:38:53 -0500 | [diff] [blame] | 953 | |
| 954 | if (type != OBJ_COMMIT) |
| 955 | /* only commits */ |
Antoine Pelisse | c4458ec | 2013-04-06 19:04:31 +0200 | [diff] [blame] | 956 | continue; |
Pieter de Bie | df6a7ff | 2008-06-11 13:17:04 +0200 | [diff] [blame] | 957 | |
brian m. carlson | bc83266 | 2017-05-06 22:10:10 +0000 | [diff] [blame] | 958 | commit = lookup_commit(&oid); |
Felipe Contreras | 47bd9bf | 2013-05-05 17:38:54 -0500 | [diff] [blame] | 959 | if (!commit) |
brian m. carlson | 273f8ee | 2017-02-21 23:47:23 +0000 | [diff] [blame] | 960 | die("not a commit? can't happen: %s", oid_to_hex(&oid)); |
Felipe Contreras | 47bd9bf | 2013-05-05 17:38:54 -0500 | [diff] [blame] | 961 | |
| 962 | object = &commit->object; |
Felipe Contreras | e6812cf | 2013-05-05 17:38:53 -0500 | [diff] [blame] | 963 | |
Pieter de Bie | df6a7ff | 2008-06-11 13:17:04 +0200 | [diff] [blame] | 964 | if (object->flags & SHOWN) |
brian m. carlson | 273f8ee | 2017-02-21 23:47:23 +0000 | [diff] [blame] | 965 | error("Object %s already has a mark", oid_to_hex(&oid)); |
Pieter de Bie | df6a7ff | 2008-06-11 13:17:04 +0200 | [diff] [blame] | 966 | |
| 967 | mark_object(object, mark); |
Pieter de Bie | df6a7ff | 2008-06-11 13:17:04 +0200 | [diff] [blame] | 968 | |
| 969 | object->flags |= SHOWN; |
| 970 | } |
| 971 | fclose(f); |
| 972 | } |
| 973 | |
Felipe Contreras | 60ed264 | 2014-04-20 13:59:28 -0500 | [diff] [blame] | 974 | static void handle_deletes(void) |
| 975 | { |
| 976 | int i; |
| 977 | for (i = 0; i < refspecs_nr; i++) { |
| 978 | struct refspec *refspec = &refspecs[i]; |
| 979 | if (*refspec->src) |
| 980 | continue; |
| 981 | |
| 982 | printf("reset %s\nfrom %s\n\n", |
| 983 | refspec->dst, sha1_to_hex(null_sha1)); |
| 984 | } |
| 985 | } |
| 986 | |
Johannes Schindelin | f2dc849 | 2007-12-02 14:14:13 +0000 | [diff] [blame] | 987 | int cmd_fast_export(int argc, const char **argv, const char *prefix) |
| 988 | { |
| 989 | struct rev_info revs; |
Thiago Farina | 3cd4745 | 2010-08-28 23:04:17 -0300 | [diff] [blame] | 990 | struct object_array commits = OBJECT_ARRAY_INIT; |
Johannes Schindelin | f2dc849 | 2007-12-02 14:14:13 +0000 | [diff] [blame] | 991 | struct commit *commit; |
Pieter de Bie | df6a7ff | 2008-06-11 13:17:04 +0200 | [diff] [blame] | 992 | char *export_filename = NULL, *import_filename = NULL; |
Antoine Pelisse | c4458ec | 2013-04-06 19:04:31 +0200 | [diff] [blame] | 993 | uint32_t lastimportid; |
Felipe Contreras | 03e9010 | 2014-04-20 13:59:24 -0500 | [diff] [blame] | 994 | struct string_list refspecs_list = STRING_LIST_INIT_NODUP; |
Jonathan Tan | b3e8ca8 | 2017-09-20 16:55:02 -0700 | [diff] [blame] | 995 | struct string_list paths_of_changed_objects = STRING_LIST_INIT_DUP; |
Johannes Schindelin | f2dc849 | 2007-12-02 14:14:13 +0000 | [diff] [blame] | 996 | struct option options[] = { |
| 997 | OPT_INTEGER(0, "progress", &progress, |
Nguyễn Thái Ngọc Duy | 3b787b9 | 2012-08-20 19:32:08 +0700 | [diff] [blame] | 998 | N_("show progress after <n> objects")), |
| 999 | OPT_CALLBACK(0, "signed-tags", &signed_tag_mode, N_("mode"), |
| 1000 | N_("select handling of signed tags"), |
Johannes Schindelin | f2dc849 | 2007-12-02 14:14:13 +0000 | [diff] [blame] | 1001 | parse_opt_signed_tag_mode), |
Nguyễn Thái Ngọc Duy | 3b787b9 | 2012-08-20 19:32:08 +0700 | [diff] [blame] | 1002 | OPT_CALLBACK(0, "tag-of-filtered-object", &tag_of_filtered_mode, N_("mode"), |
| 1003 | N_("select handling of tags that tag filtered objects"), |
Elijah Newren | 2d8ad46 | 2009-06-25 22:48:31 -0600 | [diff] [blame] | 1004 | parse_opt_tag_of_filtered_mode), |
Nguyễn Thái Ngọc Duy | 3b787b9 | 2012-08-20 19:32:08 +0700 | [diff] [blame] | 1005 | OPT_STRING(0, "export-marks", &export_filename, N_("file"), |
| 1006 | N_("Dump marks to this file")), |
| 1007 | OPT_STRING(0, "import-marks", &import_filename, N_("file"), |
| 1008 | N_("Import marks from this file")), |
Stefan Beller | d5d09d4 | 2013-08-03 13:51:19 +0200 | [diff] [blame] | 1009 | OPT_BOOL(0, "fake-missing-tagger", &fake_missing_tagger, |
| 1010 | N_("Fake a tagger when tags lack one")), |
| 1011 | OPT_BOOL(0, "full-tree", &full_tree, |
| 1012 | N_("Output full tree for each commit")), |
| 1013 | OPT_BOOL(0, "use-done-feature", &use_done_feature, |
Nguyễn Thái Ngọc Duy | 3b787b9 | 2012-08-20 19:32:08 +0700 | [diff] [blame] | 1014 | N_("Use the done feature to terminate the stream")), |
| 1015 | OPT_BOOL(0, "no-data", &no_data, N_("Skip output of blob data")), |
Felipe Contreras | 03e9010 | 2014-04-20 13:59:24 -0500 | [diff] [blame] | 1016 | OPT_STRING_LIST(0, "refspec", &refspecs_list, N_("refspec"), |
| 1017 | N_("Apply refspec to exported refs")), |
Jeff King | a872275 | 2014-08-27 13:01:28 -0400 | [diff] [blame] | 1018 | OPT_BOOL(0, "anonymize", &anonymize, N_("anonymize output")), |
Johannes Schindelin | f2dc849 | 2007-12-02 14:14:13 +0000 | [diff] [blame] | 1019 | OPT_END() |
| 1020 | }; |
| 1021 | |
Miklos Vajna | dcfdbdf | 2009-01-03 04:59:12 +0100 | [diff] [blame] | 1022 | if (argc == 1) |
| 1023 | usage_with_options (fast_export_usage, options); |
| 1024 | |
Johannes Schindelin | f2dc849 | 2007-12-02 14:14:13 +0000 | [diff] [blame] | 1025 | /* we handle encodings */ |
Johannes Schindelin | ef90d6d | 2008-05-14 18:46:53 +0100 | [diff] [blame] | 1026 | git_config(git_default_config, NULL); |
Johannes Schindelin | f2dc849 | 2007-12-02 14:14:13 +0000 | [diff] [blame] | 1027 | |
| 1028 | init_revisions(&revs, prefix); |
Elijah Newren | 668f3aa | 2009-06-25 22:48:27 -0600 | [diff] [blame] | 1029 | revs.topo_order = 1; |
Elijah Newren | 2374502 | 2009-06-25 22:48:29 -0600 | [diff] [blame] | 1030 | revs.show_source = 1; |
Elijah Newren | 3216413 | 2009-06-25 22:48:30 -0600 | [diff] [blame] | 1031 | revs.rewrite_parents = 1; |
Felipe Contreras | 8b2f86a | 2014-04-20 13:59:23 -0500 | [diff] [blame] | 1032 | argc = parse_options(argc, argv, prefix, options, fast_export_usage, |
| 1033 | PARSE_OPT_KEEP_ARGV0 | PARSE_OPT_KEEP_UNKNOWN); |
Johannes Schindelin | f2dc849 | 2007-12-02 14:14:13 +0000 | [diff] [blame] | 1034 | argc = setup_revisions(argc, argv, &revs, NULL); |
Johannes Schindelin | f2dc849 | 2007-12-02 14:14:13 +0000 | [diff] [blame] | 1035 | if (argc > 1) |
| 1036 | usage_with_options (fast_export_usage, options); |
| 1037 | |
Felipe Contreras | 03e9010 | 2014-04-20 13:59:24 -0500 | [diff] [blame] | 1038 | if (refspecs_list.nr) { |
| 1039 | const char **refspecs_str; |
| 1040 | int i; |
| 1041 | |
Jeff King | b32fa95 | 2016-02-22 17:44:25 -0500 | [diff] [blame] | 1042 | ALLOC_ARRAY(refspecs_str, refspecs_list.nr); |
Felipe Contreras | 03e9010 | 2014-04-20 13:59:24 -0500 | [diff] [blame] | 1043 | for (i = 0; i < refspecs_list.nr; i++) |
| 1044 | refspecs_str[i] = refspecs_list.items[i].string; |
| 1045 | |
| 1046 | refspecs_nr = refspecs_list.nr; |
| 1047 | refspecs = parse_fetch_refspec(refspecs_nr, refspecs_str); |
| 1048 | |
| 1049 | string_list_clear(&refspecs_list, 1); |
| 1050 | free(refspecs_str); |
| 1051 | } |
| 1052 | |
Sverre Rabbelier | 82670a5 | 2011-07-16 15:03:33 +0200 | [diff] [blame] | 1053 | if (use_done_feature) |
| 1054 | printf("feature done\n"); |
| 1055 | |
Pieter de Bie | df6a7ff | 2008-06-11 13:17:04 +0200 | [diff] [blame] | 1056 | if (import_filename) |
| 1057 | import_marks(import_filename); |
Antoine Pelisse | c4458ec | 2013-04-06 19:04:31 +0200 | [diff] [blame] | 1058 | lastimportid = last_idnum; |
Pieter de Bie | df6a7ff | 2008-06-11 13:17:04 +0200 | [diff] [blame] | 1059 | |
Nguyễn Thái Ngọc Duy | afe069d | 2010-12-17 19:43:06 +0700 | [diff] [blame] | 1060 | if (import_filename && revs.prune_data.nr) |
Elijah Newren | 4087a02 | 2010-07-17 11:00:50 -0600 | [diff] [blame] | 1061 | full_tree = 1; |
| 1062 | |
Felipe Contreras | 1d844ee | 2013-09-01 02:05:47 -0500 | [diff] [blame] | 1063 | get_tags_and_duplicates(&revs.cmdline); |
Johannes Schindelin | f2dc849 | 2007-12-02 14:14:13 +0000 | [diff] [blame] | 1064 | |
Martin Koegler | 3d51e1b | 2008-02-18 08:31:56 +0100 | [diff] [blame] | 1065 | if (prepare_revision_walk(&revs)) |
| 1066 | die("revision walk setup failed"); |
Johannes Schindelin | f2dc849 | 2007-12-02 14:14:13 +0000 | [diff] [blame] | 1067 | revs.diffopt.format_callback = show_filemodify; |
Jonathan Tan | b3e8ca8 | 2017-09-20 16:55:02 -0700 | [diff] [blame] | 1068 | revs.diffopt.format_callback_data = &paths_of_changed_objects; |
Brandon Williams | 0d1e0e7 | 2017-10-31 11:19:11 -0700 | [diff] [blame] | 1069 | revs.diffopt.flags.recursive = 1; |
Johannes Schindelin | f2dc849 | 2007-12-02 14:14:13 +0000 | [diff] [blame] | 1070 | while ((commit = get_revision(&revs))) { |
| 1071 | if (has_unshown_parent(commit)) { |
Johannes Schindelin | f2dc849 | 2007-12-02 14:14:13 +0000 | [diff] [blame] | 1072 | add_object_array(&commit->object, NULL, &commits); |
Johannes Schindelin | f2dc849 | 2007-12-02 14:14:13 +0000 | [diff] [blame] | 1073 | } |
| 1074 | else { |
Jonathan Tan | b3e8ca8 | 2017-09-20 16:55:02 -0700 | [diff] [blame] | 1075 | handle_commit(commit, &revs, &paths_of_changed_objects); |
| 1076 | handle_tail(&commits, &revs, &paths_of_changed_objects); |
Johannes Schindelin | f2dc849 | 2007-12-02 14:14:13 +0000 | [diff] [blame] | 1077 | } |
| 1078 | } |
| 1079 | |
Felipe Contreras | 1d844ee | 2013-09-01 02:05:47 -0500 | [diff] [blame] | 1080 | handle_tags_and_duplicates(); |
Felipe Contreras | 60ed264 | 2014-04-20 13:59:28 -0500 | [diff] [blame] | 1081 | handle_deletes(); |
Johannes Schindelin | f2dc849 | 2007-12-02 14:14:13 +0000 | [diff] [blame] | 1082 | |
Antoine Pelisse | c4458ec | 2013-04-06 19:04:31 +0200 | [diff] [blame] | 1083 | if (export_filename && lastimportid != last_idnum) |
Pieter de Bie | df6a7ff | 2008-06-11 13:17:04 +0200 | [diff] [blame] | 1084 | export_marks(export_filename); |
| 1085 | |
Sverre Rabbelier | 82670a5 | 2011-07-16 15:03:33 +0200 | [diff] [blame] | 1086 | if (use_done_feature) |
| 1087 | printf("done\n"); |
| 1088 | |
Felipe Contreras | 03e9010 | 2014-04-20 13:59:24 -0500 | [diff] [blame] | 1089 | free_refspec(refspecs_nr, refspecs); |
| 1090 | |
Johannes Schindelin | f2dc849 | 2007-12-02 14:14:13 +0000 | [diff] [blame] | 1091 | return 0; |
| 1092 | } |