Skip to content

Commit 1c64e79

Browse files
committed
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>
1 parent 801cfae commit 1c64e79

2 files changed

Lines changed: 19 additions & 4 deletions

File tree

builtin-mktree.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ static const char *mktree_usage[] = {
6767
NULL
6868
};
6969

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)
7171
{
7272
char *ptr, *ntr;
7373
unsigned mode;
@@ -91,10 +91,13 @@ static void mktree_line(char *buf, size_t len, int line_termination)
9191
die("input format error: %s", buf);
9292

9393
/* 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)
9598
type = sha1_object_info(sha1, NULL);
9699
else
97-
type = OBJ_COMMIT;
100+
type = object_type(mode);
98101

99102
if (type < 0)
100103
die("object %s unavailable", sha1_to_hex(sha1));
@@ -118,15 +121,17 @@ int cmd_mktree(int ac, const char **av, const char *prefix)
118121
struct strbuf sb = STRBUF_INIT;
119122
unsigned char sha1[20];
120123
int line_termination = '\n';
124+
int allow_missing = 0;
121125
const struct option option[] = {
122126
OPT_SET_INT('z', NULL, &line_termination, "input is NUL terminated", '\0'),
127+
OPT_SET_INT( 0 , "missing", &allow_missing, "allow missing objects", 1),
123128
OPT_END()
124129
};
125130

126131
ac = parse_options(ac, av, option, mktree_usage, 0);
127132

128133
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);
130135

131136
strbuf_release(&sb);
132137

t/t1010-mktree.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ test_expect_success setup '
1010
mkdir "$d" && echo "$d/one" >"$d/one" &&
1111
git add "$d"
1212
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 &&
1318
echo one >one &&
1419
git add one &&
1520
git write-tree >tree &&
@@ -48,6 +53,11 @@ test_expect_success 'ls-tree output in wrong order given to mktree (2)' '
4853
test_cmp tree.withsub actual
4954
'
5055

56+
test_expect_success 'allow missing object with --missing' '
57+
git mktree --missing <top.missing >actual &&
58+
test_cmp tree.missing actual
59+
'
60+
5161
test_expect_failure 'mktree reads ls-tree -r output (1)' '
5262
git mktree <all >actual &&
5363
test_cmp tree actual

0 commit comments

Comments
 (0)