]> git.ipfire.org Git - thirdparty/git.git/blame - builtin-write-tree.c
Remove archaic use of regex capture \1 in favour of $1
[thirdparty/git.git] / builtin-write-tree.c
CommitLineData
8bc9a0c7
LT
1/*
2 * GIT - The information manager from hell
3 *
4 * Copyright (C) Linus Torvalds, 2005
5 */
8ed05fb5 6#include "builtin.h"
e83c5163 7#include "cache.h"
8e440259 8#include "tree.h"
a52139b4 9#include "cache-tree.h"
e83c5163 10
6bd20358 11static const char write_tree_usage[] =
1b1dd23f 12"git write-tree [--missing-ok] [--prefix=<prefix>/]";
75a46f6b 13
a633fca0 14int cmd_write_tree(int argc, const char **argv, const char *unused_prefix)
8ed05fb5 15{
d11b8d34 16 int flags = 0, ret;
8ed05fb5
LS
17 const char *prefix = NULL;
18 unsigned char sha1[20];
45525bd0 19 const char *me = "git-write-tree";
8ed05fb5 20
ef90d6d4 21 git_config(git_default_config, NULL);
8ed05fb5
LS
22 while (1 < argc) {
23 const char *arg = argv[1];
24 if (!strcmp(arg, "--missing-ok"))
d11b8d34 25 flags |= WRITE_TREE_MISSING_OK;
cc44c765 26 else if (!prefixcmp(arg, "--prefix="))
8ed05fb5 27 prefix = arg + 9;
d11b8d34
JH
28 else if (!prefixcmp(arg, "--ignore-cache-tree"))
29 /*
30 * This is only useful for debugging, so I
31 * do not bother documenting it.
32 */
33 flags |= WRITE_TREE_IGNORE_CACHE_TREE;
8ed05fb5 34 else
8cdf3364 35 usage(write_tree_usage);
8ed05fb5
LS
36 argc--; argv++;
37 }
38
39 if (argc > 2)
40 die("too many options");
41
d11b8d34 42 ret = write_cache_as_tree(sha1, flags, prefix);
45525bd0
JH
43 switch (ret) {
44 case 0:
45 printf("%s\n", sha1_to_hex(sha1));
46 break;
47 case WRITE_TREE_UNREADABLE_INDEX:
48 die("%s: error reading the index", me);
49 break;
50 case WRITE_TREE_UNMERGED_INDEX:
331fcb59 51 die("%s: error building trees", me);
45525bd0
JH
52 break;
53 case WRITE_TREE_PREFIX_ERROR:
54 die("%s: prefix %s not found", me, prefix);
55 break;
56 }
8ed05fb5
LS
57 return ret;
58}