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