mktree --missing: allow missing objects
We need to allow input lines that point at objects that we do not have when dealing with submodule entries anyway. This adds an explicit option to allow missing objects of other types, to be consistent with the use of --info-only option to the update-index command and --missing-ok option to the write-tree command. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
May 10, 2009 at 11:30 UTC
1c64e79a622b43cff2d919632393c51f3fcc4f43
2 files changed
+19
-4
builtin-mktree.c
+9
-4
@@ -67,7 +67,7 @@ static const char *mktree_usage[] = {
67
NULL
68
};
69
70
-static void mktree_line(char *buf, size_t len, int line_termination)
70
+static void mktree_line(char *buf, size_t len, int line_termination, int allow_missing)
71
{
72
char *ptr, *ntr;
73
unsigned mode;
@@ -91,10 +91,13 @@ static void mktree_line(char *buf, size_t len, int line_termination)
91
die("input format error: %s", buf);
92
93
/* It is perfectly normal if we do not have a commit from a submodule */
94
- if (!S_ISGITLINK(mode))
94
+ if (S_ISGITLINK(mode))
95
+ allow_missing = 1;
96
+
97
+ if (!allow_missing)
98
type = sha1_object_info(sha1, NULL);
99
else
97
- type = OBJ_COMMIT;
100
+ type = object_type(mode);
101
102
if (type < 0)
103
die("object %s unavailable", sha1_to_hex(sha1));
@@ -118,15 +121,17 @@ int cmd_mktree(int ac, const char **av, const char *prefix)
121
struct strbuf sb = STRBUF_INIT;
122
unsigned char sha1[20];
123
int line_termination = '\n';
124
+ int allow_missing = 0;
125
const struct option option[] = {
126
OPT_SET_INT('z', NULL, &line_termination, "input is NUL terminated", '\0'),
127
+ OPT_SET_INT( 0 , "missing", &allow_missing, "allow missing objects", 1),
128
OPT_END()
129
};
130
131
ac = parse_options(ac, av, option, mktree_usage, 0);
132
133
while (strbuf_getline(&sb, stdin, line_termination) != EOF)
129
- mktree_line(sb.buf, sb.len, line_termination);
134
+ mktree_line(sb.buf, sb.len, line_termination, allow_missing);
135
136
strbuf_release(&sb);
137
t/t1010-mktree.sh
+10
@@ -10,6 +10,11 @@ test_expect_success setup '
10
mkdir "$d" && echo "$d/one" >"$d/one" &&
11
git add "$d"
12
done &&
13
+ echo zero >one &&
14
+ git update-index --add --info-only one &&
15
+ git write-tree --missing-ok >tree.missing &&
16
+ git ls-tree $(cat tree.missing) >top.missing &&
17
+ git ls-tree -r $(cat tree.missing) >all.missing &&
18
echo one >one &&
19
git add one &&
20
git write-tree >tree &&
@@ -48,6 +53,11 @@ test_expect_success 'ls-tree output in wrong order given to mktree (2)' '
53
test_cmp tree.withsub actual
54
'
55
56
+test_expect_success 'allow missing object with --missing' '
57
+ git mktree --missing <top.missing >actual &&
58
+ test_cmp tree.missing actual
59
+'
60
+
61
test_expect_failure 'mktree reads ls-tree -r output (1)' '
62
git mktree <all >actual &&
63
test_cmp tree actual