diff-index: careful when inspecting work tree items
[git/dscho.git] / diff-lib.c
blobad9ed13fc990fa6084987b065531ef89d3e6b87c
1 /*
2 * Copyright (C) 2005 Junio C Hamano
3 */
4 #include "cache.h"
5 #include "quote.h"
6 #include "commit.h"
7 #include "diff.h"
8 #include "diffcore.h"
9 #include "revision.h"
10 #include "cache-tree.h"
11 #include "path-list.h"
12 #include "unpack-trees.h"
13 #include "refs.h"
16 * diff-files
19 static int read_directory(const char *path, struct path_list *list)
21 DIR *dir;
22 struct dirent *e;
24 if (!(dir = opendir(path)))
25 return error("Could not open directory %s", path);
27 while ((e = readdir(dir)))
28 if (strcmp(".", e->d_name) && strcmp("..", e->d_name))
29 path_list_insert(e->d_name, list);
31 closedir(dir);
32 return 0;
35 static int get_mode(const char *path, int *mode)
37 struct stat st;
39 if (!path || !strcmp(path, "/dev/null"))
40 *mode = 0;
41 else if (!strcmp(path, "-"))
42 *mode = create_ce_mode(0666);
43 else if (stat(path, &st))
44 return error("Could not access '%s'", path);
45 else
46 *mode = st.st_mode;
47 return 0;
50 static int queue_diff(struct diff_options *o,
51 const char *name1, const char *name2)
53 int mode1 = 0, mode2 = 0;
55 if (get_mode(name1, &mode1) || get_mode(name2, &mode2))
56 return -1;
58 if (mode1 && mode2 && S_ISDIR(mode1) != S_ISDIR(mode2))
59 return error("file/directory conflict: %s, %s", name1, name2);
61 if (S_ISDIR(mode1) || S_ISDIR(mode2)) {
62 char buffer1[PATH_MAX], buffer2[PATH_MAX];
63 struct path_list p1 = {NULL, 0, 0, 1}, p2 = {NULL, 0, 0, 1};
64 int len1 = 0, len2 = 0, i1, i2, ret = 0;
66 if (name1 && read_directory(name1, &p1))
67 return -1;
68 if (name2 && read_directory(name2, &p2)) {
69 path_list_clear(&p1, 0);
70 return -1;
73 if (name1) {
74 len1 = strlen(name1);
75 if (len1 > 0 && name1[len1 - 1] == '/')
76 len1--;
77 memcpy(buffer1, name1, len1);
78 buffer1[len1++] = '/';
81 if (name2) {
82 len2 = strlen(name2);
83 if (len2 > 0 && name2[len2 - 1] == '/')
84 len2--;
85 memcpy(buffer2, name2, len2);
86 buffer2[len2++] = '/';
89 for (i1 = i2 = 0; !ret && (i1 < p1.nr || i2 < p2.nr); ) {
90 const char *n1, *n2;
91 int comp;
93 if (i1 == p1.nr)
94 comp = 1;
95 else if (i2 == p2.nr)
96 comp = -1;
97 else
98 comp = strcmp(p1.items[i1].path,
99 p2.items[i2].path);
101 if (comp > 0)
102 n1 = NULL;
103 else {
104 n1 = buffer1;
105 strncpy(buffer1 + len1, p1.items[i1++].path,
106 PATH_MAX - len1);
109 if (comp < 0)
110 n2 = NULL;
111 else {
112 n2 = buffer2;
113 strncpy(buffer2 + len2, p2.items[i2++].path,
114 PATH_MAX - len2);
117 ret = queue_diff(o, n1, n2);
119 path_list_clear(&p1, 0);
120 path_list_clear(&p2, 0);
122 return ret;
123 } else {
124 struct diff_filespec *d1, *d2;
126 if (DIFF_OPT_TST(o, REVERSE_DIFF)) {
127 unsigned tmp;
128 const char *tmp_c;
129 tmp = mode1; mode1 = mode2; mode2 = tmp;
130 tmp_c = name1; name1 = name2; name2 = tmp_c;
133 if (!name1)
134 name1 = "/dev/null";
135 if (!name2)
136 name2 = "/dev/null";
137 d1 = alloc_filespec(name1);
138 d2 = alloc_filespec(name2);
139 fill_filespec(d1, null_sha1, mode1);
140 fill_filespec(d2, null_sha1, mode2);
142 diff_queue(&diff_queued_diff, d1, d2);
143 return 0;
148 * Does the path name a blob in the working tree, or a directory
149 * in the working tree?
151 static int is_in_index(const char *path)
153 int len, pos;
154 struct cache_entry *ce;
156 len = strlen(path);
157 while (path[len-1] == '/')
158 len--;
159 if (!len)
160 return 1; /* "." */
161 pos = cache_name_pos(path, len);
162 if (0 <= pos)
163 return 1;
164 pos = -1 - pos;
165 while (pos < active_nr) {
166 ce = active_cache[pos++];
167 if (ce_namelen(ce) <= len ||
168 strncmp(ce->name, path, len) ||
169 (ce->name[len] > '/'))
170 break; /* path cannot be a prefix */
171 if (ce->name[len] == '/')
172 return 1;
174 return 0;
177 static int handle_diff_files_args(struct rev_info *revs,
178 int argc, const char **argv,
179 unsigned int *options)
181 *options = 0;
183 /* revs->max_count == -2 means --no-index */
184 while (1 < argc && argv[1][0] == '-') {
185 if (!strcmp(argv[1], "--base"))
186 revs->max_count = 1;
187 else if (!strcmp(argv[1], "--ours"))
188 revs->max_count = 2;
189 else if (!strcmp(argv[1], "--theirs"))
190 revs->max_count = 3;
191 else if (!strcmp(argv[1], "-n") ||
192 !strcmp(argv[1], "--no-index")) {
193 revs->max_count = -2;
194 DIFF_OPT_SET(&revs->diffopt, EXIT_WITH_STATUS);
195 DIFF_OPT_SET(&revs->diffopt, NO_INDEX);
197 else if (!strcmp(argv[1], "-q"))
198 *options |= DIFF_SILENT_ON_REMOVED;
199 else
200 return error("invalid option: %s", argv[1]);
201 argv++; argc--;
204 if (revs->max_count == -1 && revs->diffopt.nr_paths == 2) {
206 * If two files are specified, and at least one is untracked,
207 * default to no-index.
209 read_cache();
210 if (!is_in_index(revs->diffopt.paths[0]) ||
211 !is_in_index(revs->diffopt.paths[1])) {
212 revs->max_count = -2;
213 DIFF_OPT_SET(&revs->diffopt, NO_INDEX);
218 * Make sure there are NO revision (i.e. pending object) parameter,
219 * rev.max_count is reasonable (0 <= n <= 3),
220 * there is no other revision filtering parameters.
222 if (revs->pending.nr || revs->max_count > 3 ||
223 revs->min_age != -1 || revs->max_age != -1)
224 return error("no revision allowed with diff-files");
226 if (revs->max_count == -1 &&
227 (revs->diffopt.output_format & DIFF_FORMAT_PATCH))
228 revs->combine_merges = revs->dense_combined_merges = 1;
230 return 0;
233 static int is_outside_repo(const char *path, int nongit, const char *prefix)
235 int i;
236 if (nongit || !strcmp(path, "-") || is_absolute_path(path))
237 return 1;
238 if (prefixcmp(path, "../"))
239 return 0;
240 if (!prefix)
241 return 1;
242 for (i = strlen(prefix); !prefixcmp(path, "../"); ) {
243 while (i > 0 && prefix[i - 1] != '/')
244 i--;
245 if (--i < 0)
246 return 1;
247 path += 3;
249 return 0;
252 int setup_diff_no_index(struct rev_info *revs,
253 int argc, const char ** argv, int nongit, const char *prefix)
255 int i;
256 for (i = 1; i < argc; i++)
257 if (argv[i][0] != '-' || argv[i][1] == '\0')
258 break;
259 else if (!strcmp(argv[i], "--")) {
260 i++;
261 break;
262 } else if (i < argc - 3 && !strcmp(argv[i], "--no-index")) {
263 i = argc - 3;
264 DIFF_OPT_SET(&revs->diffopt, EXIT_WITH_STATUS);
265 break;
267 if (argc != i + 2 || (!is_outside_repo(argv[i + 1], nongit, prefix) &&
268 !is_outside_repo(argv[i], nongit, prefix)))
269 return -1;
271 diff_setup(&revs->diffopt);
272 for (i = 1; i < argc - 2; )
273 if (!strcmp(argv[i], "--no-index"))
274 i++;
275 else {
276 int j = diff_opt_parse(&revs->diffopt,
277 argv + i, argc - i);
278 if (!j)
279 die("invalid diff option/value: %s", argv[i]);
280 i += j;
283 if (prefix) {
284 int len = strlen(prefix);
286 revs->diffopt.paths = xcalloc(2, sizeof(char*));
287 for (i = 0; i < 2; i++) {
288 const char *p = argv[argc - 2 + i];
290 * stdin should be spelled as '-'; if you have
291 * path that is '-', spell it as ./-.
293 p = (strcmp(p, "-")
294 ? xstrdup(prefix_filename(prefix, len, p))
295 : p);
296 revs->diffopt.paths[i] = p;
299 else
300 revs->diffopt.paths = argv + argc - 2;
301 revs->diffopt.nr_paths = 2;
302 DIFF_OPT_SET(&revs->diffopt, NO_INDEX);
303 revs->max_count = -2;
304 if (diff_setup_done(&revs->diffopt) < 0)
305 die("diff_setup_done failed");
306 return 0;
309 int run_diff_files_cmd(struct rev_info *revs, int argc, const char **argv)
311 unsigned int options;
313 if (handle_diff_files_args(revs, argc, argv, &options))
314 return -1;
316 if (DIFF_OPT_TST(&revs->diffopt, NO_INDEX)) {
317 if (revs->diffopt.nr_paths != 2)
318 return error("need two files/directories with --no-index");
319 if (queue_diff(&revs->diffopt, revs->diffopt.paths[0],
320 revs->diffopt.paths[1]))
321 return -1;
322 diffcore_std(&revs->diffopt);
323 diff_flush(&revs->diffopt);
325 * The return code for --no-index imitates diff(1):
326 * 0 = no changes, 1 = changes, else error
328 return revs->diffopt.found_changes;
331 if (read_cache() < 0) {
332 perror("read_cache");
333 return -1;
335 return run_diff_files(revs, options);
338 * See if work tree has an entity that can be staged. Return 0 if so,
339 * return 1 if not and return -1 if error.
341 static int check_work_tree_entity(const struct cache_entry *ce, struct stat *st, char *symcache)
343 if (lstat(ce->name, st) < 0) {
344 if (errno != ENOENT && errno != ENOTDIR)
345 return -1;
346 return 1;
348 if (has_symlink_leading_path(ce->name, symcache))
349 return 1;
350 if (S_ISDIR(st->st_mode)) {
351 unsigned char sub[20];
352 if (resolve_gitlink_ref(ce->name, "HEAD", sub))
353 return 1;
355 return 0;
358 int run_diff_files(struct rev_info *revs, unsigned int option)
360 int entries, i;
361 int diff_unmerged_stage = revs->max_count;
362 int silent_on_removed = option & DIFF_SILENT_ON_REMOVED;
363 unsigned ce_option = ((option & DIFF_RACY_IS_MODIFIED)
364 ? CE_MATCH_RACY_IS_DIRTY : 0);
366 if (diff_unmerged_stage < 0)
367 diff_unmerged_stage = 2;
368 entries = active_nr;
369 for (i = 0; i < entries; i++) {
370 struct stat st;
371 unsigned int oldmode, newmode;
372 struct cache_entry *ce = active_cache[i];
373 int changed;
375 if (DIFF_OPT_TST(&revs->diffopt, QUIET) &&
376 DIFF_OPT_TST(&revs->diffopt, HAS_CHANGES))
377 break;
379 if (!ce_path_match(ce, revs->prune_data))
380 continue;
382 if (ce_stage(ce)) {
383 struct combine_diff_path *dpath;
384 int num_compare_stages = 0;
385 size_t path_len;
387 path_len = ce_namelen(ce);
389 dpath = xmalloc(combine_diff_path_size(5, path_len));
390 dpath->path = (char *) &(dpath->parent[5]);
392 dpath->next = NULL;
393 dpath->len = path_len;
394 memcpy(dpath->path, ce->name, path_len);
395 dpath->path[path_len] = '\0';
396 hashclr(dpath->sha1);
397 memset(&(dpath->parent[0]), 0,
398 sizeof(struct combine_diff_parent)*5);
400 if (lstat(ce->name, &st) < 0) {
401 if (errno != ENOENT && errno != ENOTDIR) {
402 perror(ce->name);
403 continue;
405 if (silent_on_removed)
406 continue;
408 else
409 dpath->mode = ce_mode_from_stat(ce, st.st_mode);
411 while (i < entries) {
412 struct cache_entry *nce = active_cache[i];
413 int stage;
415 if (strcmp(ce->name, nce->name))
416 break;
418 /* Stage #2 (ours) is the first parent,
419 * stage #3 (theirs) is the second.
421 stage = ce_stage(nce);
422 if (2 <= stage) {
423 int mode = nce->ce_mode;
424 num_compare_stages++;
425 hashcpy(dpath->parent[stage-2].sha1, nce->sha1);
426 dpath->parent[stage-2].mode = ce_mode_from_stat(nce, mode);
427 dpath->parent[stage-2].status =
428 DIFF_STATUS_MODIFIED;
431 /* diff against the proper unmerged stage */
432 if (stage == diff_unmerged_stage)
433 ce = nce;
434 i++;
437 * Compensate for loop update
439 i--;
441 if (revs->combine_merges && num_compare_stages == 2) {
442 show_combined_diff(dpath, 2,
443 revs->dense_combined_merges,
444 revs);
445 free(dpath);
446 continue;
448 free(dpath);
449 dpath = NULL;
452 * Show the diff for the 'ce' if we found the one
453 * from the desired stage.
455 diff_unmerge(&revs->diffopt, ce->name, 0, null_sha1);
456 if (ce_stage(ce) != diff_unmerged_stage)
457 continue;
460 if (ce_uptodate(ce))
461 continue;
462 if (lstat(ce->name, &st) < 0) {
463 if (errno != ENOENT && errno != ENOTDIR) {
464 perror(ce->name);
465 continue;
467 if (silent_on_removed)
468 continue;
469 diff_addremove(&revs->diffopt, '-', ce->ce_mode,
470 ce->sha1, ce->name, NULL);
471 continue;
473 changed = ce_match_stat(ce, &st, ce_option);
474 if (!changed && !DIFF_OPT_TST(&revs->diffopt, FIND_COPIES_HARDER))
475 continue;
476 oldmode = ce->ce_mode;
477 newmode = ce_mode_from_stat(ce, st.st_mode);
478 diff_change(&revs->diffopt, oldmode, newmode,
479 ce->sha1, (changed ? null_sha1 : ce->sha1),
480 ce->name, NULL);
483 diffcore_std(&revs->diffopt);
484 diff_flush(&revs->diffopt);
485 return 0;
489 * diff-index
492 struct oneway_unpack_data {
493 struct rev_info *revs;
494 char symcache[PATH_MAX];
497 /* A file entry went away or appeared */
498 static void diff_index_show_file(struct rev_info *revs,
499 const char *prefix,
500 struct cache_entry *ce,
501 const unsigned char *sha1, unsigned int mode)
503 diff_addremove(&revs->diffopt, prefix[0], mode,
504 sha1, ce->name, NULL);
507 static int get_stat_data(struct cache_entry *ce,
508 const unsigned char **sha1p,
509 unsigned int *modep,
510 int cached, int match_missing,
511 struct oneway_unpack_data *cbdata)
513 const unsigned char *sha1 = ce->sha1;
514 unsigned int mode = ce->ce_mode;
516 if (!cached) {
517 int changed;
518 struct stat st;
519 changed = check_work_tree_entity(ce, &st, cbdata->symcache);
520 if (changed < 0)
521 return -1;
522 else if (changed) {
523 if (match_missing) {
524 *sha1p = sha1;
525 *modep = mode;
526 return 0;
528 return -1;
530 changed = ce_match_stat(ce, &st, 0);
531 if (changed) {
532 mode = ce_mode_from_stat(ce, st.st_mode);
533 sha1 = null_sha1;
537 *sha1p = sha1;
538 *modep = mode;
539 return 0;
542 static void show_new_file(struct oneway_unpack_data *cbdata,
543 struct cache_entry *new,
544 int cached, int match_missing)
546 const unsigned char *sha1;
547 unsigned int mode;
548 struct rev_info *revs = cbdata->revs;
551 * New file in the index: it might actually be different in
552 * the working copy.
554 if (get_stat_data(new, &sha1, &mode, cached, match_missing, cbdata) < 0)
555 return;
557 diff_index_show_file(revs, "+", new, sha1, mode);
560 static int show_modified(struct oneway_unpack_data *cbdata,
561 struct cache_entry *old,
562 struct cache_entry *new,
563 int report_missing,
564 int cached, int match_missing)
566 unsigned int mode, oldmode;
567 const unsigned char *sha1;
568 struct rev_info *revs = cbdata->revs;
570 if (get_stat_data(new, &sha1, &mode, cached, match_missing, cbdata) < 0) {
571 if (report_missing)
572 diff_index_show_file(revs, "-", old,
573 old->sha1, old->ce_mode);
574 return -1;
577 if (revs->combine_merges && !cached &&
578 (hashcmp(sha1, old->sha1) || hashcmp(old->sha1, new->sha1))) {
579 struct combine_diff_path *p;
580 int pathlen = ce_namelen(new);
582 p = xmalloc(combine_diff_path_size(2, pathlen));
583 p->path = (char *) &p->parent[2];
584 p->next = NULL;
585 p->len = pathlen;
586 memcpy(p->path, new->name, pathlen);
587 p->path[pathlen] = 0;
588 p->mode = mode;
589 hashclr(p->sha1);
590 memset(p->parent, 0, 2 * sizeof(struct combine_diff_parent));
591 p->parent[0].status = DIFF_STATUS_MODIFIED;
592 p->parent[0].mode = new->ce_mode;
593 hashcpy(p->parent[0].sha1, new->sha1);
594 p->parent[1].status = DIFF_STATUS_MODIFIED;
595 p->parent[1].mode = old->ce_mode;
596 hashcpy(p->parent[1].sha1, old->sha1);
597 show_combined_diff(p, 2, revs->dense_combined_merges, revs);
598 free(p);
599 return 0;
602 oldmode = old->ce_mode;
603 if (mode == oldmode && !hashcmp(sha1, old->sha1) &&
604 !DIFF_OPT_TST(&revs->diffopt, FIND_COPIES_HARDER))
605 return 0;
607 diff_change(&revs->diffopt, oldmode, mode,
608 old->sha1, sha1, old->name, NULL);
609 return 0;
613 * This turns all merge entries into "stage 3". That guarantees that
614 * when we read in the new tree (into "stage 1"), we won't lose sight
615 * of the fact that we had unmerged entries.
617 static void mark_merge_entries(void)
619 int i;
620 for (i = 0; i < active_nr; i++) {
621 struct cache_entry *ce = active_cache[i];
622 if (!ce_stage(ce))
623 continue;
624 ce->ce_flags |= CE_STAGEMASK;
629 * This gets a mix of an existing index and a tree, one pathname entry
630 * at a time. The index entry may be a single stage-0 one, but it could
631 * also be multiple unmerged entries (in which case idx_pos/idx_nr will
632 * give you the position and number of entries in the index).
634 static void do_oneway_diff(struct unpack_trees_options *o,
635 struct cache_entry *idx,
636 struct cache_entry *tree)
638 struct oneway_unpack_data *cbdata = o->unpack_data;
639 struct rev_info *revs = cbdata->revs;
640 int match_missing, cached;
643 * Backward compatibility wart - "diff-index -m" does
644 * not mean "do not ignore merges", but "match_missing".
646 * But with the revision flag parsing, that's found in
647 * "!revs->ignore_merges".
649 cached = o->index_only;
650 match_missing = !revs->ignore_merges;
652 if (cached && idx && ce_stage(idx)) {
653 if (tree)
654 diff_unmerge(&revs->diffopt, idx->name, idx->ce_mode, idx->sha1);
655 return;
659 * Something added to the tree?
661 if (!tree) {
662 show_new_file(cbdata, idx, cached, match_missing);
663 return;
667 * Something removed from the tree?
669 if (!idx) {
670 diff_index_show_file(revs, "-", tree, tree->sha1, tree->ce_mode);
671 return;
674 /* Show difference between old and new */
675 show_modified(cbdata, tree, idx, 1, cached, match_missing);
678 static inline void skip_same_name(struct cache_entry *ce, struct unpack_trees_options *o)
680 int len = ce_namelen(ce);
681 const struct index_state *index = o->src_index;
683 while (o->pos < index->cache_nr) {
684 struct cache_entry *next = index->cache[o->pos];
685 if (len != ce_namelen(next))
686 break;
687 if (memcmp(ce->name, next->name, len))
688 break;
689 o->pos++;
694 * The unpack_trees() interface is designed for merging, so
695 * the different source entries are designed primarily for
696 * the source trees, with the old index being really mainly
697 * used for being replaced by the result.
699 * For diffing, the index is more important, and we only have a
700 * single tree.
702 * We're supposed to return how many index entries we want to skip.
704 * This wrapper makes it all more readable, and takes care of all
705 * the fairly complex unpack_trees() semantic requirements, including
706 * the skipping, the path matching, the type conflict cases etc.
708 static int oneway_diff(struct cache_entry **src, struct unpack_trees_options *o)
710 struct cache_entry *idx = src[0];
711 struct cache_entry *tree = src[1];
712 struct oneway_unpack_data *cbdata = o->unpack_data;
713 struct rev_info *revs = cbdata->revs;
715 if (idx && ce_stage(idx))
716 skip_same_name(idx, o);
719 * Unpack-trees generates a DF/conflict entry if
720 * there was a directory in the index and a tree
721 * in the tree. From a diff standpoint, that's a
722 * delete of the tree and a create of the file.
724 if (tree == o->df_conflict_entry)
725 tree = NULL;
727 if (ce_path_match(idx ? idx : tree, revs->prune_data))
728 do_oneway_diff(o, idx, tree);
730 return 0;
733 int run_diff_index(struct rev_info *revs, int cached)
735 struct object *ent;
736 struct tree *tree;
737 const char *tree_name;
738 struct unpack_trees_options opts;
739 struct tree_desc t;
740 struct oneway_unpack_data unpack_cb;
742 mark_merge_entries();
744 ent = revs->pending.objects[0].item;
745 tree_name = revs->pending.objects[0].name;
746 tree = parse_tree_indirect(ent->sha1);
747 if (!tree)
748 return error("bad tree object %s", tree_name);
750 unpack_cb.revs = revs;
751 unpack_cb.symcache[0] = '\0';
752 memset(&opts, 0, sizeof(opts));
753 opts.head_idx = 1;
754 opts.index_only = cached;
755 opts.merge = 1;
756 opts.fn = oneway_diff;
757 opts.unpack_data = &unpack_cb;
758 opts.src_index = &the_index;
759 opts.dst_index = NULL;
761 init_tree_desc(&t, tree->buffer, tree->size);
762 if (unpack_trees(1, &t, &opts))
763 exit(128);
765 diffcore_std(&revs->diffopt);
766 diff_flush(&revs->diffopt);
767 return 0;
770 int do_diff_cache(const unsigned char *tree_sha1, struct diff_options *opt)
772 struct tree *tree;
773 struct rev_info revs;
774 int i;
775 struct cache_entry **dst;
776 struct cache_entry *last = NULL;
777 struct unpack_trees_options opts;
778 struct tree_desc t;
779 struct oneway_unpack_data unpack_cb;
782 * This is used by git-blame to run diff-cache internally;
783 * it potentially needs to repeatedly run this, so we will
784 * start by removing the higher order entries the last round
785 * left behind.
787 dst = active_cache;
788 for (i = 0; i < active_nr; i++) {
789 struct cache_entry *ce = active_cache[i];
790 if (ce_stage(ce)) {
791 if (last && !strcmp(ce->name, last->name))
792 continue;
793 cache_tree_invalidate_path(active_cache_tree,
794 ce->name);
795 last = ce;
796 ce->ce_flags |= CE_REMOVE;
798 *dst++ = ce;
800 active_nr = dst - active_cache;
802 init_revisions(&revs, NULL);
803 revs.prune_data = opt->paths;
804 tree = parse_tree_indirect(tree_sha1);
805 if (!tree)
806 die("bad tree object %s", sha1_to_hex(tree_sha1));
808 unpack_cb.revs = &revs;
809 unpack_cb.symcache[0] = '\0';
810 memset(&opts, 0, sizeof(opts));
811 opts.head_idx = 1;
812 opts.index_only = 1;
813 opts.merge = 1;
814 opts.fn = oneway_diff;
815 opts.unpack_data = &unpack_cb;
816 opts.src_index = &the_index;
817 opts.dst_index = &the_index;
819 init_tree_desc(&t, tree->buffer, tree->size);
820 if (unpack_trees(1, &t, &opts))
821 exit(128);
822 return 0;