summaryrefslogtreecommitdiff
path: root/builtin-mktree.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2009-05-10 18:30:03 (GMT)
committerJunio C Hamano <gitster@pobox.com>2009-05-11 00:31:01 (GMT)
commit1c64e79a622b43cff2d919632393c51f3fcc4f43 (patch)
treec41997708c590da61789b3ed377933b96a6f4520 /builtin-mktree.c
parent801cfae8fd683761ae268cab8cec08e4b0f5a35b (diff)
downloadgit-1c64e79a622b43cff2d919632393c51f3fcc4f43.zip
git-1c64e79a622b43cff2d919632393c51f3fcc4f43.tar.gz
git-1c64e79a622b43cff2d919632393c51f3fcc4f43.tar.bz2
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>
Diffstat (limited to 'builtin-mktree.c')
-rw-r--r--builtin-mktree.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/builtin-mktree.c b/builtin-mktree.c
index 17cdb3d..e1c9a27 100644
--- a/builtin-mktree.c
+++ b/builtin-mktree.c
@@ -67,7 +67,7 @@ static const char *mktree_usage[] = {
NULL
};
-static void mktree_line(char *buf, size_t len, int line_termination)
+static void mktree_line(char *buf, size_t len, int line_termination, int allow_missing)
{
char *ptr, *ntr;
unsigned mode;
@@ -91,10 +91,13 @@ static void mktree_line(char *buf, size_t len, int line_termination)
die("input format error: %s", buf);
/* It is perfectly normal if we do not have a commit from a submodule */
- if (!S_ISGITLINK(mode))
+ if (S_ISGITLINK(mode))
+ allow_missing = 1;
+
+ if (!allow_missing)
type = sha1_object_info(sha1, NULL);
else
- type = OBJ_COMMIT;
+ type = object_type(mode);
if (type < 0)
die("object %s unavailable", sha1_to_hex(sha1));
@@ -118,15 +121,17 @@ int cmd_mktree(int ac, const char **av, const char *prefix)
struct strbuf sb = STRBUF_INIT;
unsigned char sha1[20];
int line_termination = '\n';
+ int allow_missing = 0;
const struct option option[] = {
OPT_SET_INT('z', NULL, &line_termination, "input is NUL terminated", '\0'),
+ OPT_SET_INT( 0 , "missing", &allow_missing, "allow missing objects", 1),
OPT_END()
};
ac = parse_options(ac, av, option, mktree_usage, 0);
while (strbuf_getline(&sb, stdin, line_termination) != EOF)
- mktree_line(sb.buf, sb.len, line_termination);
+ mktree_line(sb.buf, sb.len, line_termination, allow_missing);
strbuf_release(&sb);