summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <junkio@cox.net>2007-05-23 22:37:03 -0700
committerJunio C Hamano <junkio@cox.net>2007-05-23 22:37:03 -0700
commita21f0f0a22c513130f1268e3296dd52d47d2f0e0 (patch)
treea78ea345b2a1976d49b1b50b4bfb9feb9544f187
parentbaf5597ae43398e485f63f8e9216d34b5cd0a0d6 (diff)
parentaac65ed1bc63619d32516079995f5cbe4bb46492 (diff)
downloadgit-a21f0f0a22c513130f1268e3296dd52d47d2f0e0.tar.gz
Merge branch 'maint' of git://repo.or.cz/git/fastimport into maint
* 'maint' of git://repo.or.cz/git/fastimport: Fix possible coredump with fast-import --import-marks Refactor fast-import branch creation from existing commit fast-import: Fix crash when referencing already existing objects fast-import: Fix uninitialized variable
-rw-r--r--fast-import.c67
-rwxr-xr-xt/t9300-fast-import.sh29
2 files changed, 66 insertions, 30 deletions
diff --git a/fast-import.c b/fast-import.c
index 3a2d5ed8e6..17554f6849 100644
--- a/fast-import.c
+++ b/fast-import.c
@@ -1013,7 +1013,7 @@ static void load_tree(struct tree_entry *root)
return;
myoe = find_object(sha1);
- if (myoe) {
+ if (myoe && myoe->pack_id != MAX_PACK_ID) {
if (myoe->type != OBJ_TREE)
die("Not a tree: %s", sha1_to_hex(sha1));
t->delta_depth = 0;
@@ -1122,6 +1122,7 @@ static void store_tree(struct tree_entry *root)
|| le->pack_id != pack_id) {
lo.data = NULL;
lo.depth = 0;
+ lo.no_free = 0;
} else {
mktree(t, 0, &lo.len, &old_tree);
lo.data = old_tree.buffer;
@@ -1656,6 +1657,33 @@ static void file_change_deleteall(struct branch *b)
load_tree(&b->branch_tree);
}
+static void cmd_from_commit(struct branch *b, char *buf, unsigned long size)
+{
+ if (!buf || size < 46)
+ die("Not a valid commit: %s", sha1_to_hex(b->sha1));
+ if (memcmp("tree ", buf, 5)
+ || get_sha1_hex(buf + 5, b->branch_tree.versions[1].sha1))
+ die("The commit %s is corrupt", sha1_to_hex(b->sha1));
+ hashcpy(b->branch_tree.versions[0].sha1,
+ b->branch_tree.versions[1].sha1);
+}
+
+static void cmd_from_existing(struct branch *b)
+{
+ if (is_null_sha1(b->sha1)) {
+ hashclr(b->branch_tree.versions[0].sha1);
+ hashclr(b->branch_tree.versions[1].sha1);
+ } else {
+ unsigned long size;
+ char *buf;
+
+ buf = read_object_with_reference(b->sha1,
+ commit_type, &size, b->sha1);
+ cmd_from_commit(b, buf, size);
+ free(buf);
+ }
+}
+
static void cmd_from(struct branch *b)
{
const char *from;
@@ -1681,40 +1709,19 @@ static void cmd_from(struct branch *b)
} else if (*from == ':') {
uintmax_t idnum = strtoumax(from + 1, NULL, 10);
struct object_entry *oe = find_mark(idnum);
- unsigned long size;
- char *buf;
if (oe->type != OBJ_COMMIT)
die("Mark :%" PRIuMAX " not a commit", idnum);
hashcpy(b->sha1, oe->sha1);
- buf = gfi_unpack_entry(oe, &size);
- if (!buf || size < 46)
- die("Not a valid commit: %s", from);
- if (memcmp("tree ", buf, 5)
- || get_sha1_hex(buf + 5, b->branch_tree.versions[1].sha1))
- die("The commit %s is corrupt", sha1_to_hex(b->sha1));
- free(buf);
- hashcpy(b->branch_tree.versions[0].sha1,
- b->branch_tree.versions[1].sha1);
- } else if (!get_sha1(from, b->sha1)) {
- if (is_null_sha1(b->sha1)) {
- hashclr(b->branch_tree.versions[0].sha1);
- hashclr(b->branch_tree.versions[1].sha1);
- } else {
+ if (oe->pack_id != MAX_PACK_ID) {
unsigned long size;
- char *buf;
-
- buf = read_object_with_reference(b->sha1,
- commit_type, &size, b->sha1);
- if (!buf || size < 46)
- die("Not a valid commit: %s", from);
- if (memcmp("tree ", buf, 5)
- || get_sha1_hex(buf + 5, b->branch_tree.versions[1].sha1))
- die("The commit %s is corrupt", sha1_to_hex(b->sha1));
+ char *buf = gfi_unpack_entry(oe, &size);
+ cmd_from_commit(b, buf, size);
free(buf);
- hashcpy(b->branch_tree.versions[0].sha1,
- b->branch_tree.versions[1].sha1);
- }
- } else
+ } else
+ cmd_from_existing(b);
+ } else if (!get_sha1(from, b->sha1))
+ cmd_from_existing(b);
+ else
die("Invalid ref name or SHA1 expression: %s", from);
read_next_command();
diff --git a/t/t9300-fast-import.sh b/t/t9300-fast-import.sh
index 8e958da536..72e49f5d3b 100755
--- a/t/t9300-fast-import.sh
+++ b/t/t9300-fast-import.sh
@@ -119,6 +119,35 @@ test_expect_success \
</dev/null &&
git diff -u expect marks.new'
+test_tick
+cat >input <<INPUT_END
+commit refs/heads/verify--import-marks
+committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
+data <<COMMIT
+recreate from :5
+COMMIT
+
+from :5
+M 755 :2 copy-of-file2
+
+INPUT_END
+test_expect_success \
+ 'A: verify marks import does not crash' \
+ 'git-fast-import --import-marks=marks.out <input &&
+ git-whatchanged verify--import-marks'
+test_expect_success \
+ 'A: verify pack' \
+ 'for p in .git/objects/pack/*.pack;do git-verify-pack $p||exit;done'
+cat >expect <<EOF
+:000000 100755 0000000000000000000000000000000000000000 7123f7f44e39be127c5eb701e5968176ee9d78b1 A copy-of-file2
+EOF
+git-diff-tree -M -r master verify--import-marks >actual
+test_expect_success \
+ 'A: verify diff' \
+ 'compare_diff_raw expect actual &&
+ test `git-rev-parse --verify master:file2` \
+ = `git-rev-parse --verify verify--import-marks:copy-of-file2`'
+
###
### series B
###