From: Junio C Hamano Date: Thu, 27 Jan 2011 18:23:53 +0000 (-0800) Subject: Merge branch 'jn/fast-import-empty-tree-removal' into maint X-Git-Tag: v1.7.4~2^2~2 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/5ce3258122939f93a927c75d308c1c34038f0386?hp=-c Merge branch 'jn/fast-import-empty-tree-removal' into maint * jn/fast-import-empty-tree-removal: fast-import: treat filemodify with empty tree as delete --- 5ce3258122939f93a927c75d308c1c34038f0386 diff --combined fast-import.c index 613623be14,cd9310d1e5..7563e43a39 --- a/fast-import.c +++ b/fast-import.c @@@ -539,17 -539,22 +539,17 @@@ static struct object_entry *insert_obje { unsigned int h = sha1[0] << 8 | sha1[1]; struct object_entry *e = object_table[h]; - struct object_entry *p = NULL; while (e) { if (!hashcmp(sha1, e->idx.sha1)) return e; - p = e; e = e->next; } e = new_object(sha1); - e->next = NULL; + e->next = object_table[h]; e->idx.offset = 0; - if (p) - p->next = e; - else - object_table[h] = e; + object_table[h] = e; return e; } @@@ -1523,14 -1528,6 +1523,14 @@@ static int tree_content_remove for (i = 0; i < t->entry_count; i++) { e = t->entries[i]; if (e->name->str_len == n && !strncmp(p, e->name->str_dat, n)) { + if (slash1 && !S_ISDIR(e->versions[1].mode)) + /* + * If p names a file in some subdirectory, and a + * file or symlink matching the name of the + * parent directory of p exists, then p cannot + * exist and need not be deleted. + */ + return 1; if (!slash1 || !S_ISDIR(e->versions[1].mode)) goto del_entry; if (!e->tree) @@@ -1669,7 -1666,7 +1669,7 @@@ static void dump_marks_helper(FILE *f if (m->shift) { for (k = 0; k < 1024; k++) { if (m->data.sets[k]) - dump_marks_helper(f, (base + k) << m->shift, + dump_marks_helper(f, base + (k << m->shift), m->data.sets[k]); } } else { @@@ -2166,6 -2163,12 +2166,12 @@@ static void file_change_m(struct branc p = uq.buf; } + /* Git does not track empty, non-toplevel directories. */ + if (S_ISDIR(mode) && !memcmp(sha1, EMPTY_TREE_SHA1_BIN, 20) && *p) { + tree_content_remove(&b->branch_tree, p, NULL); + return; + } + if (S_ISGITLINK(mode)) { if (inline_data) die("Git links cannot be specified 'inline': %s", @@@ -2879,7 -2882,7 +2885,7 @@@ static int git_pack_config(const char * } static const char fast_import_usage[] = -"git fast-import [--date-format=f] [--max-pack-size=n] [--big-file-threshold=n] [--depth=n] [--active-branches=n] [--export-marks=marks.file]"; +"git fast-import [--date-format=] [--max-pack-size=] [--big-file-threshold=] [--depth=] [--active-branches=] [--export-marks=]"; static void parse_argv(void) { diff --combined t/t9300-fast-import.sh index 7c059204e9,8487734ada..385e78c22c --- a/t/t9300-fast-import.sh +++ b/t/t9300-fast-import.sh @@@ -166,63 -166,6 +166,63 @@@ test_expect_success test `git rev-parse --verify master:file2` \ = `git rev-parse --verify verify--import-marks:copy-of-file2`' +test_tick +mt=$(git hash-object --stdin < /dev/null) +: >input.blob +: >marks.exp +: >tree.exp + +cat >input.commit < $GIT_COMMITTER_DATE +data <>input.blob <>input.commit + echo "M 100644 :$m m$i" >>input.commit + echo "M 100644 :$n n$i" >>input.commit + + echo ":$l $mt" >>marks.exp + echo ":$m $mt" >>marks.exp + echo ":$n $mt" >>marks.exp + + printf "100644 blob $mt\tl$i\n" >>tree.exp + printf "100644 blob $mt\tm$i\n" >>tree.exp + printf "100644 blob $mt\tn$i\n" >>tree.exp + + l=$(($l + $l)) + m=$(($m + $m)) + n=$(($l + $n)) + + i=$((1 + $i)) +done + +sort tree.exp > tree.exp_s + +test_expect_success 'A: export marks with large values' ' + cat input.blob input.commit | git fast-import --export-marks=marks.large && + git ls-tree refs/heads/verify--dump-marks >tree.out && + test_cmp tree.exp_s tree.out && + test_cmp marks.exp marks.large' + ### ### series B ### @@@ -874,6 -817,48 +874,48 @@@ test_expect_success git diff-tree -C --find-copies-harder -r N4^ N4 >actual && compare_diff_raw expect actual' + test_expect_success \ + 'N: delete directory by copying' \ + 'cat >expect <<-\EOF && + OBJID + :100644 000000 OBJID OBJID D foo/bar/qux + OBJID + :000000 100644 OBJID OBJID A foo/bar/baz + :000000 100644 OBJID OBJID A foo/bar/qux + EOF + empty_tree=$(git mktree input <<-INPUT_END && + commit refs/heads/N-delete + committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE + data < $GIT_COMMITTER_DATE + data <actual && + test_cmp expect actual' + test_expect_success \ 'N: modify copied tree' \ 'cat >expect <<-\EOF && @@@ -1110,10 -1095,11 +1152,10 @@@ test_expect_success 'P: supermodule & submodule mix' \ 'git fast-import