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