]> git.ipfire.org Git - thirdparty/git.git/blame - builtin/fast-export.c
t9350: add tests for tags of things other than a commit
[thirdparty/git.git] / builtin / fast-export.c
CommitLineData
f2dc849e
JS
1/*
2 * "git fast-export" builtin command
3 *
4 * Copyright (C) 2007 Johannes E. Schindelin
5 */
6#include "builtin.h"
7#include "cache.h"
b2141fc1 8#include "config.h"
fb58c8d5 9#include "refs.h"
ec0cb496 10#include "refspec.h"
cbd53a21 11#include "object-store.h"
f2dc849e
JS
12#include "commit.h"
13#include "object.h"
14#include "tag.h"
15#include "diff.h"
16#include "diffcore.h"
17#include "log-tree.h"
18#include "revision.h"
19#include "decorate.h"
c455c87c 20#include "string-list.h"
f2dc849e
JS
21#include "utf8.h"
22#include "parse-options.h"
6280dfdc 23#include "quote.h"
03e9010c 24#include "remote.h"
a8722750 25#include "blob.h"
87be2523 26#include "commit-slab.h"
f2dc849e
JS
27
28static const char *fast_export_usage[] = {
3b787b96 29 N_("git fast-export [rev-list-opts]"),
f2dc849e
JS
30 NULL
31};
32
33static int progress;
b93b81e7
EN
34static enum { SIGNED_TAG_ABORT, VERBATIM, WARN, WARN_STRIP, STRIP } signed_tag_mode = SIGNED_TAG_ABORT;
35static enum { TAG_FILTERING_ABORT, DROP, REWRITE } tag_of_filtered_mode = TAG_FILTERING_ABORT;
e80001f8 36static enum { REENCODE_ABORT, REENCODE_YES, REENCODE_NO } reencode_mode = REENCODE_ABORT;
4e46a8d6 37static int fake_missing_tagger;
82670a5c 38static int use_done_feature;
79559f27 39static int no_data;
7f40ab09 40static int full_tree;
530ca19c 41static int reference_excluded_commits;
a965bb31 42static int show_original_ids;
a1638cfe 43static int mark_tags;
1d844ee7 44static struct string_list extra_refs = STRING_LIST_INIT_NODUP;
fdf31b63 45static struct string_list tag_refs = STRING_LIST_INIT_NODUP;
16eefc8e 46static struct refspec refspecs = REFSPEC_INIT_FETCH;
a8722750 47static int anonymize;
87be2523 48static struct revision_sources revision_sources;
f2dc849e
JS
49
50static int parse_opt_signed_tag_mode(const struct option *opt,
51 const char *arg, int unset)
52{
53 if (unset || !strcmp(arg, "abort"))
b93b81e7 54 signed_tag_mode = SIGNED_TAG_ABORT;
ee4bc371
JS
55 else if (!strcmp(arg, "verbatim") || !strcmp(arg, "ignore"))
56 signed_tag_mode = VERBATIM;
f2dc849e
JS
57 else if (!strcmp(arg, "warn"))
58 signed_tag_mode = WARN;
cd16c59b
JK
59 else if (!strcmp(arg, "warn-strip"))
60 signed_tag_mode = WARN_STRIP;
f2dc849e
JS
61 else if (!strcmp(arg, "strip"))
62 signed_tag_mode = STRIP;
63 else
04a74b6c 64 return error("Unknown signed-tags mode: %s", arg);
f2dc849e
JS
65 return 0;
66}
67
2d8ad469
EN
68static int parse_opt_tag_of_filtered_mode(const struct option *opt,
69 const char *arg, int unset)
70{
71 if (unset || !strcmp(arg, "abort"))
b93b81e7 72 tag_of_filtered_mode = TAG_FILTERING_ABORT;
2d8ad469
EN
73 else if (!strcmp(arg, "drop"))
74 tag_of_filtered_mode = DROP;
75 else if (!strcmp(arg, "rewrite"))
76 tag_of_filtered_mode = REWRITE;
77 else
78 return error("Unknown tag-of-filtered mode: %s", arg);
79 return 0;
80}
81
e80001f8
EN
82static int parse_opt_reencode_mode(const struct option *opt,
83 const char *arg, int unset)
84{
85 if (unset) {
86 reencode_mode = REENCODE_ABORT;
87 return 0;
88 }
89
90 switch (git_parse_maybe_bool(arg)) {
91 case 0:
92 reencode_mode = REENCODE_NO;
93 break;
94 case 1:
95 reencode_mode = REENCODE_YES;
96 break;
97 default:
98 if (!strcasecmp(arg, "abort"))
99 reencode_mode = REENCODE_ABORT;
100 else
101 return error("Unknown reencoding mode: %s", arg);
102 }
103
104 return 0;
105}
106
f2dc849e
JS
107static struct decoration idnums;
108static uint32_t last_idnum;
109
110static int has_unshown_parent(struct commit *commit)
111{
112 struct commit_list *parent;
113
114 for (parent = commit->parents; parent; parent = parent->next)
115 if (!(parent->item->object.flags & SHOWN) &&
116 !(parent->item->object.flags & UNINTERESTING))
117 return 1;
118 return 0;
119}
120
a8722750
JK
121struct anonymized_entry {
122 struct hashmap_entry hash;
123 const char *orig;
124 size_t orig_len;
125 const char *anon;
126 size_t anon_len;
127};
128
7663cdc8
SB
129static int anonymized_entry_cmp(const void *unused_cmp_data,
130 const void *va, const void *vb,
131 const void *unused_keydata)
a8722750
JK
132{
133 const struct anonymized_entry *a = va, *b = vb;
134 return a->orig_len != b->orig_len ||
135 memcmp(a->orig, b->orig, a->orig_len);
136}
137
138/*
139 * Basically keep a cache of X->Y so that we can repeatedly replace
140 * the same anonymized string with another. The actual generation
141 * is farmed out to the generate function.
142 */
143static const void *anonymize_mem(struct hashmap *map,
144 void *(*generate)(const void *, size_t *),
145 const void *orig, size_t *len)
146{
147 struct anonymized_entry key, *ret;
148
149 if (!map->cmpfn)
7663cdc8 150 hashmap_init(map, anonymized_entry_cmp, NULL, 0);
a8722750
JK
151
152 hashmap_entry_init(&key, memhash(orig, *len));
153 key.orig = orig;
154 key.orig_len = *len;
155 ret = hashmap_get(map, &key, NULL);
156
157 if (!ret) {
158 ret = xmalloc(sizeof(*ret));
159 hashmap_entry_init(&ret->hash, key.hash.hash);
160 ret->orig = xstrdup(orig);
161 ret->orig_len = *len;
162 ret->anon = generate(orig, len);
163 ret->anon_len = *len;
164 hashmap_put(map, ret);
165 }
166
167 *len = ret->anon_len;
168 return ret->anon;
169}
170
171/*
172 * We anonymize each component of a path individually,
173 * so that paths a/b and a/c will share a common root.
174 * The paths are cached via anonymize_mem so that repeated
175 * lookups for "a" will yield the same value.
176 */
177static void anonymize_path(struct strbuf *out, const char *path,
178 struct hashmap *map,
179 void *(*generate)(const void *, size_t *))
180{
181 while (*path) {
182 const char *end_of_component = strchrnul(path, '/');
183 size_t len = end_of_component - path;
184 const char *c = anonymize_mem(map, generate, path, &len);
185 strbuf_add(out, c, len);
186 path = end_of_component;
187 if (*path)
188 strbuf_addch(out, *path++);
189 }
190}
191
c112084a 192static inline void *mark_to_ptr(uint32_t mark)
f2dc849e 193{
c112084a 194 return (void *)(uintptr_t)mark;
df6a7ff7
PB
195}
196
197static inline uint32_t ptr_to_mark(void * mark)
198{
c112084a 199 return (uint32_t)(uintptr_t)mark;
df6a7ff7
PB
200}
201
202static inline void mark_object(struct object *object, uint32_t mark)
203{
204 add_decoration(&idnums, object, mark_to_ptr(mark));
205}
206
207static inline void mark_next_object(struct object *object)
208{
209 mark_object(object, ++last_idnum);
f2dc849e
JS
210}
211
212static int get_object_mark(struct object *object)
213{
214 void *decoration = lookup_decoration(&idnums, object);
215 if (!decoration)
216 return 0;
df6a7ff7 217 return ptr_to_mark(decoration);
f2dc849e
JS
218}
219
f129c427
EN
220static struct commit *rewrite_commit(struct commit *p)
221{
222 for (;;) {
223 if (p->parents && p->parents->next)
224 break;
225 if (p->object.flags & UNINTERESTING)
226 break;
227 if (!(p->object.flags & TREESAME))
228 break;
229 if (!p->parents)
230 return NULL;
231 p = p->parents->item;
232 }
233 return p;
234}
235
f2dc849e
JS
236static void show_progress(void)
237{
238 static int counter = 0;
239 if (!progress)
240 return;
241 if ((++counter % progress) == 0)
242 printf("progress %d objects\n", counter);
243}
244
a8722750
JK
245/*
246 * Ideally we would want some transformation of the blob data here
247 * that is unreversible, but would still be the same size and have
248 * the same data relationship to other blobs (so that we get the same
249 * delta and packing behavior as the original). But the first and last
250 * requirements there are probably mutually exclusive, so let's take
251 * the easy way out for now, and just generate arbitrary content.
252 *
253 * There's no need to cache this result with anonymize_mem, since
254 * we already handle blob content caching with marks.
255 */
256static char *anonymize_blob(unsigned long *size)
257{
258 static int counter;
259 struct strbuf out = STRBUF_INIT;
260 strbuf_addf(&out, "anonymous blob %d", counter++);
261 *size = out.len;
262 return strbuf_detach(&out, NULL);
263}
264
273f8ee8 265static void export_blob(const struct object_id *oid)
f2dc849e
JS
266{
267 unsigned long size;
268 enum object_type type;
269 char *buf;
270 struct object *object;
30b939c3 271 int eaten;
f2dc849e 272
79559f27
GI
273 if (no_data)
274 return;
275
273f8ee8 276 if (is_null_oid(oid))
f2dc849e
JS
277 return;
278
d0229abd 279 object = lookup_object(the_repository, oid);
30b939c3 280 if (object && object->flags & SHOWN)
f2dc849e
JS
281 return;
282
a8722750
JK
283 if (anonymize) {
284 buf = anonymize_blob(&size);
da14a7ff 285 object = (struct object *)lookup_blob(the_repository, oid);
a8722750
JK
286 eaten = 0;
287 } else {
b4f5aca4 288 buf = read_object_file(oid, &type, &size);
a8722750 289 if (!buf)
1a07e59c 290 die("could not read blob %s", oid_to_hex(oid));
17e65451 291 if (check_object_signature(oid, buf, size, type_name(type)) < 0)
843b9e6d 292 die("oid mismatch in blob %s", oid_to_hex(oid));
1ec5bfd2
SB
293 object = parse_object_buffer(the_repository, oid, type,
294 size, buf, &eaten);
a8722750
JK
295 }
296
30b939c3 297 if (!object)
273f8ee8 298 die("Could not read blob %s", oid_to_hex(oid));
f2dc849e 299
df6a7ff7 300 mark_next_object(object);
f2dc849e 301
a965bb31
EN
302 printf("blob\nmark :%"PRIu32"\n", last_idnum);
303 if (show_original_ids)
304 printf("original-oid %s\n", oid_to_hex(oid));
4d597532 305 printf("data %"PRIuMAX"\n", (uintmax_t)size);
b0fe0d72 306 if (size && fwrite(buf, size, 1, stdout) != 1)
1a07e59c 307 die_errno("could not write blob '%s'", oid_to_hex(oid));
f2dc849e
JS
308 printf("\n");
309
310 show_progress();
311
312 object->flags |= SHOWN;
30b939c3
JK
313 if (!eaten)
314 free(buf);
f2dc849e
JS
315}
316
060df624
EN
317static int depth_first(const void *a_, const void *b_)
318{
319 const struct diff_filepair *a = *((const struct diff_filepair **)a_);
320 const struct diff_filepair *b = *((const struct diff_filepair **)b_);
321 const char *name_a, *name_b;
322 int len_a, len_b, len;
323 int cmp;
324
325 name_a = a->one ? a->one->path : a->two->path;
326 name_b = b->one ? b->one->path : b->two->path;
327
328 len_a = strlen(name_a);
329 len_b = strlen(name_b);
330 len = (len_a < len_b) ? len_a : len_b;
331
332 /* strcmp will sort 'd' before 'd/e', we want 'd/e' before 'd' */
333 cmp = memcmp(name_a, name_b, len);
334 if (cmp)
335 return cmp;
4ce6fb80
JS
336 cmp = len_b - len_a;
337 if (cmp)
338 return cmp;
339 /*
340 * Move 'R'ename entries last so that all references of the file
341 * appear in the output before it is renamed (e.g., when a file
342 * was copied and renamed in the same commit).
343 */
344 return (a->status == 'R') - (b->status == 'R');
060df624
EN
345}
346
a8722750 347static void print_path_1(const char *path)
6280dfdc
JK
348{
349 int need_quote = quote_c_style(path, NULL, NULL, 0);
350 if (need_quote)
351 quote_c_style(path, NULL, stdout, 0);
ff59f6da
JS
352 else if (strchr(path, ' '))
353 printf("\"%s\"", path);
6280dfdc
JK
354 else
355 printf("%s", path);
356}
357
a8722750
JK
358static void *anonymize_path_component(const void *path, size_t *len)
359{
360 static int counter;
361 struct strbuf out = STRBUF_INIT;
362 strbuf_addf(&out, "path%d", counter++);
363 return strbuf_detach(&out, len);
364}
365
366static void print_path(const char *path)
367{
368 if (!anonymize)
369 print_path_1(path);
370 else {
371 static struct hashmap paths;
372 static struct strbuf anon = STRBUF_INIT;
373
374 anonymize_path(&anon, path, &paths, anonymize_path_component);
375 print_path_1(anon.buf);
376 strbuf_reset(&anon);
377 }
378}
379
273f8ee8 380static void *generate_fake_oid(const void *old, size_t *len)
a8722750 381{
843b9e6d
EN
382 static uint32_t counter = 1; /* avoid null oid */
383 const unsigned hashsz = the_hash_algo->rawsz;
384 unsigned char *out = xcalloc(hashsz, 1);
385 put_be32(out + hashsz - 4, counter++);
a8722750
JK
386 return out;
387}
388
843b9e6d 389static const struct object_id *anonymize_oid(const struct object_id *oid)
a8722750 390{
843b9e6d
EN
391 static struct hashmap objs;
392 size_t len = the_hash_algo->rawsz;
393 return anonymize_mem(&objs, generate_fake_oid, oid, &len);
a8722750
JK
394}
395
f2dc849e
JS
396static void show_filemodify(struct diff_queue_struct *q,
397 struct diff_options *options, void *data)
398{
399 int i;
b3e8ca89 400 struct string_list *changed = data;
060df624
EN
401
402 /*
403 * Handle files below a directory first, in case they are all deleted
404 * and the directory changes to a file or symlink.
405 */
9ed0d8d6 406 QSORT(q->queue, q->nr, depth_first);
060df624 407
f2dc849e 408 for (i = 0; i < q->nr; i++) {
ae7c5dce 409 struct diff_filespec *ospec = q->queue[i]->one;
f2dc849e 410 struct diff_filespec *spec = q->queue[i]->two;
ae7c5dce
AG
411
412 switch (q->queue[i]->status) {
413 case DIFF_STATUS_DELETED:
6280dfdc
JK
414 printf("D ");
415 print_path(spec->path);
b3e8ca89 416 string_list_insert(changed, spec->path);
6280dfdc 417 putchar('\n');
ae7c5dce
AG
418 break;
419
420 case DIFF_STATUS_COPIED:
421 case DIFF_STATUS_RENAMED:
b3e8ca89
JT
422 /*
423 * If a change in the file corresponding to ospec->path
424 * has been observed, we cannot trust its contents
425 * because the diff is calculated based on the prior
426 * contents, not the current contents. So, declare a
427 * copy or rename only if there was no change observed.
428 */
429 if (!string_list_has_string(changed, ospec->path)) {
430 printf("%c ", q->queue[i]->status);
431 print_path(ospec->path);
432 putchar(' ');
433 print_path(spec->path);
434 string_list_insert(changed, spec->path);
435 putchar('\n');
436
4a7e27e9 437 if (oideq(&ospec->oid, &spec->oid) &&
b3e8ca89
JT
438 ospec->mode == spec->mode)
439 break;
440 }
ae7c5dce
AG
441 /* fallthrough */
442
443 case DIFF_STATUS_TYPE_CHANGED:
444 case DIFF_STATUS_MODIFIED:
445 case DIFF_STATUS_ADDED:
03db4525
AG
446 /*
447 * Links refer to objects in another repositories;
448 * output the SHA-1 verbatim.
449 */
79559f27 450 if (no_data || S_ISGITLINK(spec->mode))
6280dfdc 451 printf("M %06o %s ", spec->mode,
843b9e6d
EN
452 oid_to_hex(anonymize ?
453 anonymize_oid(&spec->oid) :
454 &spec->oid));
03db4525 455 else {
5abddd1e 456 struct object *object = lookup_object(the_repository,
d0229abd 457 &spec->oid);
6280dfdc
JK
458 printf("M %06o :%d ", spec->mode,
459 get_object_mark(object));
03db4525 460 }
6280dfdc 461 print_path(spec->path);
b3e8ca89 462 string_list_insert(changed, spec->path);
6280dfdc 463 putchar('\n');
ae7c5dce
AG
464 break;
465
466 default:
467 die("Unexpected comparison status '%c' for %s, %s",
468 q->queue[i]->status,
469 ospec->path ? ospec->path : "none",
470 spec->path ? spec->path : "none");
f2dc849e
JS
471 }
472 }
473}
474
475static const char *find_encoding(const char *begin, const char *end)
476{
477 const char *needle = "\nencoding ";
478 char *bol, *eol;
479
480 bol = memmem(begin, end ? end - begin : strlen(begin),
481 needle, strlen(needle));
482 if (!bol)
57a8be2c 483 return NULL;
f2dc849e
JS
484 bol += strlen(needle);
485 eol = strchrnul(bol, '\n');
486 *eol = '\0';
487 return bol;
488}
489
a8722750
JK
490static void *anonymize_ref_component(const void *old, size_t *len)
491{
492 static int counter;
493 struct strbuf out = STRBUF_INIT;
494 strbuf_addf(&out, "ref%d", counter++);
495 return strbuf_detach(&out, len);
496}
497
498static const char *anonymize_refname(const char *refname)
499{
500 /*
501 * If any of these prefixes is found, we will leave it intact
502 * so that tags remain tags and so forth.
503 */
504 static const char *prefixes[] = {
505 "refs/heads/",
506 "refs/tags/",
507 "refs/remotes/",
508 "refs/"
509 };
510 static struct hashmap refs;
511 static struct strbuf anon = STRBUF_INIT;
512 int i;
513
514 /*
515 * We also leave "master" as a special case, since it does not reveal
516 * anything interesting.
517 */
518 if (!strcmp(refname, "refs/heads/master"))
519 return refname;
520
521 strbuf_reset(&anon);
522 for (i = 0; i < ARRAY_SIZE(prefixes); i++) {
523 if (skip_prefix(refname, prefixes[i], &refname)) {
524 strbuf_addstr(&anon, prefixes[i]);
525 break;
526 }
527 }
528
529 anonymize_path(&anon, refname, &refs, anonymize_ref_component);
530 return anon.buf;
531}
532
533/*
534 * We do not even bother to cache commit messages, as they are unlikely
535 * to be repeated verbatim, and it is not that interesting when they are.
536 */
537static char *anonymize_commit_message(const char *old)
538{
539 static int counter;
540 return xstrfmt("subject %d\n\nbody\n", counter++);
541}
542
543static struct hashmap idents;
544static void *anonymize_ident(const void *old, size_t *len)
545{
546 static int counter;
547 struct strbuf out = STRBUF_INIT;
548 strbuf_addf(&out, "User %d <user%d@example.com>", counter, counter);
549 counter++;
550 return strbuf_detach(&out, len);
551}
552
553/*
554 * Our strategy here is to anonymize the names and email addresses,
555 * but keep timestamps intact, as they influence things like traversal
556 * order (and by themselves should not be too revealing).
557 */
558static void anonymize_ident_line(const char **beg, const char **end)
559{
560 static struct strbuf buffers[] = { STRBUF_INIT, STRBUF_INIT };
561 static unsigned which_buffer;
562
563 struct strbuf *out;
564 struct ident_split split;
565 const char *end_of_header;
566
567 out = &buffers[which_buffer++];
568 which_buffer %= ARRAY_SIZE(buffers);
569 strbuf_reset(out);
570
571 /* skip "committer", "author", "tagger", etc */
572 end_of_header = strchr(*beg, ' ');
573 if (!end_of_header)
033abf97 574 BUG("malformed line fed to anonymize_ident_line: %.*s",
a8722750
JK
575 (int)(*end - *beg), *beg);
576 end_of_header++;
577 strbuf_add(out, *beg, end_of_header - *beg);
578
579 if (!split_ident_line(&split, end_of_header, *end - end_of_header) &&
580 split.date_begin) {
581 const char *ident;
582 size_t len;
583
584 len = split.mail_end - split.name_begin;
585 ident = anonymize_mem(&idents, anonymize_ident,
586 split.name_begin, &len);
587 strbuf_add(out, ident, len);
588 strbuf_addch(out, ' ');
589 strbuf_add(out, split.date_begin, split.tz_end - split.date_begin);
590 } else {
591 strbuf_addstr(out, "Malformed Ident <malformed@example.com> 0 -0000");
592 }
593
594 *beg = out->buf;
595 *end = out->buf + out->len;
596}
597
b3e8ca89
JT
598static void handle_commit(struct commit *commit, struct rev_info *rev,
599 struct string_list *paths_of_changed_objects)
f2dc849e
JS
600{
601 int saved_output_format = rev->diffopt.output_format;
bc6b8fc1 602 const char *commit_buffer;
f2dc849e
JS
603 const char *author, *author_end, *committer, *committer_end;
604 const char *encoding, *message;
605 char *reencoded = NULL;
606 struct commit_list *p;
a8722750 607 const char *refname;
f2dc849e
JS
608 int i;
609
610 rev->diffopt.output_format = DIFF_FORMAT_CALLBACK;
611
683ff884 612 parse_commit_or_die(commit);
8597ea3a 613 commit_buffer = get_commit_buffer(commit, NULL);
bc6b8fc1 614 author = strstr(commit_buffer, "\nauthor ");
f2dc849e 615 if (!author)
1a07e59c
NTND
616 die("could not find author in commit %s",
617 oid_to_hex(&commit->object.oid));
f2dc849e
JS
618 author++;
619 author_end = strchrnul(author, '\n');
620 committer = strstr(author_end, "\ncommitter ");
621 if (!committer)
1a07e59c
NTND
622 die("could not find committer in commit %s",
623 oid_to_hex(&commit->object.oid));
f2dc849e
JS
624 committer++;
625 committer_end = strchrnul(committer, '\n');
626 message = strstr(committer_end, "\n\n");
627 encoding = find_encoding(committer_end, message);
628 if (message)
629 message += 2;
630
ebeec7db 631 if (commit->parents &&
530ca19c
EN
632 (get_object_mark(&commit->parents->item->object) != 0 ||
633 reference_excluded_commits) &&
4087a02e 634 !full_tree) {
683ff884 635 parse_commit_or_die(commit->parents->item);
2e27bd77
DS
636 diff_tree_oid(get_commit_tree_oid(commit->parents->item),
637 get_commit_tree_oid(commit), "", &rev->diffopt);
f2dc849e
JS
638 }
639 else
2e27bd77 640 diff_root_tree_oid(get_commit_tree_oid(commit),
7b8dea0c 641 "", &rev->diffopt);
f2dc849e 642
03db4525 643 /* Export the referenced blobs, and remember the marks. */
f2dc849e 644 for (i = 0; i < diff_queued_diff.nr; i++)
03db4525 645 if (!S_ISGITLINK(diff_queued_diff.queue[i]->two->mode))
273f8ee8 646 export_blob(&diff_queued_diff.queue[i]->two->oid);
f2dc849e 647
87be2523 648 refname = *revision_sources_at(&revision_sources, commit);
fdf31b63
EN
649 /*
650 * FIXME: string_list_remove() below for each ref is overall
651 * O(N^2). Compared to a history walk and diffing trees, this is
652 * just lost in the noise in practice. However, theoretically a
653 * repo may have enough refs for this to become slow.
654 */
655 string_list_remove(&extra_refs, refname, 0);
a8722750
JK
656 if (anonymize) {
657 refname = anonymize_refname(refname);
658 anonymize_ident_line(&committer, &committer_end);
659 anonymize_ident_line(&author, &author_end);
660 }
661
df6a7ff7 662 mark_next_object(&commit->object);
e80001f8 663 if (anonymize) {
a8722750 664 reencoded = anonymize_commit_message(message);
e80001f8
EN
665 } else if (encoding) {
666 switch(reencode_mode) {
667 case REENCODE_YES:
668 reencoded = reencode_string(message, "UTF-8", encoding);
669 break;
670 case REENCODE_NO:
671 break;
672 case REENCODE_ABORT:
673 die("Encountered commit-specific encoding %s in commit "
674 "%s; use --reencode=[yes|no] to handle it",
675 encoding, oid_to_hex(&commit->object.oid));
676 }
677 }
d8933f01 678 if (!commit->parents)
a8722750 679 printf("reset %s\n", refname);
a965bb31
EN
680 printf("commit %s\nmark :%"PRIu32"\n", refname, last_idnum);
681 if (show_original_ids)
682 printf("original-oid %s\n", oid_to_hex(&commit->object.oid));
ccbfc96d 683 printf("%.*s\n%.*s\n",
f2dc849e 684 (int)(author_end - author), author,
ccbfc96d
EN
685 (int)(committer_end - committer), committer);
686 if (!reencoded && encoding)
687 printf("encoding %s\n", encoding);
688 printf("data %u\n%s",
f2dc849e
JS
689 (unsigned)(reencoded
690 ? strlen(reencoded) : message
691 ? strlen(message) : 0),
692 reencoded ? reencoded : message ? message : "");
8e0f7003 693 free(reencoded);
bc6b8fc1 694 unuse_commit_buffer(commit, commit_buffer);
f2dc849e
JS
695
696 for (i = 0, p = commit->parents; p; p = p->next) {
530ca19c
EN
697 struct object *obj = &p->item->object;
698 int mark = get_object_mark(obj);
699
700 if (!mark && !reference_excluded_commits)
f2dc849e
JS
701 continue;
702 if (i == 0)
530ca19c
EN
703 printf("from ");
704 else
705 printf("merge ");
706 if (mark)
707 printf(":%d\n", mark);
f2dc849e 708 else
530ca19c
EN
709 printf("%s\n", oid_to_hex(anonymize ?
710 anonymize_oid(&obj->oid) :
711 &obj->oid));
f2dc849e
JS
712 i++;
713 }
f2dc849e 714
4087a02e
EN
715 if (full_tree)
716 printf("deleteall\n");
f2dc849e 717 log_tree_diff_flush(rev);
b3e8ca89 718 string_list_clear(paths_of_changed_objects, 0);
f2dc849e
JS
719 rev->diffopt.output_format = saved_output_format;
720
721 printf("\n");
722
723 show_progress();
724}
725
a8722750
JK
726static void *anonymize_tag(const void *old, size_t *len)
727{
728 static int counter;
729 struct strbuf out = STRBUF_INIT;
730 strbuf_addf(&out, "tag message %d", counter++);
731 return strbuf_detach(&out, len);
732}
733
b3e8ca89
JT
734static void handle_tail(struct object_array *commits, struct rev_info *revs,
735 struct string_list *paths_of_changed_objects)
f2dc849e
JS
736{
737 struct commit *commit;
738 while (commits->nr) {
71992039 739 commit = (struct commit *)object_array_pop(commits);
be011bbe
740 if (has_unshown_parent(commit)) {
741 /* Queue again, to be handled later */
742 add_object_array(&commit->object, NULL, commits);
f2dc849e 743 return;
be011bbe 744 }
b3e8ca89 745 handle_commit(commit, revs, paths_of_changed_objects);
f2dc849e
JS
746 }
747}
748
749static void handle_tag(const char *name, struct tag *tag)
750{
751 unsigned long size;
752 enum object_type type;
753 char *buf;
754 const char *tagger, *tagger_end, *message;
755 size_t message_size = 0;
02c48cd6 756 struct object *tagged;
2d8ad469
EN
757 int tagged_mark;
758 struct commit *p;
02c48cd6 759
98e023de 760 /* Trees have no identifier in fast-export output, thus we have no way
02c48cd6
EN
761 * to output tags of trees, tags of tags of trees, etc. Simply omit
762 * such tags.
763 */
764 tagged = tag->tagged;
765 while (tagged->type == OBJ_TAG) {
766 tagged = ((struct tag *)tagged)->tagged;
767 }
768 if (tagged->type == OBJ_TREE) {
769 warning("Omitting tag %s,\nsince tags of trees (or tags of tags of trees, etc.) are not supported.",
f2fd0760 770 oid_to_hex(&tag->object.oid));
02c48cd6
EN
771 return;
772 }
f2dc849e 773
b4f5aca4 774 buf = read_object_file(&tag->object.oid, &type, &size);
f2dc849e 775 if (!buf)
1a07e59c 776 die("could not read tag %s", oid_to_hex(&tag->object.oid));
f2dc849e
JS
777 message = memmem(buf, size, "\n\n", 2);
778 if (message) {
779 message += 2;
780 message_size = strlen(message);
781 }
782 tagger = memmem(buf, message ? message - buf : size, "\ntagger ", 8);
4e46a8d6
JS
783 if (!tagger) {
784 if (fake_missing_tagger)
785 tagger = "tagger Unspecified Tagger "
786 "<unspecified-tagger> 0 +0000";
787 else
788 tagger = "";
789 tagger_end = tagger + strlen(tagger);
790 } else {
791 tagger++;
792 tagger_end = strchrnul(tagger, '\n');
a8722750
JK
793 if (anonymize)
794 anonymize_ident_line(&tagger, &tagger_end);
795 }
796
797 if (anonymize) {
798 name = anonymize_refname(name);
799 if (message) {
800 static struct hashmap tags;
801 message = anonymize_mem(&tags, anonymize_tag,
802 message, &message_size);
803 }
4e46a8d6 804 }
f2dc849e
JS
805
806 /* handle signed tags */
807 if (message) {
808 const char *signature = strstr(message,
809 "\n-----BEGIN PGP SIGNATURE-----\n");
810 if (signature)
811 switch(signed_tag_mode) {
b93b81e7 812 case SIGNED_TAG_ABORT:
1a07e59c
NTND
813 die("encountered signed tag %s; use "
814 "--signed-tags=<mode> to handle it",
815 oid_to_hex(&tag->object.oid));
f2dc849e 816 case WARN:
1a07e59c
NTND
817 warning("exporting signed tag %s",
818 oid_to_hex(&tag->object.oid));
f2dc849e 819 /* fallthru */
ee4bc371 820 case VERBATIM:
f2dc849e 821 break;
cd16c59b 822 case WARN_STRIP:
1a07e59c
NTND
823 warning("stripping signature from tag %s",
824 oid_to_hex(&tag->object.oid));
cd16c59b 825 /* fallthru */
f2dc849e
JS
826 case STRIP:
827 message_size = signature + 1 - message;
828 break;
829 }
830 }
831
2d8ad469
EN
832 /* handle tag->tagged having been filtered out due to paths specified */
833 tagged = tag->tagged;
834 tagged_mark = get_object_mark(tagged);
835 if (!tagged_mark) {
836 switch(tag_of_filtered_mode) {
b93b81e7 837 case TAG_FILTERING_ABORT:
1a07e59c
NTND
838 die("tag %s tags unexported object; use "
839 "--tag-of-filtered-object=<mode> to handle it",
840 oid_to_hex(&tag->object.oid));
2d8ad469
EN
841 case DROP:
842 /* Ignore this tag altogether */
1efb1e9a 843 free(buf);
2d8ad469
EN
844 return;
845 case REWRITE:
846 if (tagged->type != OBJ_COMMIT) {
1a07e59c
NTND
847 die("tag %s tags unexported %s!",
848 oid_to_hex(&tag->object.oid),
849 type_name(tagged->type));
2d8ad469 850 }
f129c427
EN
851 p = rewrite_commit((struct commit *)tagged);
852 if (!p) {
853 printf("reset %s\nfrom %s\n\n",
854 name, oid_to_hex(&null_oid));
855 free(buf);
856 return;
2d8ad469
EN
857 }
858 tagged_mark = get_object_mark(&p->object);
859 }
860 }
861
59556548 862 if (starts_with(name, "refs/tags/"))
f2dc849e 863 name += 10;
af2abd87 864 printf("tag %s\n", name);
a1638cfe
EN
865 if (mark_tags) {
866 mark_next_object(&tag->object);
867 printf("mark :%"PRIu32"\n", last_idnum);
868 }
af2abd87
EN
869 if (tagged_mark)
870 printf("from :%d\n", tagged_mark);
871 else
872 printf("from %s\n", oid_to_hex(&tagged->oid));
873
a965bb31
EN
874 if (show_original_ids)
875 printf("original-oid %s\n", oid_to_hex(&tag->object.oid));
876 printf("%.*s%sdata %d\n%.*s\n",
f2dc849e 877 (int)(tagger_end - tagger), tagger,
4e46a8d6 878 tagger == tagger_end ? "" : "\n",
f2dc849e 879 (int)message_size, (int)message_size, message ? message : "");
1efb1e9a 880 free(buf);
f2dc849e
JS
881}
882
3e9b9cb1
FC
883static struct commit *get_commit(struct rev_cmdline_entry *e, char *full_name)
884{
885 switch (e->item->type) {
886 case OBJ_COMMIT:
887 return (struct commit *)e->item;
888 case OBJ_TAG: {
889 struct tag *tag = (struct tag *)e->item;
890
891 /* handle nested tags */
892 while (tag && tag->object.type == OBJ_TAG) {
109cd76d 893 parse_object(the_repository, &tag->object.oid);
fdf31b63 894 string_list_append(&tag_refs, full_name)->util = tag;
3e9b9cb1
FC
895 tag = (struct tag *)tag->tagged;
896 }
897 if (!tag)
898 die("Tag %s points nowhere?", e->name);
899 return (struct commit *)tag;
900 break;
901 }
902 default:
903 return NULL;
904 }
905}
906
1d844ee7 907static void get_tags_and_duplicates(struct rev_cmdline_info *info)
f2dc849e 908{
f2dc849e
JS
909 int i;
910
49266e8a
FC
911 for (i = 0; i < info->nr; i++) {
912 struct rev_cmdline_entry *e = info->rev + i;
273f8ee8 913 struct object_id oid;
2d242de4 914 struct commit *commit;
f2dc849e
JS
915 char *full_name;
916
49266e8a
FC
917 if (e->flags & UNINTERESTING)
918 continue;
919
cca5fa64 920 if (dwim_ref(e->name, strlen(e->name), &oid, &full_name) != 1)
f2dc849e
JS
921 continue;
922
16eefc8e 923 if (refspecs.nr) {
03e9010c 924 char *private;
d000414e 925 private = apply_refspecs(&refspecs, full_name);
03e9010c
FC
926 if (private) {
927 free(full_name);
928 full_name = private;
929 }
930 }
931
3e9b9cb1
FC
932 commit = get_commit(e, full_name);
933 if (!commit) {
2d07f6d4
EFL
934 warning("%s: Unexpected object of type %s, skipping.",
935 e->name,
debca9d2 936 type_name(e->item->type));
2d07f6d4 937 continue;
f2dc849e 938 }
f28e7c90 939
3e9b9cb1
FC
940 switch(commit->object.type) {
941 case OBJ_COMMIT:
942 break;
943 case OBJ_BLOB:
273f8ee8 944 export_blob(&commit->object.oid);
3e9b9cb1
FC
945 continue;
946 default: /* OBJ_TAG (nested tags) is already handled */
947 warning("Tag points to object of unexpected type %s, skipping.",
debca9d2 948 type_name(commit->object.type));
3e9b9cb1
FC
949 continue;
950 }
951
f28e7c90 952 /*
fdf31b63
EN
953 * Make sure this ref gets properly updated eventually, whether
954 * through a commit or manually at the end.
f28e7c90 955 */
fdf31b63 956 if (e->item->type != OBJ_TAG)
1d844ee7 957 string_list_append(&extra_refs, full_name)->util = commit;
fdf31b63 958
87be2523
NTND
959 if (!*revision_sources_at(&revision_sources, commit))
960 *revision_sources_at(&revision_sources, commit) = full_name;
f2dc849e 961 }
fdf31b63
EN
962
963 string_list_sort(&extra_refs);
964 string_list_remove_duplicates(&extra_refs, 0);
f2dc849e
JS
965}
966
fdf31b63 967static void handle_tags_and_duplicates(struct string_list *extras)
f2dc849e
JS
968{
969 struct commit *commit;
970 int i;
971
fdf31b63
EN
972 for (i = extras->nr - 1; i >= 0; i--) {
973 const char *name = extras->items[i].string;
974 struct object *object = extras->items[i].util;
975 int mark;
976
f2dc849e
JS
977 switch (object->type) {
978 case OBJ_TAG:
979 handle_tag(name, (struct tag *)object);
980 break;
981 case OBJ_COMMIT:
a8722750
JK
982 if (anonymize)
983 name = anonymize_refname(name);
f2dc849e 984 /* create refs pointing to already seen commits */
cd13762d
EN
985 commit = rewrite_commit((struct commit *)object);
986 if (!commit) {
987 /*
988 * Neither this object nor any of its
989 * ancestors touch any relevant paths, so
990 * it has been filtered to nothing. Delete
991 * it.
992 */
993 printf("reset %s\nfrom %s\n\n",
994 name, oid_to_hex(&null_oid));
995 continue;
996 }
fdf31b63
EN
997
998 mark = get_object_mark(&commit->object);
999 if (!mark) {
1000 /*
1001 * Getting here means we have a commit which
1002 * was excluded by a negative refspec (e.g.
530ca19c
EN
1003 * fast-export ^master master). If we are
1004 * referencing excluded commits, set the ref
1005 * to the exact commit. Otherwise, the user
fdf31b63 1006 * wants the branch exported but every commit
530ca19c
EN
1007 * in its history to be deleted, which basically
1008 * just means deletion of the ref.
fdf31b63 1009 */
530ca19c
EN
1010 if (!reference_excluded_commits) {
1011 /* delete the ref */
1012 printf("reset %s\nfrom %s\n\n",
1013 name, oid_to_hex(&null_oid));
1014 continue;
1015 }
1016 /* set ref to commit using oid, not mark */
1017 printf("reset %s\nfrom %s\n\n", name,
1018 oid_to_hex(&commit->object.oid));
fdf31b63
EN
1019 continue;
1020 }
1021
1022 printf("reset %s\nfrom :%d\n\n", name, mark
1023 );
f2dc849e
JS
1024 show_progress();
1025 break;
1026 }
1027 }
1028}
1029
df6a7ff7
PB
1030static void export_marks(char *file)
1031{
1032 unsigned int i;
1033 uint32_t mark;
ddd3e312 1034 struct decoration_entry *deco = idnums.entries;
df6a7ff7 1035 FILE *f;
96d69b55 1036 int e = 0;
df6a7ff7 1037
ea56518d 1038 f = fopen_for_writing(file);
df6a7ff7 1039 if (!f)
bb6ad28c 1040 die_errno("Unable to open marks file %s for writing.", file);
df6a7ff7 1041
69913575
JH
1042 for (i = 0; i < idnums.size; i++) {
1043 if (deco->base && deco->base->type == 1) {
df6a7ff7 1044 mark = ptr_to_mark(deco->decoration);
96d69b55 1045 if (fprintf(f, ":%"PRIu32" %s\n", mark,
f2fd0760 1046 oid_to_hex(&deco->base->oid)) < 0) {
96d69b55
MA
1047 e = 1;
1048 break;
1049 }
df6a7ff7 1050 }
69913575 1051 deco++;
df6a7ff7
PB
1052 }
1053
96d69b55
MA
1054 e |= ferror(f);
1055 e |= fclose(f);
1056 if (e)
df6a7ff7
PB
1057 error("Unable to write marks file %s.", file);
1058}
1059
208d6924 1060static void import_marks(char *input_file, int check_exists)
df6a7ff7
PB
1061{
1062 char line[512];
208d6924
EN
1063 FILE *f;
1064 struct stat sb;
1065
1066 if (check_exists && stat(input_file, &sb))
1067 return;
df6a7ff7 1068
208d6924 1069 f = xfopen(input_file, "r");
df6a7ff7
PB
1070 while (fgets(line, sizeof(line), f)) {
1071 uint32_t mark;
1072 char *line_end, *mark_end;
273f8ee8 1073 struct object_id oid;
df6a7ff7 1074 struct object *object;
47bd9bf8 1075 struct commit *commit;
e6812cfa 1076 enum object_type type;
df6a7ff7
PB
1077
1078 line_end = strchr(line, '\n');
1079 if (line[0] != ':' || !line_end)
1080 die("corrupt mark line: %s", line);
69913575 1081 *line_end = '\0';
df6a7ff7
PB
1082
1083 mark = strtoumax(line + 1, &mark_end, 10);
1084 if (!mark || mark_end == line + 1
273f8ee8 1085 || *mark_end != ' ' || get_oid_hex(mark_end + 1, &oid))
df6a7ff7
PB
1086 die("corrupt mark line: %s", line);
1087
c4458ecd
AP
1088 if (last_idnum < mark)
1089 last_idnum = mark;
1090
0df8e965 1091 type = oid_object_info(the_repository, &oid, NULL);
e6812cfa 1092 if (type < 0)
273f8ee8 1093 die("object not found: %s", oid_to_hex(&oid));
e6812cfa
FC
1094
1095 if (type != OBJ_COMMIT)
1096 /* only commits */
c4458ecd 1097 continue;
df6a7ff7 1098
c1f5eb49 1099 commit = lookup_commit(the_repository, &oid);
47bd9bf8 1100 if (!commit)
273f8ee8 1101 die("not a commit? can't happen: %s", oid_to_hex(&oid));
47bd9bf8
FC
1102
1103 object = &commit->object;
e6812cfa 1104
df6a7ff7 1105 if (object->flags & SHOWN)
273f8ee8 1106 error("Object %s already has a mark", oid_to_hex(&oid));
df6a7ff7
PB
1107
1108 mark_object(object, mark);
df6a7ff7
PB
1109
1110 object->flags |= SHOWN;
1111 }
1112 fclose(f);
1113}
1114
60ed2643
FC
1115static void handle_deletes(void)
1116{
1117 int i;
16eefc8e
BW
1118 for (i = 0; i < refspecs.nr; i++) {
1119 struct refspec_item *refspec = &refspecs.items[i];
60ed2643
FC
1120 if (*refspec->src)
1121 continue;
1122
1123 printf("reset %s\nfrom %s\n\n",
843b9e6d 1124 refspec->dst, oid_to_hex(&null_oid));
60ed2643
FC
1125 }
1126}
1127
f2dc849e
JS
1128int cmd_fast_export(int argc, const char **argv, const char *prefix)
1129{
1130 struct rev_info revs;
3cd47459 1131 struct object_array commits = OBJECT_ARRAY_INIT;
f2dc849e 1132 struct commit *commit;
208d6924
EN
1133 char *export_filename = NULL,
1134 *import_filename = NULL,
1135 *import_filename_if_exists = NULL;
c4458ecd 1136 uint32_t lastimportid;
03e9010c 1137 struct string_list refspecs_list = STRING_LIST_INIT_NODUP;
b3e8ca89 1138 struct string_list paths_of_changed_objects = STRING_LIST_INIT_DUP;
f2dc849e
JS
1139 struct option options[] = {
1140 OPT_INTEGER(0, "progress", &progress,
3b787b96
NTND
1141 N_("show progress after <n> objects")),
1142 OPT_CALLBACK(0, "signed-tags", &signed_tag_mode, N_("mode"),
1143 N_("select handling of signed tags"),
f2dc849e 1144 parse_opt_signed_tag_mode),
3b787b96
NTND
1145 OPT_CALLBACK(0, "tag-of-filtered-object", &tag_of_filtered_mode, N_("mode"),
1146 N_("select handling of tags that tag filtered objects"),
2d8ad469 1147 parse_opt_tag_of_filtered_mode),
e80001f8
EN
1148 OPT_CALLBACK(0, "reencode", &reencode_mode, N_("mode"),
1149 N_("select handling of commit messages in an alternate encoding"),
1150 parse_opt_reencode_mode),
3b787b96
NTND
1151 OPT_STRING(0, "export-marks", &export_filename, N_("file"),
1152 N_("Dump marks to this file")),
1153 OPT_STRING(0, "import-marks", &import_filename, N_("file"),
1154 N_("Import marks from this file")),
208d6924
EN
1155 OPT_STRING(0, "import-marks-if-exists",
1156 &import_filename_if_exists,
1157 N_("file"),
1158 N_("Import marks from this file if it exists")),
d5d09d47
SB
1159 OPT_BOOL(0, "fake-missing-tagger", &fake_missing_tagger,
1160 N_("Fake a tagger when tags lack one")),
1161 OPT_BOOL(0, "full-tree", &full_tree,
1162 N_("Output full tree for each commit")),
1163 OPT_BOOL(0, "use-done-feature", &use_done_feature,
3b787b96
NTND
1164 N_("Use the done feature to terminate the stream")),
1165 OPT_BOOL(0, "no-data", &no_data, N_("Skip output of blob data")),
03e9010c
FC
1166 OPT_STRING_LIST(0, "refspec", &refspecs_list, N_("refspec"),
1167 N_("Apply refspec to exported refs")),
a8722750 1168 OPT_BOOL(0, "anonymize", &anonymize, N_("anonymize output")),
530ca19c
EN
1169 OPT_BOOL(0, "reference-excluded-parents",
1170 &reference_excluded_commits, N_("Reference parents which are not in fast-export stream by object id")),
a965bb31
EN
1171 OPT_BOOL(0, "show-original-ids", &show_original_ids,
1172 N_("Show original object ids of blobs/commits")),
a1638cfe
EN
1173 OPT_BOOL(0, "mark-tags", &mark_tags,
1174 N_("Label tags with mark ids")),
530ca19c 1175
f2dc849e
JS
1176 OPT_END()
1177 };
1178
dcfdbdf0
MV
1179 if (argc == 1)
1180 usage_with_options (fast_export_usage, options);
1181
f2dc849e 1182 /* we handle encodings */
ef90d6d4 1183 git_config(git_default_config, NULL);
f2dc849e 1184
2abf3503 1185 repo_init_revisions(the_repository, &revs, prefix);
87be2523 1186 init_revision_sources(&revision_sources);
668f3aa7 1187 revs.topo_order = 1;
87be2523 1188 revs.sources = &revision_sources;
32164131 1189 revs.rewrite_parents = 1;
8b2f86a7
FC
1190 argc = parse_options(argc, argv, prefix, options, fast_export_usage,
1191 PARSE_OPT_KEEP_ARGV0 | PARSE_OPT_KEEP_UNKNOWN);
f2dc849e 1192 argc = setup_revisions(argc, argv, &revs, NULL);
f2dc849e
JS
1193 if (argc > 1)
1194 usage_with_options (fast_export_usage, options);
1195
03e9010c 1196 if (refspecs_list.nr) {
03e9010c
FC
1197 int i;
1198
03e9010c 1199 for (i = 0; i < refspecs_list.nr; i++)
16eefc8e 1200 refspec_append(&refspecs, refspecs_list.items[i].string);
03e9010c
FC
1201
1202 string_list_clear(&refspecs_list, 1);
03e9010c
FC
1203 }
1204
82670a5c
SR
1205 if (use_done_feature)
1206 printf("feature done\n");
1207
208d6924
EN
1208 if (import_filename && import_filename_if_exists)
1209 die(_("Cannot pass both --import-marks and --import-marks-if-exists"));
df6a7ff7 1210 if (import_filename)
208d6924
EN
1211 import_marks(import_filename, 0);
1212 else if (import_filename_if_exists)
1213 import_marks(import_filename_if_exists, 1);
c4458ecd 1214 lastimportid = last_idnum;
df6a7ff7 1215
afe069d1 1216 if (import_filename && revs.prune_data.nr)
4087a02e
EN
1217 full_tree = 1;
1218
1d844ee7 1219 get_tags_and_duplicates(&revs.cmdline);
f2dc849e 1220
3d51e1b5
MK
1221 if (prepare_revision_walk(&revs))
1222 die("revision walk setup failed");
f2dc849e 1223 revs.diffopt.format_callback = show_filemodify;
b3e8ca89 1224 revs.diffopt.format_callback_data = &paths_of_changed_objects;
0d1e0e78 1225 revs.diffopt.flags.recursive = 1;
f2dc849e
JS
1226 while ((commit = get_revision(&revs))) {
1227 if (has_unshown_parent(commit)) {
f2dc849e 1228 add_object_array(&commit->object, NULL, &commits);
f2dc849e
JS
1229 }
1230 else {
b3e8ca89
JT
1231 handle_commit(commit, &revs, &paths_of_changed_objects);
1232 handle_tail(&commits, &revs, &paths_of_changed_objects);
f2dc849e
JS
1233 }
1234 }
1235
fdf31b63
EN
1236 handle_tags_and_duplicates(&extra_refs);
1237 handle_tags_and_duplicates(&tag_refs);
60ed2643 1238 handle_deletes();
f2dc849e 1239
c4458ecd 1240 if (export_filename && lastimportid != last_idnum)
df6a7ff7
PB
1241 export_marks(export_filename);
1242
82670a5c
SR
1243 if (use_done_feature)
1244 printf("done\n");
1245
16eefc8e 1246 refspec_clear(&refspecs);
03e9010c 1247
f2dc849e
JS
1248 return 0;
1249}