]> git.ipfire.org Git - thirdparty/git.git/blame - builtin/fast-export.c
i18n: describe: mark parseopt strings for translation
[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"
8#include "commit.h"
9#include "object.h"
10#include "tag.h"
11#include "diff.h"
12#include "diffcore.h"
13#include "log-tree.h"
14#include "revision.h"
15#include "decorate.h"
c455c87c 16#include "string-list.h"
f2dc849e
JS
17#include "utf8.h"
18#include "parse-options.h"
6280dfdc 19#include "quote.h"
f2dc849e
JS
20
21static const char *fast_export_usage[] = {
1b1dd23f 22 "git fast-export [rev-list-opts]",
f2dc849e
JS
23 NULL
24};
25
26static int progress;
2d8ad469 27static enum { ABORT, VERBATIM, WARN, STRIP } signed_tag_mode = ABORT;
d7a10c31 28static enum { ERROR, DROP, REWRITE } tag_of_filtered_mode = ERROR;
4e46a8d6 29static int fake_missing_tagger;
82670a5c 30static int use_done_feature;
79559f27 31static int no_data;
7f40ab09 32static int full_tree;
f2dc849e
JS
33
34static int parse_opt_signed_tag_mode(const struct option *opt,
35 const char *arg, int unset)
36{
37 if (unset || !strcmp(arg, "abort"))
38 signed_tag_mode = ABORT;
ee4bc371
JS
39 else if (!strcmp(arg, "verbatim") || !strcmp(arg, "ignore"))
40 signed_tag_mode = VERBATIM;
f2dc849e
JS
41 else if (!strcmp(arg, "warn"))
42 signed_tag_mode = WARN;
43 else if (!strcmp(arg, "strip"))
44 signed_tag_mode = STRIP;
45 else
46 return error("Unknown signed-tag mode: %s", arg);
47 return 0;
48}
49
2d8ad469
EN
50static int parse_opt_tag_of_filtered_mode(const struct option *opt,
51 const char *arg, int unset)
52{
53 if (unset || !strcmp(arg, "abort"))
d7a10c31 54 tag_of_filtered_mode = ERROR;
2d8ad469
EN
55 else if (!strcmp(arg, "drop"))
56 tag_of_filtered_mode = DROP;
57 else if (!strcmp(arg, "rewrite"))
58 tag_of_filtered_mode = REWRITE;
59 else
60 return error("Unknown tag-of-filtered mode: %s", arg);
61 return 0;
62}
63
f2dc849e
JS
64static struct decoration idnums;
65static uint32_t last_idnum;
66
67static int has_unshown_parent(struct commit *commit)
68{
69 struct commit_list *parent;
70
71 for (parent = commit->parents; parent; parent = parent->next)
72 if (!(parent->item->object.flags & SHOWN) &&
73 !(parent->item->object.flags & UNINTERESTING))
74 return 1;
75 return 0;
76}
77
78/* Since intptr_t is C99, we do not use it here */
df6a7ff7 79static inline uint32_t *mark_to_ptr(uint32_t mark)
f2dc849e 80{
df6a7ff7
PB
81 return ((uint32_t *)NULL) + mark;
82}
83
84static inline uint32_t ptr_to_mark(void * mark)
85{
86 return (uint32_t *)mark - (uint32_t *)NULL;
87}
88
89static inline void mark_object(struct object *object, uint32_t mark)
90{
91 add_decoration(&idnums, object, mark_to_ptr(mark));
92}
93
94static inline void mark_next_object(struct object *object)
95{
96 mark_object(object, ++last_idnum);
f2dc849e
JS
97}
98
99static int get_object_mark(struct object *object)
100{
101 void *decoration = lookup_decoration(&idnums, object);
102 if (!decoration)
103 return 0;
df6a7ff7 104 return ptr_to_mark(decoration);
f2dc849e
JS
105}
106
107static void show_progress(void)
108{
109 static int counter = 0;
110 if (!progress)
111 return;
112 if ((++counter % progress) == 0)
113 printf("progress %d objects\n", counter);
114}
115
116static void handle_object(const unsigned char *sha1)
117{
118 unsigned long size;
119 enum object_type type;
120 char *buf;
121 struct object *object;
122
79559f27
GI
123 if (no_data)
124 return;
125
f2dc849e
JS
126 if (is_null_sha1(sha1))
127 return;
128
129 object = parse_object(sha1);
130 if (!object)
131 die ("Could not read blob %s", sha1_to_hex(sha1));
132
133 if (object->flags & SHOWN)
134 return;
135
136 buf = read_sha1_file(sha1, &type, &size);
137 if (!buf)
138 die ("Could not read blob %s", sha1_to_hex(sha1));
139
df6a7ff7 140 mark_next_object(object);
f2dc849e 141
6e1c2344 142 printf("blob\nmark :%"PRIu32"\ndata %lu\n", last_idnum, size);
b0fe0d72 143 if (size && fwrite(buf, size, 1, stdout) != 1)
0721c314 144 die_errno ("Could not write blob '%s'", sha1_to_hex(sha1));
f2dc849e
JS
145 printf("\n");
146
147 show_progress();
148
149 object->flags |= SHOWN;
150 free(buf);
151}
152
060df624
EN
153static int depth_first(const void *a_, const void *b_)
154{
155 const struct diff_filepair *a = *((const struct diff_filepair **)a_);
156 const struct diff_filepair *b = *((const struct diff_filepair **)b_);
157 const char *name_a, *name_b;
158 int len_a, len_b, len;
159 int cmp;
160
161 name_a = a->one ? a->one->path : a->two->path;
162 name_b = b->one ? b->one->path : b->two->path;
163
164 len_a = strlen(name_a);
165 len_b = strlen(name_b);
166 len = (len_a < len_b) ? len_a : len_b;
167
168 /* strcmp will sort 'd' before 'd/e', we want 'd/e' before 'd' */
169 cmp = memcmp(name_a, name_b, len);
170 if (cmp)
171 return cmp;
4ce6fb80
JS
172 cmp = len_b - len_a;
173 if (cmp)
174 return cmp;
175 /*
176 * Move 'R'ename entries last so that all references of the file
177 * appear in the output before it is renamed (e.g., when a file
178 * was copied and renamed in the same commit).
179 */
180 return (a->status == 'R') - (b->status == 'R');
060df624
EN
181}
182
6280dfdc
JK
183static void print_path(const char *path)
184{
185 int need_quote = quote_c_style(path, NULL, NULL, 0);
186 if (need_quote)
187 quote_c_style(path, NULL, stdout, 0);
ff59f6da
JS
188 else if (strchr(path, ' '))
189 printf("\"%s\"", path);
6280dfdc
JK
190 else
191 printf("%s", path);
192}
193
f2dc849e
JS
194static void show_filemodify(struct diff_queue_struct *q,
195 struct diff_options *options, void *data)
196{
197 int i;
060df624
EN
198
199 /*
200 * Handle files below a directory first, in case they are all deleted
201 * and the directory changes to a file or symlink.
202 */
203 qsort(q->queue, q->nr, sizeof(q->queue[0]), depth_first);
204
f2dc849e 205 for (i = 0; i < q->nr; i++) {
ae7c5dce 206 struct diff_filespec *ospec = q->queue[i]->one;
f2dc849e 207 struct diff_filespec *spec = q->queue[i]->two;
ae7c5dce
AG
208
209 switch (q->queue[i]->status) {
210 case DIFF_STATUS_DELETED:
6280dfdc
JK
211 printf("D ");
212 print_path(spec->path);
213 putchar('\n');
ae7c5dce
AG
214 break;
215
216 case DIFF_STATUS_COPIED:
217 case DIFF_STATUS_RENAMED:
6280dfdc
JK
218 printf("%c ", q->queue[i]->status);
219 print_path(ospec->path);
220 putchar(' ');
221 print_path(spec->path);
222 putchar('\n');
ae7c5dce
AG
223
224 if (!hashcmp(ospec->sha1, spec->sha1) &&
225 ospec->mode == spec->mode)
226 break;
227 /* fallthrough */
228
229 case DIFF_STATUS_TYPE_CHANGED:
230 case DIFF_STATUS_MODIFIED:
231 case DIFF_STATUS_ADDED:
03db4525
AG
232 /*
233 * Links refer to objects in another repositories;
234 * output the SHA-1 verbatim.
235 */
79559f27 236 if (no_data || S_ISGITLINK(spec->mode))
6280dfdc
JK
237 printf("M %06o %s ", spec->mode,
238 sha1_to_hex(spec->sha1));
03db4525
AG
239 else {
240 struct object *object = lookup_object(spec->sha1);
6280dfdc
JK
241 printf("M %06o :%d ", spec->mode,
242 get_object_mark(object));
03db4525 243 }
6280dfdc
JK
244 print_path(spec->path);
245 putchar('\n');
ae7c5dce
AG
246 break;
247
248 default:
249 die("Unexpected comparison status '%c' for %s, %s",
250 q->queue[i]->status,
251 ospec->path ? ospec->path : "none",
252 spec->path ? spec->path : "none");
f2dc849e
JS
253 }
254 }
255}
256
257static const char *find_encoding(const char *begin, const char *end)
258{
259 const char *needle = "\nencoding ";
260 char *bol, *eol;
261
262 bol = memmem(begin, end ? end - begin : strlen(begin),
263 needle, strlen(needle));
264 if (!bol)
265 return git_commit_encoding;
266 bol += strlen(needle);
267 eol = strchrnul(bol, '\n');
268 *eol = '\0';
269 return bol;
270}
271
272static void handle_commit(struct commit *commit, struct rev_info *rev)
273{
274 int saved_output_format = rev->diffopt.output_format;
275 const char *author, *author_end, *committer, *committer_end;
276 const char *encoding, *message;
277 char *reencoded = NULL;
278 struct commit_list *p;
279 int i;
280
281 rev->diffopt.output_format = DIFF_FORMAT_CALLBACK;
282
283 parse_commit(commit);
284 author = strstr(commit->buffer, "\nauthor ");
285 if (!author)
286 die ("Could not find author in commit %s",
287 sha1_to_hex(commit->object.sha1));
288 author++;
289 author_end = strchrnul(author, '\n');
290 committer = strstr(author_end, "\ncommitter ");
291 if (!committer)
292 die ("Could not find committer in commit %s",
293 sha1_to_hex(commit->object.sha1));
294 committer++;
295 committer_end = strchrnul(committer, '\n');
296 message = strstr(committer_end, "\n\n");
297 encoding = find_encoding(committer_end, message);
298 if (message)
299 message += 2;
300
ebeec7db 301 if (commit->parents &&
4087a02e
EN
302 get_object_mark(&commit->parents->item->object) != 0 &&
303 !full_tree) {
f2dc849e
JS
304 parse_commit(commit->parents->item);
305 diff_tree_sha1(commit->parents->item->tree->object.sha1,
306 commit->tree->object.sha1, "", &rev->diffopt);
307 }
308 else
309 diff_root_tree_sha1(commit->tree->object.sha1,
310 "", &rev->diffopt);
311
03db4525 312 /* Export the referenced blobs, and remember the marks. */
f2dc849e 313 for (i = 0; i < diff_queued_diff.nr; i++)
03db4525
AG
314 if (!S_ISGITLINK(diff_queued_diff.queue[i]->two->mode))
315 handle_object(diff_queued_diff.queue[i]->two->sha1);
f2dc849e 316
df6a7ff7 317 mark_next_object(&commit->object);
f2dc849e
JS
318 if (!is_encoding_utf8(encoding))
319 reencoded = reencode_string(message, "UTF-8", encoding);
d8933f01
SP
320 if (!commit->parents)
321 printf("reset %s\n", (const char*)commit->util);
6e1c2344 322 printf("commit %s\nmark :%"PRIu32"\n%.*s\n%.*s\ndata %u\n%s",
f2dc849e
JS
323 (const char *)commit->util, last_idnum,
324 (int)(author_end - author), author,
325 (int)(committer_end - committer), committer,
326 (unsigned)(reencoded
327 ? strlen(reencoded) : message
328 ? strlen(message) : 0),
329 reencoded ? reencoded : message ? message : "");
8e0f7003 330 free(reencoded);
f2dc849e
JS
331
332 for (i = 0, p = commit->parents; p; p = p->next) {
333 int mark = get_object_mark(&p->item->object);
334 if (!mark)
335 continue;
336 if (i == 0)
337 printf("from :%d\n", mark);
f2dc849e 338 else
5070b49e 339 printf("merge :%d\n", mark);
f2dc849e
JS
340 i++;
341 }
f2dc849e 342
4087a02e
EN
343 if (full_tree)
344 printf("deleteall\n");
f2dc849e
JS
345 log_tree_diff_flush(rev);
346 rev->diffopt.output_format = saved_output_format;
347
348 printf("\n");
349
350 show_progress();
351}
352
353static void handle_tail(struct object_array *commits, struct rev_info *revs)
354{
355 struct commit *commit;
356 while (commits->nr) {
357 commit = (struct commit *)commits->objects[commits->nr - 1].item;
358 if (has_unshown_parent(commit))
359 return;
360 handle_commit(commit, revs);
361 commits->nr--;
362 }
363}
364
365static void handle_tag(const char *name, struct tag *tag)
366{
367 unsigned long size;
368 enum object_type type;
369 char *buf;
370 const char *tagger, *tagger_end, *message;
371 size_t message_size = 0;
02c48cd6 372 struct object *tagged;
2d8ad469
EN
373 int tagged_mark;
374 struct commit *p;
02c48cd6
EN
375
376 /* Trees have no identifer in fast-export output, thus we have no way
377 * to output tags of trees, tags of tags of trees, etc. Simply omit
378 * such tags.
379 */
380 tagged = tag->tagged;
381 while (tagged->type == OBJ_TAG) {
382 tagged = ((struct tag *)tagged)->tagged;
383 }
384 if (tagged->type == OBJ_TREE) {
385 warning("Omitting tag %s,\nsince tags of trees (or tags of tags of trees, etc.) are not supported.",
386 sha1_to_hex(tag->object.sha1));
387 return;
388 }
f2dc849e
JS
389
390 buf = read_sha1_file(tag->object.sha1, &type, &size);
391 if (!buf)
392 die ("Could not read tag %s", sha1_to_hex(tag->object.sha1));
393 message = memmem(buf, size, "\n\n", 2);
394 if (message) {
395 message += 2;
396 message_size = strlen(message);
397 }
398 tagger = memmem(buf, message ? message - buf : size, "\ntagger ", 8);
4e46a8d6
JS
399 if (!tagger) {
400 if (fake_missing_tagger)
401 tagger = "tagger Unspecified Tagger "
402 "<unspecified-tagger> 0 +0000";
403 else
404 tagger = "";
405 tagger_end = tagger + strlen(tagger);
406 } else {
407 tagger++;
408 tagger_end = strchrnul(tagger, '\n');
409 }
f2dc849e
JS
410
411 /* handle signed tags */
412 if (message) {
413 const char *signature = strstr(message,
414 "\n-----BEGIN PGP SIGNATURE-----\n");
415 if (signature)
416 switch(signed_tag_mode) {
417 case ABORT:
418 die ("Encountered signed tag %s; use "
419 "--signed-tag=<mode> to handle it.",
420 sha1_to_hex(tag->object.sha1));
421 case WARN:
422 warning ("Exporting signed tag %s",
423 sha1_to_hex(tag->object.sha1));
424 /* fallthru */
ee4bc371 425 case VERBATIM:
f2dc849e
JS
426 break;
427 case STRIP:
428 message_size = signature + 1 - message;
429 break;
430 }
431 }
432
2d8ad469
EN
433 /* handle tag->tagged having been filtered out due to paths specified */
434 tagged = tag->tagged;
435 tagged_mark = get_object_mark(tagged);
436 if (!tagged_mark) {
437 switch(tag_of_filtered_mode) {
438 case ABORT:
439 die ("Tag %s tags unexported object; use "
440 "--tag-of-filtered-object=<mode> to handle it.",
441 sha1_to_hex(tag->object.sha1));
442 case DROP:
443 /* Ignore this tag altogether */
444 return;
445 case REWRITE:
446 if (tagged->type != OBJ_COMMIT) {
447 die ("Tag %s tags unexported %s!",
448 sha1_to_hex(tag->object.sha1),
449 typename(tagged->type));
450 }
451 p = (struct commit *)tagged;
452 for (;;) {
453 if (p->parents && p->parents->next)
454 break;
455 if (p->object.flags & UNINTERESTING)
456 break;
457 if (!(p->object.flags & TREESAME))
458 break;
459 if (!p->parents)
460 die ("Can't find replacement commit for tag %s\n",
461 sha1_to_hex(tag->object.sha1));
462 p = p->parents->item;
463 }
464 tagged_mark = get_object_mark(&p->object);
465 }
466 }
467
f2dc849e
JS
468 if (!prefixcmp(name, "refs/tags/"))
469 name += 10;
4e46a8d6 470 printf("tag %s\nfrom :%d\n%.*s%sdata %d\n%.*s\n",
2d8ad469 471 name, tagged_mark,
f2dc849e 472 (int)(tagger_end - tagger), tagger,
4e46a8d6 473 tagger == tagger_end ? "" : "\n",
f2dc849e
JS
474 (int)message_size, (int)message_size, message ? message : "");
475}
476
477static void get_tags_and_duplicates(struct object_array *pending,
c455c87c 478 struct string_list *extra_refs)
f2dc849e
JS
479{
480 struct tag *tag;
481 int i;
482
483 for (i = 0; i < pending->nr; i++) {
484 struct object_array_entry *e = pending->objects + i;
485 unsigned char sha1[20];
486 struct commit *commit = commit;
487 char *full_name;
488
489 if (dwim_ref(e->name, strlen(e->name), sha1, &full_name) != 1)
490 continue;
491
492 switch (e->item->type) {
493 case OBJ_COMMIT:
494 commit = (struct commit *)e->item;
495 break;
496 case OBJ_TAG:
497 tag = (struct tag *)e->item;
1982467d
EFL
498
499 /* handle nested tags */
f2dc849e 500 while (tag && tag->object.type == OBJ_TAG) {
1982467d 501 parse_object(tag->object.sha1);
1d2f80fa 502 string_list_append(extra_refs, full_name)->util = tag;
f2dc849e
JS
503 tag = (struct tag *)tag->tagged;
504 }
505 if (!tag)
506 die ("Tag %s points nowhere?", e->name);
507 switch(tag->object.type) {
508 case OBJ_COMMIT:
509 commit = (struct commit *)tag;
510 break;
511 case OBJ_BLOB:
512 handle_object(tag->object.sha1);
513 continue;
1982467d 514 default: /* OBJ_TAG (nested tags) is already handled */
c0582c53
EFL
515 warning("Tag points to object of unexpected type %s, skipping.",
516 typename(tag->object.type));
517 continue;
f2dc849e
JS
518 }
519 break;
520 default:
2d07f6d4
EFL
521 warning("%s: Unexpected object of type %s, skipping.",
522 e->name,
523 typename(e->item->type));
524 continue;
f2dc849e
JS
525 }
526 if (commit->util)
527 /* more than one name for the same object */
1d2f80fa 528 string_list_append(extra_refs, full_name)->util = commit;
f2dc849e
JS
529 else
530 commit->util = full_name;
531 }
532}
533
c455c87c 534static void handle_tags_and_duplicates(struct string_list *extra_refs)
f2dc849e
JS
535{
536 struct commit *commit;
537 int i;
538
539 for (i = extra_refs->nr - 1; i >= 0; i--) {
c455c87c 540 const char *name = extra_refs->items[i].string;
f2dc849e
JS
541 struct object *object = extra_refs->items[i].util;
542 switch (object->type) {
543 case OBJ_TAG:
544 handle_tag(name, (struct tag *)object);
545 break;
546 case OBJ_COMMIT:
547 /* create refs pointing to already seen commits */
548 commit = (struct commit *)object;
549 printf("reset %s\nfrom :%d\n\n", name,
550 get_object_mark(&commit->object));
551 show_progress();
552 break;
553 }
554 }
555}
556
df6a7ff7
PB
557static void export_marks(char *file)
558{
559 unsigned int i;
560 uint32_t mark;
561 struct object_decoration *deco = idnums.hash;
562 FILE *f;
96d69b55 563 int e = 0;
df6a7ff7
PB
564
565 f = fopen(file, "w");
566 if (!f)
bb6ad28c 567 die_errno("Unable to open marks file %s for writing.", file);
df6a7ff7 568
69913575
JH
569 for (i = 0; i < idnums.size; i++) {
570 if (deco->base && deco->base->type == 1) {
df6a7ff7 571 mark = ptr_to_mark(deco->decoration);
96d69b55
MA
572 if (fprintf(f, ":%"PRIu32" %s\n", mark,
573 sha1_to_hex(deco->base->sha1)) < 0) {
574 e = 1;
575 break;
576 }
df6a7ff7 577 }
69913575 578 deco++;
df6a7ff7
PB
579 }
580
96d69b55
MA
581 e |= ferror(f);
582 e |= fclose(f);
583 if (e)
df6a7ff7
PB
584 error("Unable to write marks file %s.", file);
585}
586
69913575 587static void import_marks(char *input_file)
df6a7ff7
PB
588{
589 char line[512];
590 FILE *f = fopen(input_file, "r");
591 if (!f)
d824cbba 592 die_errno("cannot read '%s'", input_file);
df6a7ff7
PB
593
594 while (fgets(line, sizeof(line), f)) {
595 uint32_t mark;
596 char *line_end, *mark_end;
597 unsigned char sha1[20];
598 struct object *object;
599
600 line_end = strchr(line, '\n');
601 if (line[0] != ':' || !line_end)
602 die("corrupt mark line: %s", line);
69913575 603 *line_end = '\0';
df6a7ff7
PB
604
605 mark = strtoumax(line + 1, &mark_end, 10);
606 if (!mark || mark_end == line + 1
607 || *mark_end != ' ' || get_sha1(mark_end + 1, sha1))
608 die("corrupt mark line: %s", line);
609
610 object = parse_object(sha1);
611 if (!object)
612 die ("Could not read blob %s", sha1_to_hex(sha1));
613
614 if (object->flags & SHOWN)
43bc2302 615 error("Object %s already has a mark", sha1_to_hex(sha1));
df6a7ff7
PB
616
617 mark_object(object, mark);
618 if (last_idnum < mark)
619 last_idnum = mark;
620
621 object->flags |= SHOWN;
622 }
623 fclose(f);
624}
625
f2dc849e
JS
626int cmd_fast_export(int argc, const char **argv, const char *prefix)
627{
628 struct rev_info revs;
3cd47459 629 struct object_array commits = OBJECT_ARRAY_INIT;
183113a5 630 struct string_list extra_refs = STRING_LIST_INIT_NODUP;
f2dc849e 631 struct commit *commit;
df6a7ff7 632 char *export_filename = NULL, *import_filename = NULL;
f2dc849e
JS
633 struct option options[] = {
634 OPT_INTEGER(0, "progress", &progress,
635 "show progress after <n> objects"),
636 OPT_CALLBACK(0, "signed-tags", &signed_tag_mode, "mode",
637 "select handling of signed tags",
638 parse_opt_signed_tag_mode),
2d8ad469
EN
639 OPT_CALLBACK(0, "tag-of-filtered-object", &tag_of_filtered_mode, "mode",
640 "select handling of tags that tag filtered objects",
641 parse_opt_tag_of_filtered_mode),
23c6a803 642 OPT_STRING(0, "export-marks", &export_filename, "file",
df6a7ff7 643 "Dump marks to this file"),
23c6a803 644 OPT_STRING(0, "import-marks", &import_filename, "file",
df6a7ff7 645 "Import marks from this file"),
4e46a8d6
JS
646 OPT_BOOLEAN(0, "fake-missing-tagger", &fake_missing_tagger,
647 "Fake a tagger when tags lack one"),
7f40ab09
EN
648 OPT_BOOLEAN(0, "full-tree", &full_tree,
649 "Output full tree for each commit"),
82670a5c
SR
650 OPT_BOOLEAN(0, "use-done-feature", &use_done_feature,
651 "Use the done feature to terminate the stream"),
cbb08c2e 652 OPT_BOOL(0, "no-data", &no_data, "Skip output of blob data"),
f2dc849e
JS
653 OPT_END()
654 };
655
dcfdbdf0
MV
656 if (argc == 1)
657 usage_with_options (fast_export_usage, options);
658
f2dc849e 659 /* we handle encodings */
ef90d6d4 660 git_config(git_default_config, NULL);
f2dc849e
JS
661
662 init_revisions(&revs, prefix);
668f3aa7 663 revs.topo_order = 1;
2374502c 664 revs.show_source = 1;
32164131 665 revs.rewrite_parents = 1;
f2dc849e 666 argc = setup_revisions(argc, argv, &revs, NULL);
37782920 667 argc = parse_options(argc, argv, prefix, options, fast_export_usage, 0);
f2dc849e
JS
668 if (argc > 1)
669 usage_with_options (fast_export_usage, options);
670
82670a5c
SR
671 if (use_done_feature)
672 printf("feature done\n");
673
df6a7ff7
PB
674 if (import_filename)
675 import_marks(import_filename);
676
afe069d1 677 if (import_filename && revs.prune_data.nr)
4087a02e
EN
678 full_tree = 1;
679
f2dc849e
JS
680 get_tags_and_duplicates(&revs.pending, &extra_refs);
681
3d51e1b5
MK
682 if (prepare_revision_walk(&revs))
683 die("revision walk setup failed");
f2dc849e
JS
684 revs.diffopt.format_callback = show_filemodify;
685 DIFF_OPT_SET(&revs.diffopt, RECURSIVE);
686 while ((commit = get_revision(&revs))) {
687 if (has_unshown_parent(commit)) {
f2dc849e 688 add_object_array(&commit->object, NULL, &commits);
f2dc849e
JS
689 }
690 else {
691 handle_commit(commit, &revs);
692 handle_tail(&commits, &revs);
693 }
694 }
695
696 handle_tags_and_duplicates(&extra_refs);
697
df6a7ff7
PB
698 if (export_filename)
699 export_marks(export_filename);
700
82670a5c
SR
701 if (use_done_feature)
702 printf("done\n");
703
f2dc849e
JS
704 return 0;
705}