summaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
Diffstat (limited to 'builtin')
-rw-r--r--builtin/add.c1
-rw-r--r--builtin/am.c11
-rw-r--r--builtin/blame.c3
-rw-r--r--builtin/branch.c1
-rw-r--r--builtin/cat-file.c1
-rw-r--r--builtin/check-attr.c1
-rw-r--r--builtin/check-ignore.c1
-rw-r--r--builtin/check-mailmap.c1
-rw-r--r--builtin/checkout-index.c1
-rw-r--r--builtin/checkout.c32
-rw-r--r--builtin/clean.c1
-rw-r--r--builtin/clone.c3
-rw-r--r--builtin/column.c1
-rw-r--r--builtin/commit-tree.c1
-rw-r--r--builtin/commit.c11
-rw-r--r--builtin/config.c27
-rw-r--r--builtin/count-objects.c1
-rw-r--r--builtin/credential.c4
-rw-r--r--builtin/describe.c1
-rw-r--r--builtin/diff-files.c4
-rw-r--r--builtin/diff-index.c4
-rw-r--r--builtin/diff-tree.c28
-rw-r--r--builtin/diff.c9
-rw-r--r--builtin/difftool.c1
-rw-r--r--builtin/fast-export.c13
-rw-r--r--builtin/fetch.c8
-rw-r--r--builtin/fmt-merge-msg.c1
-rw-r--r--builtin/for-each-ref.c1
-rw-r--r--builtin/fsck.c4
-rw-r--r--builtin/gc.c1
-rw-r--r--builtin/grep.c42
-rw-r--r--builtin/hash-object.c1
-rw-r--r--builtin/help.c1
-rw-r--r--builtin/index-pack.c1
-rw-r--r--builtin/init-db.c1
-rw-r--r--builtin/log.c20
-rw-r--r--builtin/ls-files.c179
-rw-r--r--builtin/ls-tree.c1
-rw-r--r--builtin/merge-base.c1
-rw-r--r--builtin/merge-file.c1
-rw-r--r--builtin/merge.c7
-rw-r--r--builtin/mv.c1
-rw-r--r--builtin/name-rev.c1
-rw-r--r--builtin/notes.c137
-rw-r--r--builtin/pack-objects.c1
-rw-r--r--builtin/patch-id.c1
-rw-r--r--builtin/pull.c4
-rw-r--r--builtin/push.c5
-rw-r--r--builtin/read-tree.c33
-rw-r--r--builtin/rebase--helper.c1
-rw-r--r--builtin/receive-pack.c1
-rw-r--r--builtin/reflog.c1
-rw-r--r--builtin/remote-ext.c5
-rw-r--r--builtin/remote-fd.c5
-rw-r--r--builtin/remote.c1
-rw-r--r--builtin/repack.c1
-rw-r--r--builtin/replace.c1
-rw-r--r--builtin/rerere.c1
-rw-r--r--builtin/reset.c40
-rw-r--r--builtin/rev-list.c4
-rw-r--r--builtin/rev-parse.c1
-rw-r--r--builtin/revert.c1
-rw-r--r--builtin/rm.c3
-rw-r--r--builtin/send-pack.c1
-rw-r--r--builtin/shortlog.c1
-rw-r--r--builtin/show-branch.c14
-rw-r--r--builtin/stripspace.c1
-rw-r--r--builtin/submodule--helper.c6
-rw-r--r--builtin/symbolic-ref.c1
-rw-r--r--builtin/tag.c1
-rw-r--r--builtin/unpack-file.c1
-rw-r--r--builtin/unpack-objects.c1
-rw-r--r--builtin/update-index.c3
-rw-r--r--builtin/update-ref.c1
-rw-r--r--builtin/update-server-info.c1
-rw-r--r--builtin/upload-archive.c5
-rw-r--r--builtin/var.c1
-rw-r--r--builtin/verify-commit.c1
-rw-r--r--builtin/verify-pack.c1
-rw-r--r--builtin/verify-tag.c1
-rw-r--r--builtin/worktree.c1
-rw-r--r--builtin/write-tree.c1
82 files changed, 400 insertions, 324 deletions
diff --git a/builtin/add.c b/builtin/add.c
index d7cab1b..e888fb8 100644
--- a/builtin/add.c
+++ b/builtin/add.c
@@ -4,6 +4,7 @@
* Copyright (C) 2006 Linus Torvalds
*/
#include "cache.h"
+#include "config.h"
#include "builtin.h"
#include "lockfile.h"
#include "dir.h"
diff --git a/builtin/am.c b/builtin/am.c
index 5ee146b..7c7b916 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -4,6 +4,7 @@
* Based on git-am.sh by Junio C Hamano.
*/
#include "cache.h"
+#include "config.h"
#include "builtin.h"
#include "exec_cmd.h"
#include "parse-options.h"
@@ -563,7 +564,7 @@ static int copy_notes_for_rebase(const struct am_state *state)
goto finish;
}
- if (copy_note_for_rewrite(c, from_obj.hash, to_obj.hash))
+ if (copy_note_for_rewrite(c, &from_obj, &to_obj))
ret = error(_("Failed to copy notes from '%s' to '%s'"),
oid_to_hex(&from_obj), oid_to_hex(&to_obj));
}
@@ -1275,12 +1276,8 @@ static int parse_mail(struct am_state *state, const char *mail)
die("BUG: invalid value for state->scissors");
}
- mi.input = fopen(mail, "r");
- if (!mi.input)
- die("could not open input");
- mi.output = fopen(am_path(state, "info"), "w");
- if (!mi.output)
- die("could not open output 'info'");
+ mi.input = xfopen(mail, "r");
+ mi.output = xfopen(am_path(state, "info"), "w");
if (mailinfo(&mi, am_path(state, "msg"), am_path(state, "patch")))
die("could not parse patch");
diff --git a/builtin/blame.c b/builtin/blame.c
index d7a2df3..bda1a78 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -6,6 +6,7 @@
*/
#include "cache.h"
+#include "config.h"
#include "builtin.h"
#include "commit.h"
#include "diff.h"
@@ -481,7 +482,7 @@ static void output(struct blame_scoreboard *sb, int option)
*/
static int read_ancestry(const char *graft_file)
{
- FILE *fp = fopen(graft_file, "r");
+ FILE *fp = fopen_or_warn(graft_file, "r");
struct strbuf buf = STRBUF_INIT;
if (!fp)
return -1;
diff --git a/builtin/branch.c b/builtin/branch.c
index 83fcda4..c958e93 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -6,6 +6,7 @@
*/
#include "cache.h"
+#include "config.h"
#include "color.h"
#include "refs.h"
#include "commit.h"
diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index 4bffd7a..7efbc40 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -4,6 +4,7 @@
* Copyright (C) Linus Torvalds, 2005
*/
#include "cache.h"
+#include "config.h"
#include "builtin.h"
#include "diff.h"
#include "parse-options.h"
diff --git a/builtin/check-attr.c b/builtin/check-attr.c
index 4d01ca0..91444dc 100644
--- a/builtin/check-attr.c
+++ b/builtin/check-attr.c
@@ -1,5 +1,6 @@
#include "builtin.h"
#include "cache.h"
+#include "config.h"
#include "attr.h"
#include "quote.h"
#include "parse-options.h"
diff --git a/builtin/check-ignore.c b/builtin/check-ignore.c
index c7b8c08..3e280b9 100644
--- a/builtin/check-ignore.c
+++ b/builtin/check-ignore.c
@@ -1,5 +1,6 @@
#include "builtin.h"
#include "cache.h"
+#include "config.h"
#include "dir.h"
#include "quote.h"
#include "pathspec.h"
diff --git a/builtin/check-mailmap.c b/builtin/check-mailmap.c
index cf0f54f..cdce144 100644
--- a/builtin/check-mailmap.c
+++ b/builtin/check-mailmap.c
@@ -1,4 +1,5 @@
#include "builtin.h"
+#include "config.h"
#include "mailmap.h"
#include "parse-options.h"
#include "string-list.h"
diff --git a/builtin/checkout-index.c b/builtin/checkout-index.c
index 07631d0..39c8be0 100644
--- a/builtin/checkout-index.c
+++ b/builtin/checkout-index.c
@@ -5,6 +5,7 @@
*
*/
#include "builtin.h"
+#include "config.h"
#include "lockfile.h"
#include "quote.h"
#include "cache-tree.h"
diff --git a/builtin/checkout.c b/builtin/checkout.c
index a6b2af3..9661e1b 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -1,4 +1,5 @@
#include "builtin.h"
+#include "config.h"
#include "lockfile.h"
#include "parse-options.h"
#include "refs.h"
@@ -21,31 +22,12 @@
#include "submodule-config.h"
#include "submodule.h"
-static int recurse_submodules = RECURSE_SUBMODULES_DEFAULT;
-
static const char * const checkout_usage[] = {
N_("git checkout [<options>] <branch>"),
N_("git checkout [<options>] [<branch>] -- <file>..."),
NULL,
};
-static int option_parse_recurse_submodules(const struct option *opt,
- const char *arg, int unset)
-{
- if (unset) {
- recurse_submodules = RECURSE_SUBMODULES_OFF;
- return 0;
- }
- if (arg)
- recurse_submodules =
- parse_update_recurse_submodules_arg(opt->long_name,
- arg);
- else
- recurse_submodules = RECURSE_SUBMODULES_ON;
-
- return 0;
-}
-
struct checkout_opts {
int patch_mode;
int quiet;
@@ -876,7 +858,7 @@ static int git_checkout_config(const char *var, const char *value, void *cb)
}
if (starts_with(var, "submodule."))
- return parse_submodule_config_option(var, value);
+ return submodule_config(var, value, NULL);
return git_xmerge_config(var, value, NULL);
}
@@ -1184,9 +1166,9 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
N_("second guess 'git checkout <no-such-branch>'")),
OPT_BOOL(0, "ignore-other-worktrees", &opts.ignore_other_worktrees,
N_("do not check if another worktree is holding the given ref")),
- { OPTION_CALLBACK, 0, "recurse-submodules", &recurse_submodules,
+ { OPTION_CALLBACK, 0, "recurse-submodules", NULL,
"checkout", "control recursive updating of submodules",
- PARSE_OPT_OPTARG, option_parse_recurse_submodules },
+ PARSE_OPT_OPTARG, option_parse_recurse_submodules_worktree_updater },
OPT_BOOL(0, "progress", &opts.show_progress, N_("force progress reporting")),
OPT_END(),
};
@@ -1217,12 +1199,6 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
git_xmerge_config("merge.conflictstyle", conflict_style, NULL);
}
- if (recurse_submodules != RECURSE_SUBMODULES_OFF) {
- git_config(submodule_config, NULL);
- if (recurse_submodules != RECURSE_SUBMODULES_DEFAULT)
- set_config_update_recurse_submodules(recurse_submodules);
- }
-
if ((!!opts.new_branch + !!opts.new_branch_force + !!opts.new_orphan_branch) > 1)
die(_("-b, -B and --orphan are mutually exclusive"));
diff --git a/builtin/clean.c b/builtin/clean.c
index 142bf66..ed95413 100644
--- a/builtin/clean.c
+++ b/builtin/clean.c
@@ -8,6 +8,7 @@
#include "builtin.h"
#include "cache.h"
+#include "config.h"
#include "dir.h"
#include "parse-options.h"
#include "string-list.h"
diff --git a/builtin/clone.c b/builtin/clone.c
index 743f16a..08b5cc4 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -9,6 +9,7 @@
*/
#include "builtin.h"
+#include "config.h"
#include "lockfile.h"
#include "parse-options.h"
#include "fetch-pack.h"
@@ -360,7 +361,7 @@ static void copy_alternates(struct strbuf *src, struct strbuf *dst,
* to turn entries with paths relative to the original
* absolute, so that they can be used in the new repository.
*/
- FILE *in = fopen(src->buf, "r");
+ FILE *in = xfopen(src->buf, "r");
struct strbuf line = STRBUF_INIT;
while (strbuf_getline(&line, in) != EOF) {
diff --git a/builtin/column.c b/builtin/column.c
index 33314b4..0c3223d 100644
--- a/builtin/column.c
+++ b/builtin/column.c
@@ -1,5 +1,6 @@
#include "builtin.h"
#include "cache.h"
+#include "config.h"
#include "strbuf.h"
#include "parse-options.h"
#include "string-list.h"
diff --git a/builtin/commit-tree.c b/builtin/commit-tree.c
index f39c2b2..a4a923d 100644
--- a/builtin/commit-tree.c
+++ b/builtin/commit-tree.c
@@ -4,6 +4,7 @@
* Copyright (C) Linus Torvalds, 2005
*/
#include "cache.h"
+#include "config.h"
#include "commit.h"
#include "tree.h"
#include "builtin.h"
diff --git a/builtin/commit.c b/builtin/commit.c
index da1ba4c..021070e 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -6,6 +6,7 @@
*/
#include "cache.h"
+#include "config.h"
#include "lockfile.h"
#include "cache-tree.h"
#include "color.h"
@@ -253,7 +254,8 @@ static int list_paths(struct string_list *list, const char *with_tree,
if (with_tree) {
char *max_prefix = common_prefix(pattern);
- overlay_tree_on_cache(with_tree, max_prefix ? max_prefix : prefix);
+ overlay_tree_on_index(&the_index, with_tree,
+ max_prefix ? max_prefix : prefix);
free(max_prefix);
}
@@ -1699,10 +1701,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
if (!reflog_msg)
reflog_msg = "commit (merge)";
pptr = commit_list_append(current_head, pptr);
- fp = fopen(git_path_merge_head(), "r");
- if (fp == NULL)
- die_errno(_("could not open '%s' for reading"),
- git_path_merge_head());
+ fp = xfopen(git_path_merge_head(), "r");
while (strbuf_getline_lf(&m, fp) != EOF) {
struct commit *parent;
@@ -1809,7 +1808,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
cfg = init_copy_notes_for_rewrite("amend");
if (cfg) {
/* we are amending, so current_head is not NULL */
- copy_note_for_rewrite(cfg, current_head->object.oid.hash, oid.hash);
+ copy_note_for_rewrite(cfg, &current_head->object.oid, &oid);
finish_copy_notes_for_rewrite(cfg, "Notes added by 'git commit --amend'");
}
run_rewrite_hook(&current_head->object.oid, &oid);
diff --git a/builtin/config.c b/builtin/config.c
index 7f6c25d..82db29f 100644
--- a/builtin/config.c
+++ b/builtin/config.c
@@ -1,5 +1,6 @@
#include "builtin.h"
#include "cache.h"
+#include "config.h"
#include "color.h"
#include "parse-options.h"
#include "urlmatch.h"
@@ -242,8 +243,8 @@ static int get_value(const char *key_, const char *regex_)
}
}
- git_config_with_options(collect_config, &values,
- &given_config_source, &config_options);
+ config_with_options(collect_config, &values,
+ &given_config_source, &config_options);
ret = !values.nr;
@@ -320,8 +321,8 @@ static void get_color(const char *var, const char *def_color)
get_color_slot = var;
get_color_found = 0;
parsed_color[0] = '\0';
- git_config_with_options(git_get_color_config, NULL,
- &given_config_source, &config_options);
+ config_with_options(git_get_color_config, NULL,
+ &given_config_source, &config_options);
if (!get_color_found && def_color) {
if (color_parse(def_color, parsed_color) < 0)
@@ -352,8 +353,8 @@ static int get_colorbool(const char *var, int print)
get_colorbool_found = -1;
get_diff_color_found = -1;
get_color_ui_found = -1;
- git_config_with_options(git_get_colorbool_config, NULL,
- &given_config_source, &config_options);
+ config_with_options(git_get_colorbool_config, NULL,
+ &given_config_source, &config_options);
if (get_colorbool_found < 0) {
if (!strcmp(get_colorbool_slot, "color.diff"))
@@ -441,8 +442,8 @@ static int get_urlmatch(const char *var, const char *url)
show_keys = 1;
}
- git_config_with_options(urlmatch_config_entry, &config,
- &given_config_source, &config_options);
+ config_with_options(urlmatch_config_entry, &config,
+ &given_config_source, &config_options);
ret = !values.nr;
@@ -538,6 +539,10 @@ int cmd_config(int argc, const char **argv, const char *prefix)
config_options.respect_includes = !given_config_source.file;
else
config_options.respect_includes = respect_includes_opt;
+ if (!nongit) {
+ config_options.commondir = get_git_common_dir();
+ config_options.git_dir = get_git_dir();
+ }
if (end_null) {
term = '\0';
@@ -582,9 +587,9 @@ int cmd_config(int argc, const char **argv, const char *prefix)
if (actions == ACTION_LIST) {
check_argc(argc, 0, 0);
- if (git_config_with_options(show_all_config, NULL,
- &given_config_source,
- &config_options) < 0) {
+ if (config_with_options(show_all_config, NULL,
+ &given_config_source,
+ &config_options) < 0) {
if (given_config_source.file)
die_errno("unable to read config file '%s'",
given_config_source.file);
diff --git a/builtin/count-objects.c b/builtin/count-objects.c
index acb0594..1d82e61 100644
--- a/builtin/count-objects.c
+++ b/builtin/count-objects.c
@@ -5,6 +5,7 @@
*/
#include "cache.h"
+#include "config.h"
#include "dir.h"
#include "builtin.h"
#include "parse-options.h"
diff --git a/builtin/credential.c b/builtin/credential.c
index 0412fa0..879acfb 100644
--- a/builtin/credential.c
+++ b/builtin/credential.c
@@ -10,9 +10,9 @@ int cmd_credential(int argc, const char **argv, const char *prefix)
const char *op;
struct credential c = CREDENTIAL_INIT;
- op = argv[1];
- if (!op)
+ if (argc != 2 || !strcmp(argv[1], "-h"))
usage(usage_msg);
+ op = argv[1];
if (credential_read(&c, stdin) < 0)
die("unable to read credential from stdin");
diff --git a/builtin/describe.c b/builtin/describe.c
index 893c878..70eb144 100644
--- a/builtin/describe.c
+++ b/builtin/describe.c
@@ -1,4 +1,5 @@
#include "cache.h"
+#include "config.h"
#include "lockfile.h"
#include "commit.h"
#include "tag.h"
diff --git a/builtin/diff-files.c b/builtin/diff-files.c
index a572da9..17bf84d 100644
--- a/builtin/diff-files.c
+++ b/builtin/diff-files.c
@@ -4,6 +4,7 @@
* Copyright (C) Linus Torvalds, 2005
*/
#include "cache.h"
+#include "config.h"
#include "diff.h"
#include "commit.h"
#include "revision.h"
@@ -20,6 +21,9 @@ int cmd_diff_files(int argc, const char **argv, const char *prefix)
int result;
unsigned options = 0;
+ if (argc == 2 && !strcmp(argv[1], "-h"))
+ usage(diff_files_usage);
+
git_config(git_diff_basic_config, NULL); /* no "diff" UI options */
init_revisions(&rev, prefix);
gitmodules_config();
diff --git a/builtin/diff-index.c b/builtin/diff-index.c
index f084826..185e6f9 100644
--- a/builtin/diff-index.c
+++ b/builtin/diff-index.c
@@ -1,4 +1,5 @@
#include "cache.h"
+#include "config.h"
#include "diff.h"
#include "commit.h"
#include "revision.h"
@@ -17,6 +18,9 @@ int cmd_diff_index(int argc, const char **argv, const char *prefix)
int i;
int result;
+ if (argc == 2 && !strcmp(argv[1], "-h"))
+ usage(diff_cache_usage);
+
git_config(git_diff_basic_config, NULL); /* no "diff" UI options */
init_revisions(&rev, prefix);
gitmodules_config();
diff --git a/builtin/diff-tree.c b/builtin/diff-tree.c
index e401112..31d2cb4 100644
--- a/builtin/diff-tree.c
+++ b/builtin/diff-tree.c
@@ -1,4 +1,5 @@
#include "cache.h"
+#include "config.h"
#include "diff.h"
#include "commit.h"
#include "log-tree.h"
@@ -7,7 +8,7 @@
static struct rev_info log_tree_opt;
-static int diff_tree_commit_sha1(const struct object_id *oid)
+static int diff_tree_commit_oid(const struct object_id *oid)
{
struct commit *commit = lookup_commit_reference(oid);
if (!commit)
@@ -49,8 +50,8 @@ static int stdin_diff_trees(struct tree *tree1, const char *p)
return -1;
printf("%s %s\n", oid_to_hex(&tree1->object.oid),
oid_to_hex(&tree2->object.oid));
- diff_tree_sha1(tree1->object.oid.hash, tree2->object.oid.hash,
- "", &log_tree_opt.diffopt);
+ diff_tree_oid(&tree1->object.oid, &tree2->object.oid,
+ "", &log_tree_opt.diffopt);
log_tree_diff_flush(&log_tree_opt);
return 0;
}
@@ -98,13 +99,15 @@ static void diff_tree_tweak_rev(struct rev_info *rev, struct setup_revision_opt
int cmd_diff_tree(int argc, const char **argv, const char *prefix)
{
- int nr_sha1;
char line[1000];
struct object *tree1, *tree2;
static struct rev_info *opt = &log_tree_opt;
struct setup_revision_opt s_r_opt;
int read_stdin = 0;
+ if (argc == 2 && !strcmp(argv[1], "-h"))
+ usage(diff_tree_usage);
+
git_config(git_diff_basic_config, NULL); /* no "diff" UI options */
init_revisions(opt, prefix);
gitmodules_config();
@@ -128,19 +131,20 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix)
}
/*
- * NOTE! We expect "a ^b" to be equal to "a..b", so we
- * reverse the order of the objects if the second one
- * is marked UNINTERESTING.
+ * NOTE! We expect "a..b" to expand to "^a b" but it is
+ * perfectly valid for revision range parser to yield "b ^a",
+ * which means the same thing. If we get the latter, i.e. the
+ * second one is marked UNINTERESTING, we recover the original
+ * order the user gave, i.e. "a..b", by swapping the trees.
*/
- nr_sha1 = opt->pending.nr;
- switch (nr_sha1) {
+ switch (opt->pending.nr) {
case 0:
if (!read_stdin)
usage(diff_tree_usage);
break;
case 1:
tree1 = opt->pending.objects[0].item;
- diff_tree_commit_sha1(&tree1->oid);
+ diff_tree_commit_oid(&tree1->oid);
break;
case 2:
tree1 = opt->pending.objects[0].item;
@@ -148,9 +152,7 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix)
if (tree2->flags & UNINTERESTING) {
SWAP(tree2, tree1);
}
- diff_tree_sha1(tree1->oid.hash,
- tree2->oid.hash,
- "", &opt->diffopt);
+ diff_tree_oid(&tree1->oid, &tree2->oid, "", &opt->diffopt);
log_tree_diff_flush(opt);
break;
}
diff --git a/builtin/diff.c b/builtin/diff.c
index 0c8f86e..7cde6ab 100644
--- a/builtin/diff.c
+++ b/builtin/diff.c
@@ -4,6 +4,7 @@
* Copyright (c) 2006 Junio C Hamano
*/
#include "cache.h"
+#include "config.h"
#include "lockfile.h"
#include "color.h"
#include "commit.h"
@@ -56,8 +57,8 @@ static void stuff_change(struct diff_options *opt,
one = alloc_filespec(old_path);
two = alloc_filespec(new_path);
- fill_filespec(one, old_oid->hash, old_oid_valid, old_mode);
- fill_filespec(two, new_oid->hash, new_oid_valid, new_mode);
+ fill_filespec(one, old_oid, old_oid_valid, old_mode);
+ fill_filespec(two, new_oid, new_oid_valid, new_mode);
diff_queue(&diff_queued_diff, one, two);
}
@@ -174,7 +175,7 @@ static int builtin_diff_tree(struct rev_info *revs,
swap = 1;
oid[swap] = &ent0->item->oid;
oid[1 - swap] = &ent1->item->oid;
- diff_tree_sha1(oid[0]->hash, oid[1]->hash, "", &revs->diffopt);
+ diff_tree_oid(oid[0], oid[1], "", &revs->diffopt);
log_tree_diff_flush(revs);
return 0;
}
@@ -194,7 +195,7 @@ static int builtin_diff_combined(struct rev_info *revs,
revs->dense_combined_merges = revs->combine_merges = 1;
for (i = 1; i < ents; i++)
oid_array_append(&parents, &ent[i].item->oid);
- diff_tree_combined(ent[0].item->oid.hash, &parents,
+ diff_tree_combined(&ent[0].item->oid, &parents,
revs->dense_combined_merges, revs);
oid_array_clear(&parents);
return 0;
diff --git a/builtin/difftool.c b/builtin/difftool.c
index b9a892f..9199227 100644
--- a/builtin/difftool.c
+++ b/builtin/difftool.c
@@ -12,6 +12,7 @@
* Copyright (C) 2016 Johannes Schindelin
*/
#include "cache.h"
+#include "config.h"
#include "builtin.h"
#include "run-command.h"
#include "exec_cmd.h"
diff --git a/builtin/fast-export.c b/builtin/fast-export.c
index 24e29ad..12d501b 100644
--- a/builtin/fast-export.c
+++ b/builtin/fast-export.c
@@ -5,6 +5,7 @@
*/
#include "builtin.h"
#include "cache.h"
+#include "config.h"
#include "refs.h"
#include "commit.h"
#include "object.h"
@@ -562,12 +563,12 @@ static void handle_commit(struct commit *commit, struct rev_info *rev)
get_object_mark(&commit->parents->item->object) != 0 &&
!full_tree) {
parse_commit_or_die(commit->parents->item);
- diff_tree_sha1(commit->parents->item->tree->object.oid.hash,
- commit->tree->object.oid.hash, "", &rev->diffopt);
+ diff_tree_oid(&commit->parents->item->tree->object.oid,
+ &commit->tree->object.oid, "", &rev->diffopt);
}
else
- diff_root_tree_sha1(commit->tree->object.oid.hash,
- "", &rev->diffopt);
+ diff_root_tree_oid(&commit->tree->object.oid,
+ "", &rev->diffopt);
/* Export the referenced blobs, and remember the marks. */
for (i = 0; i < diff_queued_diff.nr; i++)
@@ -907,9 +908,7 @@ static void export_marks(char *file)
static void import_marks(char *input_file)
{
char line[512];
- FILE *f = fopen(input_file, "r");
- if (!f)
- die_errno("cannot read '%s'", input_file);
+ FILE *f = xfopen(input_file, "r");
while (fgets(line, sizeof(line), f)) {
uint32_t mark;
diff --git a/builtin/fetch.c b/builtin/fetch.c
index 4770845..16cf842 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -2,6 +2,7 @@
* "git fetch"
*/
#include "cache.h"
+#include "config.h"
#include "refs.h"
#include "commit.h"
#include "builtin.h"
@@ -73,6 +74,13 @@ static int git_fetch_config(const char *k, const char *v, void *cb)
fetch_prune_config = git_config_bool(k, v);
return 0;
}
+
+ if (!strcmp(k, "submodule.recurse")) {
+ int r = git_config_bool(k, v) ?
+ RECURSE_SUBMODULES_ON : RECURSE_SUBMODULES_OFF;
+ recurse_submodules = r;
+ }
+
return git_default_config(k, v, cb);
}
diff --git a/builtin/fmt-merge-msg.c b/builtin/fmt-merge-msg.c
index 70137b0..10cbb43 100644
--- a/builtin/fmt-merge-msg.c
+++ b/builtin/fmt-merge-msg.c
@@ -1,5 +1,6 @@
#include "builtin.h"
#include "cache.h"
+#include "config.h"
#include "refs.h"
#include "commit.h"
#include "diff.h"
diff --git a/builtin/for-each-ref.c b/builtin/for-each-ref.c
index eca365b..52be99c 100644
--- a/builtin/for-each-ref.c
+++ b/builtin/for-each-ref.c
@@ -1,5 +1,6 @@
#include "builtin.h"
#include "cache.h"
+#include "config.h"
#include "refs.h"
#include "object.h"
#include "parse-options.h"
diff --git a/builtin/fsck.c b/builtin/fsck.c
index cb2ba6c..87c6756 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -1,5 +1,6 @@
#include "builtin.h"
#include "cache.h"
+#include "config.h"
#include "commit.h"
#include "tree.h"
#include "blob.h"
@@ -280,8 +281,7 @@ static void check_unreachable_object(struct object *obj)
free(filename);
return;
}
- if (!(f = fopen(filename, "w")))
- die_errno("Could not open '%s'", filename);
+ f = xfopen(filename, "w");
if (obj->type == OBJ_BLOB) {
if (stream_blob_to_fd(fileno(f), &obj->oid, NULL, 1))
die_errno("Could not write '%s'", filename);
diff --git a/builtin/gc.c b/builtin/gc.c
index f484eda..bd91f13 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -11,6 +11,7 @@
*/
#include "builtin.h"
+#include "config.h"
#include "tempfile.h"
#include "lockfile.h"
#include "parse-options.h"
diff --git a/builtin/grep.c b/builtin/grep.c
index 7df9c25..f61a9d9 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -4,6 +4,7 @@
* Copyright (c) 2006 Junio C Hamano
*/
#include "cache.h"
+#include "config.h"
#include "blob.h"
#include "tree.h"
#include "commit.h"
@@ -224,7 +225,8 @@ static void start_threads(struct grep_opt *opt)
int err;
struct grep_opt *o = grep_opt_dup(opt);
o->output = strbuf_out;
- o->debug = 0;
+ if (i)
+ o->debug = 0;
compile_grep_patterns(o);
err = pthread_create(&threads[i], NULL, run, o);
@@ -302,6 +304,9 @@ static int grep_cmd_config(const char *var, const char *value, void *cb)
#endif
}
+ if (!strcmp(var, "submodule.recurse"))
+ recurse_submodules = git_config_bool(var, value);
+
return st;
}
@@ -338,7 +343,7 @@ static int grep_oid(struct grep_opt *opt, const struct object_id *oid,
#ifndef NO_PTHREADS
if (num_threads) {
- add_work(opt, GREP_SOURCE_SHA1, pathbuf.buf, path, oid);
+ add_work(opt, GREP_SOURCE_OID, pathbuf.buf, path, oid);
strbuf_release(&pathbuf);
return 0;
} else
@@ -347,7 +352,7 @@ static int grep_oid(struct grep_opt *opt, const struct object_id *oid,
struct grep_source gs;
int hit;
- grep_source_init(&gs, GREP_SOURCE_SHA1, pathbuf.buf, path, oid);
+ grep_source_init(&gs, GREP_SOURCE_OID, pathbuf.buf, path, oid);
strbuf_release(&pathbuf);
hit = grep_source(opt, &gs);
@@ -583,7 +588,7 @@ static int grep_submodule_launch(struct grep_opt *opt,
* with the object's name: 'tree-name:filename'. In order to
* provide uniformity of output we want to pass the name of the
* parent project's object name to the submodule so the submodule can
- * prefix its output with the parent's name and not its own SHA1.
+ * prefix its output with the parent's name and not its own OID.
*/
if (gs->identifier && end_of_base)
argv_array_pushf(&cp.args, "--parent-basename=%.*s",
@@ -596,12 +601,12 @@ static int grep_submodule_launch(struct grep_opt *opt,
* If there is a tree identifier for the submodule, add the
* rev after adding the submodule options but before the
* pathspecs. To do this we listen for the '--' and insert the
- * sha1 before pushing the '--' onto the child process argv
+ * oid before pushing the '--' onto the child process argv
* array.
*/
if (gs->identifier &&
!strcmp("--", submodule_options.argv[i])) {
- argv_array_push(&cp.args, sha1_to_hex(gs->identifier));
+ argv_array_push(&cp.args, oid_to_hex(gs->identifier));
}
argv_array_push(&cp.args, submodule_options.argv[i]);
@@ -631,11 +636,11 @@ static int grep_submodule_launch(struct grep_opt *opt,
/*
* Prep grep structures for a submodule grep
- * sha1: the sha1 of the submodule or NULL if using the working tree
+ * oid: the oid of the submodule or NULL if using the working tree
* filename: name of the submodule including tree name of parent
* path: location of the submodule
*/
-static int grep_submodule(struct grep_opt *opt, const unsigned char *sha1,
+static int grep_submodule(struct grep_opt *opt, const struct object_id *oid,
const char *filename, const char *path)
{
if (!is_submodule_initialized(path))
@@ -645,7 +650,7 @@ static int grep_submodule(struct grep_opt *opt, const unsigned char *sha1,
* If searching history, check for the presense of the
* submodule's gitdir before skipping the submodule.
*/
- if (sha1) {
+ if (oid) {
const struct submodule *sub =
submodule_from_path(null_sha1, path);
if (sub)
@@ -660,7 +665,7 @@ static int grep_submodule(struct grep_opt *opt, const unsigned char *sha1,
#ifndef NO_PTHREADS
if (num_threads) {
- add_work(opt, GREP_SOURCE_SUBMODULE, filename, path, sha1);
+ add_work(opt, GREP_SOURCE_SUBMODULE, filename, path, oid);
return 0;
} else
#endif
@@ -669,7 +674,7 @@ static int grep_submodule(struct grep_opt *opt, const unsigned char *sha1,
int hit;
grep_source_init(&gs, GREP_SOURCE_SUBMODULE,
- filename, path, sha1);
+ filename, path, oid);
hit = grep_submodule_launch(opt, &gs);
grep_source_clear(&gs);
@@ -788,7 +793,7 @@ static int grep_tree(struct grep_opt *opt, const struct pathspec *pathspec,
check_attr);
free(data);
} else if (recurse_submodules && S_ISGITLINK(entry.mode)) {
- hit |= grep_submodule(opt, entry.oid->hash, base->buf,
+ hit |= grep_submodule(opt, entry.oid, base->buf,
base->buf + tn_len);
}
@@ -1167,8 +1172,6 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
if (!opt.fixed && opt.ignore_case)
opt.regflags |= REG_ICASE;
- compile_grep_patterns(&opt);
-
/*
* We have to find "--" in a separate pass, because its presence
* influences how we will parse arguments that come before it.
@@ -1241,12 +1244,23 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
num_threads = GREP_NUM_THREADS_DEFAULT;
else if (num_threads < 0)
die(_("invalid number of threads specified (%d)"), num_threads);
+ if (num_threads == 1)
+ num_threads = 0;
#else
if (num_threads)
warning(_("no threads support, ignoring --threads"));
num_threads = 0;
#endif
+ if (!num_threads)
+ /*
+ * The compiled patterns on the main path are only
+ * used when not using threading. Otherwise
+ * start_threads() below calls compile_grep_patterns()
+ * for each thread.
+ */
+ compile_grep_patterns(&opt);
+
#ifndef NO_PTHREADS
if (num_threads) {
if (!(opt.name_only || opt.unmatch_name_only || opt.count)
diff --git a/builtin/hash-object.c b/builtin/hash-object.c
index bbeaf20..d04baf9 100644
--- a/builtin/hash-object.c
+++ b/builtin/hash-object.c
@@ -5,6 +5,7 @@
* Copyright (C) Junio C Hamano, 2005
*/
#include "builtin.h"
+#include "config.h"
#include "blob.h"
#include "quote.h"
#include "parse-options.h"
diff --git a/builtin/help.c b/builtin/help.c
index 49f7a07..334a849 100644
--- a/builtin/help.c
+++ b/builtin/help.c
@@ -2,6 +2,7 @@
* Builtin help command
*/
#include "cache.h"
+#include "config.h"
#include "builtin.h"
#include "exec_cmd.h"
#include "parse-options.h"
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index 04b9dca..edc1a91 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -1,4 +1,5 @@
#include "builtin.h"
+#include "config.h"
#include "delta.h"
#include "pack.h"
#include "csum-file.h"
diff --git a/builtin/init-db.c b/builtin/init-db.c
index 8a6acb0..47823f9 100644
--- a/builtin/init-db.c
+++ b/builtin/init-db.c
@@ -4,6 +4,7 @@
* Copyright (C) Linus Torvalds, 2005
*/
#include "cache.h"
+#include "config.h"
#include "refs.h"
#include "builtin.h"
#include "exec_cmd.h"
diff --git a/builtin/log.c b/builtin/log.c
index e89ec94..8ca1de9 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -5,6 +5,7 @@
* 2006 Junio Hamano
*/
#include "cache.h"
+#include "config.h"
#include "refs.h"
#include "color.h"
#include "commit.h"
@@ -846,8 +847,10 @@ static int open_next_file(struct commit *commit, const char *subject,
if (output_directory) {
strbuf_addstr(&filename, output_directory);
if (filename.len >=
- PATH_MAX - FORMAT_PATCH_NAME_MAX - suffix_len)
+ PATH_MAX - FORMAT_PATCH_NAME_MAX - suffix_len) {
+ strbuf_release(&filename);
return error(_("name of output directory is too long"));
+ }
strbuf_complete(&filename, '/');
}
@@ -861,8 +864,11 @@ static int open_next_file(struct commit *commit, const char *subject,
if (!quiet)
printf("%s\n", filename.buf + outdir_offset);
- if ((rev->diffopt.file = fopen(filename.buf, "w")) == NULL)
- return error(_("Cannot open patch file %s"), filename.buf);
+ if ((rev->diffopt.file = fopen(filename.buf, "w")) == NULL) {
+ error_errno(_("Cannot open patch file %s"), filename.buf);
+ strbuf_release(&filename);
+ return -1;
+ }
strbuf_release(&filename);
return 0;
@@ -1047,9 +1053,9 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout,
diff_setup_done(&opts);
- diff_tree_sha1(origin->tree->object.oid.hash,
- head->tree->object.oid.hash,
- "", &opts);
+ diff_tree_oid(&origin->tree->object.oid,
+ &head->tree->object.oid,
+ "", &opts);
diffcore_std(&opts);
diff_flush(&opts);
@@ -1358,7 +1364,7 @@ static void prepare_bases(struct base_tree_info *bases,
struct object_id *patch_id;
if (commit->util)
continue;
- if (commit_patch_id(commit, &diffopt, oid.hash, 0))
+ if (commit_patch_id(commit, &diffopt, &oid, 0))
die(_("cannot get patch id"));
ALLOC_GROW(bases->patch_id, bases->nr_patch_id + 1, bases->alloc_patch_id);
patch_id = bases->patch_id + bases->nr_patch_id;
diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index b376afc..b12d0bb 100644
--- a/builtin/ls-files.c
+++ b/builtin/ls-files.c
@@ -6,6 +6,7 @@
* Copyright (C) Linus Torvalds, 2005
*/
#include "cache.h"
+#include "config.h"
#include "quote.h"
#include "dir.h"
#include "builtin.h"
@@ -53,17 +54,17 @@ static const char *tag_modified = "";
static const char *tag_skip_worktree = "";
static const char *tag_resolve_undo = "";
-static void write_eolinfo(const struct cache_entry *ce, const char *path)
+static void write_eolinfo(const struct index_state *istate,
+ const struct cache_entry *ce, const char *path)
{
- if (!show_eol)
- return;
- else {
+ if (show_eol) {
struct stat st;
const char *i_txt = "";
const char *w_txt = "";
const char *a_txt = get_convert_attr_ascii(path);
if (ce && S_ISREG(ce->ce_mode))
- i_txt = get_cached_convert_stats_ascii(ce->name);
+ i_txt = get_cached_convert_stats_ascii(istate,
+ ce->name);
if (!lstat(path, &st) && S_ISREG(st.st_mode))
w_txt = get_wt_convert_stats_ascii(path);
printf("i/%-5s w/%-5s attr/%-17s\t", i_txt, w_txt, a_txt);
@@ -93,6 +94,43 @@ static void write_name(const char *name)
strbuf_release(&full_name);
}
+static const char *get_tag(const struct cache_entry *ce, const char *tag)
+{
+ static char alttag[4];
+
+ if (tag && *tag && show_valid_bit && (ce->ce_flags & CE_VALID)) {
+ memcpy(alttag, tag, 3);
+
+ if (isalpha(tag[0])) {
+ alttag[0] = tolower(tag[0]);
+ } else if (tag[0] == '?') {
+ alttag[0] = '!';
+ } else {
+ alttag[0] = 'v';
+ alttag[1] = tag[0];
+ alttag[2] = ' ';
+ alttag[3] = 0;
+ }
+
+ tag = alttag;
+ }
+
+ return tag;
+}
+
+static void print_debug(const struct cache_entry *ce)
+{
+ if (debug_mode) {
+ const struct stat_data *sd = &ce->ce_stat_data;
+
+ printf(" ctime: %d:%d\n", sd->sd_ctime.sec, sd->sd_ctime.nsec);
+ printf(" mtime: %d:%d\n", sd->sd_mtime.sec, sd->sd_mtime.nsec);
+ printf(" dev: %d\tino: %d\n", sd->sd_dev, sd->sd_ino);
+ printf(" uid: %d\tgid: %d\n", sd->sd_uid, sd->sd_gid);
+ printf(" size: %d\tflags: %x\n", sd->sd_size, ce->ce_flags);
+ }
+}
+
static void show_dir_entry(const char *tag, struct dir_entry *ent)
{
int len = max_prefix_len;
@@ -104,23 +142,25 @@ static void show_dir_entry(const char *tag, struct dir_entry *ent)
return;
fputs(tag, stdout);
- write_eolinfo(NULL, ent->name);
+ write_eolinfo(NULL, NULL, ent->name);
write_name(ent->name);
}
-static void show_other_files(struct dir_struct *dir)
+static void show_other_files(const struct index_state *istate,
+ const struct dir_struct *dir)
{
int i;
for (i = 0; i < dir->nr; i++) {
struct dir_entry *ent = dir->entries[i];
- if (!cache_name_is_other(ent->name, ent->len))
+ if (!index_name_is_other(istate, ent->name, ent->len))
continue;
show_dir_entry(tag_other, ent);
}
}
-static void show_killed_files(struct dir_struct *dir)
+static void show_killed_files(const struct index_state *istate,
+ const struct dir_struct *dir)
{
int i;
for (i = 0; i < dir->nr; i++) {
@@ -134,29 +174,29 @@ static void show_killed_files(struct dir_struct *dir)
/* If ent->name is prefix of an entry in the
* cache, it will be killed.
*/
- pos = cache_name_pos(ent->name, ent->len);
+ pos = index_name_pos(istate, ent->name, ent->len);
if (0 <= pos)
die("BUG: killed-file %.*s not found",
ent->len, ent->name);
pos = -pos - 1;
- while (pos < active_nr &&
- ce_stage(active_cache[pos]))
+ while (pos < istate->cache_nr &&
+ ce_stage(istate->cache[pos]))
pos++; /* skip unmerged */
- if (active_nr <= pos)
+ if (istate->cache_nr <= pos)
break;
/* pos points at a name immediately after
* ent->name in the cache. Does it expect
* ent->name to be a directory?
*/
- len = ce_namelen(active_cache[pos]);
+ len = ce_namelen(istate->cache[pos]);
if ((ent->len < len) &&
- !strncmp(active_cache[pos]->name,
+ !strncmp(istate->cache[pos]->name,
ent->name, ent->len) &&
- active_cache[pos]->name[ent->len] == '/')
+ istate->cache[pos]->name[ent->len] == '/')
killed = 1;
break;
}
- if (0 <= cache_name_pos(ent->name, sp - ent->name)) {
+ if (0 <= index_name_pos(istate, ent->name, sp - ent->name)) {
/* If any of the leading directories in
* ent->name is registered in the cache,
* ent->name will be killed.
@@ -230,7 +270,8 @@ static void show_gitlink(const struct cache_entry *ce)
exit(status);
}
-static void show_ce_entry(const char *tag, const struct cache_entry *ce)
+static void show_ce_entry(const struct index_state *istate,
+ const char *tag, const struct cache_entry *ce)
{
struct strbuf name = STRBUF_INIT;
int len = max_prefix_len;
@@ -248,22 +289,7 @@ static void show_ce_entry(const char *tag, const struct cache_entry *ce)
len, ps_matched,
S_ISDIR(ce->ce_mode) ||
S_ISGITLINK(ce->ce_mode))) {
- if (tag && *tag && show_valid_bit &&
- (ce->ce_flags & CE_VALID)) {
- static char alttag[4];
- memcpy(alttag, tag, 3);
- if (isalpha(tag[0]))
- alttag[0] = tolower(tag[0]);
- else if (tag[0] == '?')
- alttag[0] = '!';
- else {
- alttag[0] = 'v';
- alttag[1] = tag[0];
- alttag[2] = ' ';
- alttag[3] = 0;
- }
- tag = alttag;
- }
+ tag = get_tag(ce, tag);
if (!show_stage) {
fputs(tag, stdout);
@@ -274,30 +300,22 @@ static void show_ce_entry(const char *tag, const struct cache_entry *ce)
find_unique_abbrev(ce->oid.hash, abbrev),
ce_stage(ce));
}
- write_eolinfo(ce, ce->name);
+ write_eolinfo(istate, ce, ce->name);
write_name(ce->name);
- if (debug_mode) {
- const struct stat_data *sd = &ce->ce_stat_data;
-
- printf(" ctime: %d:%d\n", sd->sd_ctime.sec, sd->sd_ctime.nsec);
- printf(" mtime: %d:%d\n", sd->sd_mtime.sec, sd->sd_mtime.nsec);
- printf(" dev: %d\tino: %d\n", sd->sd_dev, sd->sd_ino);
- printf(" uid: %d\tgid: %d\n", sd->sd_uid, sd->sd_gid);
- printf(" size: %d\tflags: %x\n", sd->sd_size, ce->ce_flags);
- }
+ print_debug(ce);
}
strbuf_release(&name);
}
-static void show_ru_info(void)
+static void show_ru_info(const struct index_state *istate)
{
struct string_list_item *item;
- if (!the_index.resolve_undo)
+ if (!istate->resolve_undo)
return;
- for_each_string_list_item(item, the_index.resolve_undo) {
+ for_each_string_list_item(item, istate->resolve_undo) {
const char *path = item->string;
struct resolve_undo_info *ui = item->util;
int i, len;
@@ -319,13 +337,14 @@ static void show_ru_info(void)
}
}
-static int ce_excluded(struct dir_struct *dir, const struct cache_entry *ce)
+static int ce_excluded(struct dir_struct *dir, struct index_state *istate,
+ const struct cache_entry *ce)
{
int dtype = ce_to_dtype(ce);
- return is_excluded(dir, &the_index, ce->name, &dtype);
+ return is_excluded(dir, istate, ce->name, &dtype);
}
-static void show_files(struct dir_struct *dir)
+static void show_files(struct index_state *istate, struct dir_struct *dir)
{
int i;
@@ -333,33 +352,33 @@ static void show_files(struct dir_struct *dir)
if (show_others || show_killed) {
if (!show_others)
dir->flags |= DIR_COLLECT_KILLED_ONLY;
- fill_directory(dir, &the_index, &pathspec);
+ fill_directory(dir, istate, &pathspec);
if (show_others)
- show_other_files(dir);
+ show_other_files(istate, dir);
if (show_killed)
- show_killed_files(dir);
+ show_killed_files(istate, dir);
}
if (show_cached || show_stage) {
- for (i = 0; i < active_nr; i++) {
- const struct cache_entry *ce = active_cache[i];
+ for (i = 0; i < istate->cache_nr; i++) {
+ const struct cache_entry *ce = istate->cache[i];
if ((dir->flags & DIR_SHOW_IGNORED) &&
- !ce_excluded(dir, ce))
+ !ce_excluded(dir, istate, ce))
continue;
if (show_unmerged && !ce_stage(ce))
continue;
if (ce->ce_flags & CE_UPDATE)
continue;
- show_ce_entry(ce_stage(ce) ? tag_unmerged :
+ show_ce_entry(istate, ce_stage(ce) ? tag_unmerged :
(ce_skip_worktree(ce) ? tag_skip_worktree : tag_cached), ce);
}
}
if (show_deleted || show_modified) {
- for (i = 0; i < active_nr; i++) {
- const struct cache_entry *ce = active_cache[i];
+ for (i = 0; i < istate->cache_nr; i++) {
+ const struct cache_entry *ce = istate->cache[i];
struct stat st;
int err;
if ((dir->flags & DIR_SHOW_IGNORED) &&
- !ce_excluded(dir, ce))
+ !ce_excluded(dir, istate, ce))
continue;
if (ce->ce_flags & CE_UPDATE)
continue;
@@ -367,9 +386,9 @@ static void show_files(struct dir_struct *dir)
continue;
err = lstat(ce->name, &st);
if (show_deleted && err)
- show_ce_entry(tag_removed, ce);
- if (show_modified && ce_modified(ce, &st, 0))
- show_ce_entry(tag_modified, ce);
+ show_ce_entry(istate, tag_removed, ce);
+ if (show_modified && ie_modified(istate, ce, &st, 0))
+ show_ce_entry(istate, tag_modified, ce);
}
}
}
@@ -377,30 +396,31 @@ static void show_files(struct dir_struct *dir)
/*
* Prune the index to only contain stuff starting with "prefix"
*/
-static void prune_cache(const char *prefix, size_t prefixlen)
+static void prune_index(struct index_state *istate,
+ const char *prefix, size_t prefixlen)
{
int pos;
unsigned int first, last;
if (!prefix)
return;
- pos = cache_name_pos(prefix, prefixlen);
+ pos = index_name_pos(istate, prefix, prefixlen);
if (pos < 0)
pos = -pos-1;
first = pos;
- last = active_nr;
+ last = istate->cache_nr;
while (last > first) {
int next = (last + first) >> 1;
- const struct cache_entry *ce = active_cache[next];
+ const struct cache_entry *ce = istate->cache[next];
if (!strncmp(ce->name, prefix, prefixlen)) {
first = next+1;
continue;
}
last = next;
}
- memmove(active_cache, active_cache + pos,
+ memmove(istate->cache, istate->cache + pos,
(last - pos) * sizeof(struct cache_entry *));
- active_nr = last - pos;
+ istate->cache_nr = last - pos;
}
static int get_common_prefix_len(const char *common_prefix)
@@ -430,7 +450,8 @@ static int get_common_prefix_len(const char *common_prefix)
* that were given from the command line. We are not
* going to write this index out.
*/
-void overlay_tree_on_cache(const char *tree_name, const char *prefix)
+void overlay_tree_on_index(struct index_state *istate,
+ const char *tree_name, const char *prefix)
{
struct tree *tree;
struct object_id oid;
@@ -445,8 +466,8 @@ void overlay_tree_on_cache(const char *tree_name, const char *prefix)
die("bad tree-ish %s", tree_name);
/* Hoist the unmerged entries up to stage #3 to make room */
- for (i = 0; i < active_nr; i++) {
- struct cache_entry *ce = active_cache[i];
+ for (i = 0; i < istate->cache_nr; i++) {
+ struct cache_entry *ce = istate->cache[i];
if (!ce_stage(ce))
continue;
ce->ce_flags |= CE_STAGEMASK;
@@ -459,11 +480,11 @@ void overlay_tree_on_cache(const char *tree_name, const char *prefix)
PATHSPEC_PREFER_CWD, prefix, matchbuf);
} else
memset(&pathspec, 0, sizeof(pathspec));
- if (read_tree(tree, 1, &pathspec))
+ if (read_tree(tree, 1, &pathspec, istate))
die("unable to read tree entries %s", tree_name);
- for (i = 0; i < active_nr; i++) {
- struct cache_entry *ce = active_cache[i];
+ for (i = 0; i < istate->cache_nr; i++) {
+ struct cache_entry *ce = istate->cache[i];
switch (ce_stage(ce)) {
case 0:
last_stage0 = ce;
@@ -657,7 +678,7 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)
max_prefix = common_prefix(&pathspec);
max_prefix_len = get_common_prefix_len(max_prefix);
- prune_cache(max_prefix, max_prefix_len);
+ prune_index(&the_index, max_prefix, max_prefix_len);
/* Treat unmatching pathspec elements as errors */
if (pathspec.nr && error_unmatch)
@@ -678,11 +699,11 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)
*/
if (show_stage || show_unmerged)
die("ls-files --with-tree is incompatible with -s or -u");
- overlay_tree_on_cache(with_tree, max_prefix);
+ overlay_tree_on_index(&the_index, with_tree, max_prefix);
}
- show_files(&dir);
+ show_files(&the_index, &dir);
if (show_resolve_undo)
- show_ru_info();
+ show_ru_info(&the_index);
if (ps_matched) {
int bad;
diff --git a/builtin/ls-tree.c b/builtin/ls-tree.c
index ee7b293..ef96540 100644
--- a/builtin/ls-tree.c
+++ b/builtin/ls-tree.c
@@ -4,6 +4,7 @@
* Copyright (C) Linus Torvalds, 2005
*/
#include "cache.h"
+#include "config.h"
#include "blob.h"
#include "tree.h"
#include "commit.h"
diff --git a/builtin/merge-base.c b/builtin/merge-base.c
index 0c36a70..6dbd167 100644
--- a/builtin/merge-base.c
+++ b/builtin/merge-base.c
@@ -1,5 +1,6 @@
#include "builtin.h"
#include "cache.h"
+#include "config.h"
#include "commit.h"
#include "refs.h"
#include "diff.h"
diff --git a/builtin/merge-file.c b/builtin/merge-file.c
index 47dde7c..b08803e 100644
--- a/builtin/merge-file.c
+++ b/builtin/merge-file.c
@@ -1,5 +1,6 @@
#include "builtin.h"
#include "cache.h"
+#include "config.h"
#include "xdiff/xdiff.h"
#include "xdiff-interface.h"
#include "parse-options.h"
diff --git a/builtin/merge.c b/builtin/merge.c
index a4a098f..900bafd 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -7,6 +7,7 @@
*/
#include "cache.h"
+#include "config.h"
#include "parse-options.h"
#include "builtin.h"
#include "lockfile.h"
@@ -415,7 +416,7 @@ static void finish(struct commit *head_commit,
DIFF_FORMAT_SUMMARY | DIFF_FORMAT_DIFFSTAT;
opts.detect_rename = DIFF_DETECT_RENAME;
diff_setup_done(&opts);
- diff_tree_sha1(head->hash, new_head->hash, "", &opts);
+ diff_tree_oid(head, new_head, "", &opts);
diffcore_std(&opts);
diff_flush(&opts);
}
@@ -839,9 +840,7 @@ static int suggest_conflicts(void)
struct strbuf msgbuf = STRBUF_INIT;
filename = git_path_merge_msg();
- fp = fopen(filename, "a");
- if (!fp)
- die_errno(_("Could not open '%s' for writing"), filename);
+ fp = xfopen(filename, "a");
append_conflicts_hint(&msgbuf);
fputs(msgbuf.buf, fp);
diff --git a/builtin/mv.c b/builtin/mv.c
index 61d2003..dcf6736 100644
--- a/builtin/mv.c
+++ b/builtin/mv.c
@@ -4,6 +4,7 @@
* Copyright (C) 2006 Johannes Schindelin
*/
#include "builtin.h"
+#include "config.h"
#include "pathspec.h"
#include "lockfile.h"
#include "dir.h"
diff --git a/builtin/name-rev.c b/builtin/name-rev.c
index 7fc7e66..e21715f 100644
--- a/builtin/name-rev.c
+++ b/builtin/name-rev.c
@@ -1,5 +1,6 @@
#include "builtin.h"
#include "cache.h"
+#include "config.h"
#include "commit.h"
#include "tag.h"
#include "refs.h"
diff --git a/builtin/notes.c b/builtin/notes.c
index 7196bff..77573cf 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -8,6 +8,7 @@
*/
#include "cache.h"
+#include "config.h"
#include "builtin.h"
#include "notes.h"
#include "blob.h"
@@ -109,11 +110,11 @@ static void free_note_data(struct note_data *d)
strbuf_release(&d->buf);
}
-static int list_each_note(const unsigned char *object_sha1,
- const unsigned char *note_sha1, char *note_path,
+static int list_each_note(const struct object_id *object_oid,
+ const struct object_id *note_oid, char *note_path,
void *cb_data)
{
- printf("%s %s\n", sha1_to_hex(note_sha1), sha1_to_hex(object_sha1));
+ printf("%s %s\n", oid_to_hex(note_oid), oid_to_hex(object_oid));
return 0;
}
@@ -129,10 +130,10 @@ static void copy_obj_to_fd(int fd, const unsigned char *sha1)
}
}
-static void write_commented_object(int fd, const unsigned char *object)
+static void write_commented_object(int fd, const struct object_id *object)
{
const char *show_args[5] =
- {"show", "--stat", "--no-notes", sha1_to_hex(object), NULL};
+ {"show", "--stat", "--no-notes", oid_to_hex(object), NULL};
struct child_process show = CHILD_PROCESS_INIT;
struct strbuf buf = STRBUF_INIT;
struct strbuf cbuf = STRBUF_INIT;
@@ -145,7 +146,7 @@ static void write_commented_object(int fd, const unsigned char *object)
show.git_cmd = 1;
if (start_command(&show))
die(_("unable to start 'show' for object '%s'"),
- sha1_to_hex(object));
+ oid_to_hex(object));
if (strbuf_read(&buf, show.out, 0) < 0)
die_errno(_("could not read 'show' output"));
@@ -157,10 +158,10 @@ static void write_commented_object(int fd, const unsigned char *object)
if (finish_command(&show))
die(_("failed to finish 'show' for object '%s'"),
- sha1_to_hex(object));
+ oid_to_hex(object));
}
-static void prepare_note_data(const unsigned char *object, struct note_data *d,
+static void prepare_note_data(const struct object_id *object, struct note_data *d,
const unsigned char *old_note)
{
if (d->use_editor || !d->given) {
@@ -243,16 +244,16 @@ static int parse_reuse_arg(const struct option *opt, const char *arg, int unset)
{
struct note_data *d = opt->value;
char *buf;
- unsigned char object[20];
+ struct object_id object;
enum object_type type;
unsigned long len;
if (d->buf.len)
strbuf_addch(&d->buf, '\n');
- if (get_sha1(arg, object))
+ if (get_oid(arg, &object))
die(_("failed to resolve '%s' as a valid ref."), arg);
- if (!(buf = read_sha1_file(object, &type, &len))) {
+ if (!(buf = read_sha1_file(object.hash, &type, &len))) {
free(buf);
die(_("failed to read object '%s'."), arg);
}
@@ -292,7 +293,7 @@ static int notes_copy_from_stdin(int force, const char *rewrite_cmd)
}
while (strbuf_getline_lf(&buf, stdin) != EOF) {
- unsigned char from_obj[20], to_obj[20];
+ struct object_id from_obj, to_obj;
struct strbuf **split;
int err;
@@ -301,15 +302,15 @@ static int notes_copy_from_stdin(int force, const char *rewrite_cmd)
die(_("malformed input line: '%s'."), buf.buf);
strbuf_rtrim(split[0]);
strbuf_rtrim(split[1]);
- if (get_sha1(split[0]->buf, from_obj))
+ if (get_oid(split[0]->buf, &from_obj))
die(_("failed to resolve '%s' as a valid ref."), split[0]->buf);
- if (get_sha1(split[1]->buf, to_obj))
+ if (get_oid(split[1]->buf, &to_obj))
die(_("failed to resolve '%s' as a valid ref."), split[1]->buf);
if (rewrite_cmd)
- err = copy_note_for_rewrite(c, from_obj, to_obj);
+ err = copy_note_for_rewrite(c, &from_obj, &to_obj);
else
- err = copy_note(t, from_obj, to_obj, force,
+ err = copy_note(t, &from_obj, &to_obj, force,
combine_notes_overwrite);
if (err) {
@@ -352,8 +353,8 @@ static struct notes_tree *init_notes_check(const char *subcommand,
static int list(int argc, const char **argv, const char *prefix)
{
struct notes_tree *t;
- unsigned char object[20];
- const unsigned char *note;
+ struct object_id object;
+ const struct object_id *note;
int retval = -1;
struct option options[] = {
OPT_END()
@@ -370,15 +371,15 @@ static int list(int argc, const char **argv, const char *prefix)
t = init_notes_check("list", 0);
if (argc) {
- if (get_sha1(argv[0], object))
+ if (get_oid(argv[0], &object))
die(_("failed to resolve '%s' as a valid ref."), argv[0]);
- note = get_note(t, object);
+ note = get_note(t, &object);
if (note) {
- puts(sha1_to_hex(note));
+ puts(oid_to_hex(note));
retval = 0;
} else
retval = error(_("no note found for object %s."),
- sha1_to_hex(object));
+ oid_to_hex(&object));
} else
retval = for_each_note(t, 0, list_each_note, NULL);
@@ -393,8 +394,8 @@ static int add(int argc, const char **argv, const char *prefix)
int force = 0, allow_empty = 0;
const char *object_ref;
struct notes_tree *t;
- unsigned char object[20], new_note[20];
- const unsigned char *note;
+ struct object_id object, new_note;
+ const struct object_id *note;
struct note_data d = { 0, 0, NULL, STRBUF_INIT };
struct option options[] = {
{ OPTION_CALLBACK, 'm', "message", &d, N_("message"),
@@ -425,11 +426,11 @@ static int add(int argc, const char **argv, const char *prefix)
object_ref = argc > 1 ? argv[1] : "HEAD";
- if (get_sha1(object_ref, object))
+ if (get_oid(object_ref, &object))
die(_("failed to resolve '%s' as a valid ref."), object_ref);
t = init_notes_check("add", NOTES_INIT_WRITABLE);
- note = get_note(t, object);
+ note = get_note(t, &object);
if (note) {
if (!force) {
@@ -439,7 +440,7 @@ static int add(int argc, const char **argv, const char *prefix)
return error(_("Cannot add notes. "
"Found existing notes for object %s. "
"Use '-f' to overwrite existing notes"),
- sha1_to_hex(object));
+ oid_to_hex(&object));
}
/*
* Redirect to "edit" subcommand.
@@ -452,19 +453,19 @@ static int add(int argc, const char **argv, const char *prefix)
return append_edit(argc, argv, prefix);
}
fprintf(stderr, _("Overwriting existing notes for object %s\n"),
- sha1_to_hex(object));
+ oid_to_hex(&object));
}
- prepare_note_data(object, &d, note);
+ prepare_note_data(&object, &d, note->hash);
if (d.buf.len || allow_empty) {
- write_note_data(&d, new_note);
- if (add_note(t, object, new_note, combine_notes_overwrite))
+ write_note_data(&d, new_note.hash);
+ if (add_note(t, &object, &new_note, combine_notes_overwrite))
die("BUG: combine_notes_overwrite failed");
commit_notes(t, "Notes added by 'git notes add'");
} else {
fprintf(stderr, _("Removing note for object %s\n"),
- sha1_to_hex(object));
- remove_note(t, object);
+ oid_to_hex(&object));
+ remove_note(t, object.hash);
commit_notes(t, "Notes removed by 'git notes add'");
}
@@ -476,9 +477,9 @@ static int add(int argc, const char **argv, const char *prefix)
static int copy(int argc, const char **argv, const char *prefix)
{
int retval = 0, force = 0, from_stdin = 0;
- const unsigned char *from_note, *note;
+ const struct object_id *from_note, *note;
const char *object_ref;
- unsigned char object[20], from_obj[20];
+ struct object_id object, from_obj;
struct notes_tree *t;
const char *rewrite_cmd = NULL;
struct option options[] = {
@@ -511,37 +512,37 @@ static int copy(int argc, const char **argv, const char *prefix)
usage_with_options(git_notes_copy_usage, options);
}
- if (get_sha1(argv[0], from_obj))
+ if (get_oid(argv[0], &from_obj))
die(_("failed to resolve '%s' as a valid ref."), argv[0]);
object_ref = 1 < argc ? argv[1] : "HEAD";
- if (get_sha1(object_ref, object))
+ if (get_oid(object_ref, &object))
die(_("failed to resolve '%s' as a valid ref."), object_ref);
t = init_notes_check("copy", NOTES_INIT_WRITABLE);
- note = get_note(t, object);
+ note = get_note(t, &object);
if (note) {
if (!force) {
retval = error(_("Cannot copy notes. Found existing "
"notes for object %s. Use '-f' to "
"overwrite existing notes"),
- sha1_to_hex(object));
+ oid_to_hex(&object));
goto out;
}
fprintf(stderr, _("Overwriting existing notes for object %s\n"),
- sha1_to_hex(object));
+ oid_to_hex(&object));
}
- from_note = get_note(t, from_obj);
+ from_note = get_note(t, &from_obj);
if (!from_note) {
retval = error(_("missing notes on source object %s. Cannot "
- "copy."), sha1_to_hex(from_obj));
+ "copy."), oid_to_hex(&from_obj));
goto out;
}
- if (add_note(t, object, from_note, combine_notes_overwrite))
+ if (add_note(t, &object, from_note, combine_notes_overwrite))
die("BUG: combine_notes_overwrite failed");
commit_notes(t, "Notes added by 'git notes copy'");
out:
@@ -554,8 +555,8 @@ static int append_edit(int argc, const char **argv, const char *prefix)
int allow_empty = 0;
const char *object_ref;
struct notes_tree *t;
- unsigned char object[20], new_note[20];
- const unsigned char *note;
+ struct object_id object, new_note;
+ const struct object_id *note;
char *logmsg;
const char * const *usage;
struct note_data d = { 0, 0, NULL, STRBUF_INIT };
@@ -594,19 +595,19 @@ static int append_edit(int argc, const char **argv, const char *prefix)
object_ref = 1 < argc ? argv[1] : "HEAD";
- if (get_sha1(object_ref, object))
+ if (get_oid(object_ref, &object))
die(_("failed to resolve '%s' as a valid ref."), object_ref);
t = init_notes_check(argv[0], NOTES_INIT_WRITABLE);
- note = get_note(t, object);
+ note = get_note(t, &object);
- prepare_note_data(object, &d, edit ? note : NULL);
+ prepare_note_data(&object, &d, edit && note ? note->hash : NULL);
if (note && !edit) {
/* Append buf to previous note contents */
unsigned long size;
enum object_type type;
- char *prev_buf = read_sha1_file(note, &type, &size);
+ char *prev_buf = read_sha1_file(note->hash, &type, &size);
strbuf_grow(&d.buf, size + 1);
if (d.buf.len && prev_buf && size)
@@ -617,14 +618,14 @@ static int append_edit(int argc, const char **argv, const char *prefix)
}
if (d.buf.len || allow_empty) {
- write_note_data(&d, new_note);
- if (add_note(t, object, new_note, combine_notes_overwrite))
+ write_note_data(&d, new_note.hash);
+ if (add_note(t, &object, &new_note, combine_notes_overwrite))
die("BUG: combine_notes_overwrite failed");
logmsg = xstrfmt("Notes added by 'git notes %s'", argv[0]);
} else {
fprintf(stderr, _("Removing note for object %s\n"),
- sha1_to_hex(object));
- remove_note(t, object);
+ oid_to_hex(&object));
+ remove_note(t, object.hash);
logmsg = xstrfmt("Notes removed by 'git notes %s'", argv[0]);
}
commit_notes(t, logmsg);
@@ -639,8 +640,8 @@ static int show(int argc, const char **argv, const char *prefix)
{
const char *object_ref;
struct notes_tree *t;
- unsigned char object[20];
- const unsigned char *note;
+ struct object_id object;
+ const struct object_id *note;
int retval;
struct option options[] = {
OPT_END()
@@ -656,17 +657,17 @@ static int show(int argc, const char **argv, const char *prefix)
object_ref = argc ? argv[0] : "HEAD";
- if (get_sha1(object_ref, object))
+ if (get_oid(object_ref, &object))
die(_("failed to resolve '%s' as a valid ref."), object_ref);
t = init_notes_check("show", 0);
- note = get_note(t, object);
+ note = get_note(t, &object);
if (!note)
retval = error(_("no note found for object %s."),
- sha1_to_hex(object));
+ oid_to_hex(&object));
else {
- const char *show_args[3] = {"show", sha1_to_hex(note), NULL};
+ const char *show_args[3] = {"show", oid_to_hex(note), NULL};
retval = execv_git_cmd(show_args);
}
free_notes(t);
@@ -726,7 +727,7 @@ static int merge_commit(struct notes_merge_options *o)
if (!o->local_ref)
die(_("failed to resolve NOTES_MERGE_REF"));
- if (notes_merge_commit(o, t, partial, oid.hash))
+ if (notes_merge_commit(o, t, partial, &oid))
die(_("failed to finalize notes merge"));
/* Reuse existing commit message in reflog message */
@@ -762,7 +763,7 @@ static int git_config_get_notes_strategy(const char *key,
static int merge(int argc, const char **argv, const char *prefix)
{
struct strbuf remote_ref = STRBUF_INIT, msg = STRBUF_INIT;
- unsigned char result_sha1[20];
+ struct object_id result_oid;
struct notes_tree *t;
struct notes_merge_options o;
int do_merge = 0, do_commit = 0, do_abort = 0;
@@ -844,16 +845,16 @@ static int merge(int argc, const char **argv, const char *prefix)
remote_ref.buf, default_notes_ref());
strbuf_add(&(o.commit_msg), msg.buf + 7, msg.len - 7); /* skip "notes: " */
- result = notes_merge(&o, t, result_sha1);
+ result = notes_merge(&o, t, &result_oid);
- if (result >= 0) /* Merge resulted (trivially) in result_sha1 */
+ if (result >= 0) /* Merge resulted (trivially) in result_oid */
/* Update default notes ref with new commit */
- update_ref(msg.buf, default_notes_ref(), result_sha1, NULL,
+ update_ref(msg.buf, default_notes_ref(), result_oid.hash, NULL,
0, UPDATE_REFS_DIE_ON_ERR);
else { /* Merge has unresolved conflicts */
const struct worktree *wt;
/* Update .git/NOTES_MERGE_PARTIAL with partial merge result */
- update_ref(msg.buf, "NOTES_MERGE_PARTIAL", result_sha1, NULL,
+ update_ref(msg.buf, "NOTES_MERGE_PARTIAL", result_oid.hash, NULL,
0, UPDATE_REFS_DIE_ON_ERR);
/* Store ref-to-be-updated into .git/NOTES_MERGE_REF */
wt = find_shared_symref("NOTES_MERGE_REF", default_notes_ref());
@@ -880,10 +881,10 @@ static int merge(int argc, const char **argv, const char *prefix)
static int remove_one_note(struct notes_tree *t, const char *name, unsigned flag)
{
int status;
- unsigned char sha1[20];
- if (get_sha1(name, sha1))
+ struct object_id oid;
+ if (get_oid(name, &oid))
return error(_("Failed to resolve '%s' as a valid ref."), name);
- status = remove_note(t, sha1);
+ status = remove_note(t, oid.hash);
if (status)
fprintf(stderr, _("Object %s has no note\n"), name);
else
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index f672225..d5e96ed 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -1,5 +1,6 @@
#include "builtin.h"
#include "cache.h"
+#include "config.h"
#include "attr.h"
#include "object.h"
#include "blob.h"
diff --git a/builtin/patch-id.c b/builtin/patch-id.c
index 81552e0..970d0d3 100644
--- a/builtin/patch-id.c
+++ b/builtin/patch-id.c
@@ -1,4 +1,5 @@
#include "builtin.h"
+#include "config.h"
static void flush_current_id(int patchlen, struct object_id *id, struct object_id *result)
{
diff --git a/builtin/pull.c b/builtin/pull.c
index da8b60f..2ce311a 100644
--- a/builtin/pull.c
+++ b/builtin/pull.c
@@ -6,6 +6,7 @@
* Fetch one or more remote refs and merge it/them into the current HEAD.
*/
#include "cache.h"
+#include "config.h"
#include "builtin.h"
#include "parse-options.h"
#include "exec_cmd.h"
@@ -337,8 +338,7 @@ static void get_merge_heads(struct oid_array *merge_heads)
struct strbuf sb = STRBUF_INIT;
struct object_id oid;
- if (!(fp = fopen(filename, "r")))
- die_errno(_("could not open '%s' for reading"), filename);
+ fp = xfopen(filename, "r");
while (strbuf_getline_lf(&sb, fp) != EOF) {
if (get_oid_hex(sb.buf, &oid))
continue; /* invalid line: does not start with SHA1 */
diff --git a/builtin/push.c b/builtin/push.c
index a597759..03846e8 100644
--- a/builtin/push.c
+++ b/builtin/push.c
@@ -2,6 +2,7 @@
* "git push"
*/
#include "cache.h"
+#include "config.h"
#include "refs.h"
#include "run-command.h"
#include "builtin.h"
@@ -498,6 +499,10 @@ static int git_push_config(const char *k, const char *v, void *cb)
const char *value;
if (!git_config_get_value("push.recursesubmodules", &value))
recurse_submodules = parse_push_recurse_submodules_arg(k, value);
+ } else if (!strcmp(k, "submodule.recurse")) {
+ int val = git_config_bool(k, v) ?
+ RECURSE_SUBMODULES_ON_DEMAND : RECURSE_SUBMODULES_OFF;
+ recurse_submodules = val;
}
return git_default_config(k, v, NULL);
diff --git a/builtin/read-tree.c b/builtin/read-tree.c
index 78d3193..d5f618d 100644
--- a/builtin/read-tree.c
+++ b/builtin/read-tree.c
@@ -5,6 +5,7 @@
*/
#include "cache.h"
+#include "config.h"
#include "lockfile.h"
#include "object.h"
#include "tree.h"
@@ -21,7 +22,6 @@
static int nr_trees;
static int read_empty;
static struct tree *trees[MAX_UNPACK_TREES];
-static int recurse_submodules = RECURSE_SUBMODULES_DEFAULT;
static int list_tree(struct object_id *oid)
{
@@ -99,21 +99,12 @@ static int debug_merge(const struct cache_entry * const *stages,
return 0;
}
-static int option_parse_recurse_submodules(const struct option *opt,
- const char *arg, int unset)
+static int git_read_tree_config(const char *var, const char *value, void *cb)
{
- if (unset) {
- recurse_submodules = RECURSE_SUBMODULES_OFF;
- return 0;
- }
- if (arg)
- recurse_submodules =
- parse_update_recurse_submodules_arg(opt->long_name,
- arg);
- else
- recurse_submodules = RECURSE_SUBMODULES_ON;
+ if (!strcmp(var, "submodule.recurse"))
+ return git_default_submodule_config(var, value, cb);
- return 0;
+ return git_default_config(var, value, cb);
}
static struct lock_file lock_file;
@@ -157,9 +148,9 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
N_("skip applying sparse checkout filter")),
OPT_BOOL(0, "debug-unpack", &opts.debug_unpack,
N_("debug unpack-trees")),
- { OPTION_CALLBACK, 0, "recurse-submodules", &recurse_submodules,
+ { OPTION_CALLBACK, 0, "recurse-submodules", NULL,
"checkout", "control recursive updating of submodules",
- PARSE_OPT_OPTARG, option_parse_recurse_submodules },
+ PARSE_OPT_OPTARG, option_parse_recurse_submodules_worktree_updater },
OPT_END()
};
@@ -168,18 +159,14 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
opts.src_index = &the_index;
opts.dst_index = &the_index;
- git_config(git_default_config, NULL);
+ git_config(git_read_tree_config, NULL);
argc = parse_options(argc, argv, unused_prefix, read_tree_options,
read_tree_usage, 0);
- hold_locked_index(&lock_file, LOCK_DIE_ON_ERROR);
+ load_submodule_cache();
- if (recurse_submodules != RECURSE_SUBMODULES_DEFAULT) {
- gitmodules_config();
- git_config(submodule_config, NULL);
- set_config_update_recurse_submodules(RECURSE_SUBMODULES_ON);
- }
+ hold_locked_index(&lock_file, LOCK_DIE_ON_ERROR);
prefix_set = opts.prefix ? 1 : 0;
if (1 < opts.merge + opts.reset + prefix_set)
diff --git a/builtin/rebase--helper.c b/builtin/rebase--helper.c
index ca1ebb2..c82b4dc 100644
--- a/builtin/rebase--helper.c
+++ b/builtin/rebase--helper.c
@@ -1,5 +1,6 @@
#include "builtin.h"
#include "cache.h"
+#include "config.h"
#include "parse-options.h"
#include "sequencer.h"
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index b1706a5..71c0c76 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -1,4 +1,5 @@
#include "builtin.h"
+#include "config.h"
#include "lockfile.h"
#include "pack.h"
#include "refs.h"
diff --git a/builtin/reflog.c b/builtin/reflog.c
index 920c16d..44cdc2d 100644
--- a/builtin/reflog.c
+++ b/builtin/reflog.c
@@ -1,4 +1,5 @@
#include "builtin.h"
+#include "config.h"
#include "lockfile.h"
#include "commit.h"
#include "refs.h"
diff --git a/builtin/remote-ext.c b/builtin/remote-ext.c
index 11b48bf..bfb21ba 100644
--- a/builtin/remote-ext.c
+++ b/builtin/remote-ext.c
@@ -3,6 +3,9 @@
#include "run-command.h"
#include "pkt-line.h"
+static const char usage_msg[] =
+ "git remote-ext <remote> <url>";
+
/*
* URL syntax:
* 'command [arg1 [arg2 [...]]]' Invoke command with given arguments.
@@ -193,7 +196,7 @@ static int command_loop(const char *child)
int cmd_remote_ext(int argc, const char **argv, const char *prefix)
{
if (argc != 3)
- die("Expected two arguments");
+ usage(usage_msg);
return command_loop(argv[2]);
}
diff --git a/builtin/remote-fd.c b/builtin/remote-fd.c
index 08d7121..91dfe07 100644
--- a/builtin/remote-fd.c
+++ b/builtin/remote-fd.c
@@ -1,6 +1,9 @@
#include "builtin.h"
#include "transport.h"
+static const char usage_msg[] =
+ "git remote-fd <remote> <url>";
+
/*
* URL syntax:
* 'fd::<inoutfd>[/<anything>]' Read/write socket pair
@@ -57,7 +60,7 @@ int cmd_remote_fd(int argc, const char **argv, const char *prefix)
char *end;
if (argc != 3)
- die("Expected two arguments");
+ usage(usage_msg);
input_fd = (int)strtoul(argv[2], &end, 10);
diff --git a/builtin/remote.c b/builtin/remote.c
index f1a88fe..6273c0c 100644
--- a/builtin/remote.c
+++ b/builtin/remote.c
@@ -1,4 +1,5 @@
#include "builtin.h"
+#include "config.h"
#include "parse-options.h"
#include "transport.h"
#include "remote.h"
diff --git a/builtin/repack.c b/builtin/repack.c
index 38ba4ef..f17a68a 100644
--- a/builtin/repack.c
+++ b/builtin/repack.c
@@ -1,5 +1,6 @@
#include "builtin.h"
#include "cache.h"
+#include "config.h"
#include "dir.h"
#include "parse-options.h"
#include "run-command.h"
diff --git a/builtin/replace.c b/builtin/replace.c
index c921bc9..80a15cf 100644
--- a/builtin/replace.c
+++ b/builtin/replace.c
@@ -9,6 +9,7 @@
*/
#include "cache.h"
+#include "config.h"
#include "builtin.h"
#include "refs.h"
#include "parse-options.h"
diff --git a/builtin/rerere.c b/builtin/rerere.c
index 1bf7242..ffb66e2 100644
--- a/builtin/rerere.c
+++ b/builtin/rerere.c
@@ -1,5 +1,6 @@
#include "builtin.h"
#include "cache.h"
+#include "config.h"
#include "dir.h"
#include "parse-options.h"
#include "string-list.h"
diff --git a/builtin/reset.c b/builtin/reset.c
index 430602d..7aeaea2 100644
--- a/builtin/reset.c
+++ b/builtin/reset.c
@@ -8,6 +8,7 @@
* Copyright (c) 2005, 2006 Linus Torvalds and Junio C Hamano
*/
#include "builtin.h"
+#include "config.h"
#include "lockfile.h"
#include "tag.h"
#include "object.h"
@@ -24,25 +25,6 @@
#include "submodule.h"
#include "submodule-config.h"
-static int recurse_submodules = RECURSE_SUBMODULES_DEFAULT;
-
-static int option_parse_recurse_submodules(const struct option *opt,
- const char *arg, int unset)
-{
- if (unset) {
- recurse_submodules = RECURSE_SUBMODULES_OFF;
- return 0;
- }
- if (arg)
- recurse_submodules =
- parse_update_recurse_submodules_arg(opt->long_name,
- arg);
- else
- recurse_submodules = RECURSE_SUBMODULES_ON;
-
- return 0;
-}
-
static const char * const git_reset_usage[] = {
N_("git reset [--mixed | --soft | --hard | --merge | --keep] [-q] [<commit>]"),
N_("git reset [-q] [<tree-ish>] [--] <paths>..."),
@@ -284,6 +266,14 @@ static int reset_refs(const char *rev, const struct object_id *oid)
return update_ref_status;
}
+static int git_reset_config(const char *var, const char *value, void *cb)
+{
+ if (!strcmp(var, "submodule.recurse"))
+ return git_default_submodule_config(var, value, cb);
+
+ return git_default_config(var, value, cb);
+}
+
int cmd_reset(int argc, const char **argv, const char *prefix)
{
int reset_type = NONE, update_ref_status = 0, quiet = 0;
@@ -303,26 +293,22 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
N_("reset HEAD, index and working tree"), MERGE),
OPT_SET_INT(0, "keep", &reset_type,
N_("reset HEAD but keep local changes"), KEEP),
- { OPTION_CALLBACK, 0, "recurse-submodules", &recurse_submodules,
+ { OPTION_CALLBACK, 0, "recurse-submodules", NULL,
"reset", "control recursive updating of submodules",
- PARSE_OPT_OPTARG, option_parse_recurse_submodules },
+ PARSE_OPT_OPTARG, option_parse_recurse_submodules_worktree_updater },
OPT_BOOL('p', "patch", &patch_mode, N_("select hunks interactively")),
OPT_BOOL('N', "intent-to-add", &intent_to_add,
N_("record only the fact that removed paths will be added later")),
OPT_END()
};
- git_config(git_default_config, NULL);
+ git_config(git_reset_config, NULL);
argc = parse_options(argc, argv, prefix, options, git_reset_usage,
PARSE_OPT_KEEP_DASHDASH);
parse_args(&pathspec, argv, prefix, patch_mode, &rev);
- if (recurse_submodules != RECURSE_SUBMODULES_DEFAULT) {
- gitmodules_config();
- git_config(submodule_config, NULL);
- set_config_update_recurse_submodules(RECURSE_SUBMODULES_ON);
- }
+ load_submodule_cache();
unborn = !strcmp(rev, "HEAD") && get_sha1("HEAD", oid.hash);
if (unborn) {
diff --git a/builtin/rev-list.c b/builtin/rev-list.c
index 718c605..95d84d5 100644
--- a/builtin/rev-list.c
+++ b/builtin/rev-list.c
@@ -1,4 +1,5 @@
#include "cache.h"
+#include "config.h"
#include "commit.h"
#include "diff.h"
#include "revision.h"
@@ -277,6 +278,9 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
int use_bitmap_index = 0;
const char *show_progress = NULL;
+ if (argc == 2 && !strcmp(argv[1], "-h"))
+ usage(rev_list_usage);
+
git_config(git_default_config, NULL);
init_revisions(&revs, prefix);
revs.abbrev = DEFAULT_ABBREV;
diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c
index efdc144..c78b7b3 100644
--- a/builtin/rev-parse.c
+++ b/builtin/rev-parse.c
@@ -4,6 +4,7 @@
* Copyright (C) Linus Torvalds, 2005
*/
#include "cache.h"
+#include "config.h"
#include "commit.h"
#include "refs.h"
#include "quote.h"
diff --git a/builtin/revert.c b/builtin/revert.c
index 345d958..16028b9 100644
--- a/builtin/revert.c
+++ b/builtin/revert.c
@@ -1,4 +1,5 @@
#include "cache.h"
+#include "config.h"
#include "builtin.h"
#include "parse-options.h"
#include "diff.h"
diff --git a/builtin/rm.c b/builtin/rm.c
index 7c323d0..52826d1 100644
--- a/builtin/rm.c
+++ b/builtin/rm.c
@@ -4,6 +4,7 @@
* Copyright (C) Linus Torvalds 2006
*/
#include "builtin.h"
+#include "config.h"
#include "lockfile.h"
#include "dir.h"
#include "cache-tree.h"
@@ -129,7 +130,7 @@ static int check_local_mod(struct object_id *head, int index_only)
ce = active_cache[pos];
if (lstat(ce->name, &st) < 0) {
- if (errno != ENOENT && errno != ENOTDIR)
+ if (!is_missing_file_error(errno))
warning_errno(_("failed to stat '%s'"), ce->name);
/* It already vanished from the working tree */
continue;
diff --git a/builtin/send-pack.c b/builtin/send-pack.c
index b8e2e74..633e0c3 100644
--- a/builtin/send-pack.c
+++ b/builtin/send-pack.c
@@ -1,4 +1,5 @@
#include "builtin.h"
+#include "config.h"
#include "commit.h"
#include "refs.h"
#include "pkt-line.h"
diff --git a/builtin/shortlog.c b/builtin/shortlog.c
index 7cff183..43c4799 100644
--- a/builtin/shortlog.c
+++ b/builtin/shortlog.c
@@ -1,5 +1,6 @@
#include "builtin.h"
#include "cache.h"
+#include "config.h"
#include "commit.h"
#include "diff.h"
#include "string-list.h"
diff --git a/builtin/show-branch.c b/builtin/show-branch.c
index 4a6cc6f..527f69e 100644
--- a/builtin/show-branch.c
+++ b/builtin/show-branch.c
@@ -1,10 +1,12 @@
#include "cache.h"
+#include "config.h"
#include "commit.h"
#include "refs.h"
#include "builtin.h"
#include "color.h"
#include "argv-array.h"
#include "parse-options.h"
+#include "dir.h"
static const char* show_branch_usage[] = {
N_("git show-branch [-a | --all] [-r | --remotes] [--topo-order | --date-order]\n"
@@ -421,14 +423,6 @@ static int append_tag_ref(const char *refname, const struct object_id *oid,
static const char *match_ref_pattern = NULL;
static int match_ref_slash = 0;
-static int count_slash(const char *s)
-{
- int cnt = 0;
- while (*s)
- if (*s++ == '/')
- cnt++;
- return cnt;
-}
static int append_matching_ref(const char *refname, const struct object_id *oid,
int flag, void *cb_data)
@@ -438,7 +432,7 @@ static int append_matching_ref(const char *refname, const struct object_id *oid,
* refs/tags/v0.99.9a and friends.
*/
const char *tail;
- int slash = count_slash(refname);
+ int slash = count_slashes(refname);
for (tail = refname; *tail && match_ref_slash < slash; )
if (*tail++ == '/')
slash--;
@@ -529,7 +523,7 @@ static void append_one_rev(const char *av)
int saved_matches = ref_name_cnt;
match_ref_pattern = av;
- match_ref_slash = count_slash(av);
+ match_ref_slash = count_slashes(av);
for_each_ref(append_matching_ref, NULL);
if (saved_matches == ref_name_cnt &&
ref_name_cnt < MAX_REVS)
diff --git a/builtin/stripspace.c b/builtin/stripspace.c
index 1e62a00..bdf0328 100644
--- a/builtin/stripspace.c
+++ b/builtin/stripspace.c
@@ -1,5 +1,6 @@
#include "builtin.h"
#include "cache.h"
+#include "config.h"
#include "parse-options.h"
#include "strbuf.h"
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 8cc648d..8517032 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -1,5 +1,6 @@
#include "builtin.h"
#include "cache.h"
+#include "config.h"
#include "parse-options.h"
#include "quote.h"
#include "pathspec.h"
@@ -1221,9 +1222,8 @@ static struct cmd_struct commands[] = {
int cmd_submodule__helper(int argc, const char **argv, const char *prefix)
{
int i;
- if (argc < 2)
- die(_("submodule--helper subcommand must be "
- "called with a subcommand"));
+ if (argc < 2 || !strcmp(argv[1], "-h"))
+ usage("git submodule--helper <command>");
for (i = 0; i < ARRAY_SIZE(commands); i++) {
if (!strcmp(argv[1], commands[i].cmd)) {
diff --git a/builtin/symbolic-ref.c b/builtin/symbolic-ref.c
index 70addef..df75cb9 100644
--- a/builtin/symbolic-ref.c
+++ b/builtin/symbolic-ref.c
@@ -1,4 +1,5 @@
#include "builtin.h"
+#include "config.h"
#include "cache.h"
#include "refs.h"
#include "parse-options.h"
diff --git a/builtin/tag.c b/builtin/tag.c
index 1f74a56..01154ea 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -7,6 +7,7 @@
*/
#include "cache.h"
+#include "config.h"
#include "builtin.h"
#include "refs.h"
#include "tag.h"
diff --git a/builtin/unpack-file.c b/builtin/unpack-file.c
index 6fc6bcd..73f1334 100644
--- a/builtin/unpack-file.c
+++ b/builtin/unpack-file.c
@@ -1,4 +1,5 @@
#include "builtin.h"
+#include "config.h"
static char *create_temp_file(unsigned char *sha1)
{
diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c
index 8bc9997..193f8b9 100644
--- a/builtin/unpack-objects.c
+++ b/builtin/unpack-objects.c
@@ -1,5 +1,6 @@
#include "builtin.h"
#include "cache.h"
+#include "config.h"
#include "object.h"
#include "delta.h"
#include "pack.h"
diff --git a/builtin/update-index.c b/builtin/update-index.c
index ebfc09f..56721cf 100644
--- a/builtin/update-index.c
+++ b/builtin/update-index.c
@@ -4,6 +4,7 @@
* Copyright (C) Linus Torvalds, 2005
*/
#include "cache.h"
+#include "config.h"
#include "lockfile.h"
#include "quote.h"
#include "cache-tree.h"
@@ -257,7 +258,7 @@ static int remove_one_path(const char *path)
*/
static int process_lstat_error(const char *path, int err)
{
- if (err == ENOENT || err == ENOTDIR)
+ if (is_missing_file_error(err))
return remove_one_path(path);
return error("lstat(\"%s\"): %s", path, strerror(err));
}
diff --git a/builtin/update-ref.c b/builtin/update-ref.c
index 0b2ecf4..40ccfc1 100644
--- a/builtin/update-ref.c
+++ b/builtin/update-ref.c
@@ -1,4 +1,5 @@
#include "cache.h"
+#include "config.h"
#include "refs.h"
#include "builtin.h"
#include "parse-options.h"
diff --git a/builtin/update-server-info.c b/builtin/update-server-info.c
index 6c8cc3e..873070e 100644
--- a/builtin/update-server-info.c
+++ b/builtin/update-server-info.c
@@ -1,4 +1,5 @@
#include "cache.h"
+#include "config.h"
#include "builtin.h"
#include "parse-options.h"
diff --git a/builtin/upload-archive.c b/builtin/upload-archive.c
index cde0697..84532ae 100644
--- a/builtin/upload-archive.c
+++ b/builtin/upload-archive.c
@@ -22,7 +22,7 @@ int cmd_upload_archive_writer(int argc, const char **argv, const char *prefix)
struct argv_array sent_argv = ARGV_ARRAY_INIT;
const char *arg_cmd = "argument ";
- if (argc != 2)
+ if (argc != 2 || !strcmp(argv[1], "-h"))
usage(upload_archive_usage);
if (!enter_repo(argv[1], 0))
@@ -76,6 +76,9 @@ int cmd_upload_archive(int argc, const char **argv, const char *prefix)
{
struct child_process writer = { argv };
+ if (argc == 2 && !strcmp(argv[1], "-h"))
+ usage(upload_archive_usage);
+
/*
* Set up sideband subprocess.
*
diff --git a/builtin/var.c b/builtin/var.c
index aedbb53..6c6f46b 100644
--- a/builtin/var.c
+++ b/builtin/var.c
@@ -4,6 +4,7 @@
* Copyright (C) Eric Biederman, 2005
*/
#include "builtin.h"
+#include "config.h"
static const char var_usage[] = "git var (-l | <variable>)";
diff --git a/builtin/verify-commit.c b/builtin/verify-commit.c
index 05b734e..ba38ac9 100644
--- a/builtin/verify-commit.c
+++ b/builtin/verify-commit.c
@@ -6,6 +6,7 @@
* Based on git-verify-tag
*/
#include "cache.h"
+#include "config.h"
#include "builtin.h"
#include "commit.h"
#include "run-command.h"
diff --git a/builtin/verify-pack.c b/builtin/verify-pack.c
index c94e156..c2a1a5c 100644
--- a/builtin/verify-pack.c
+++ b/builtin/verify-pack.c
@@ -1,5 +1,6 @@
#include "builtin.h"
#include "cache.h"
+#include "config.h"
#include "run-command.h"
#include "parse-options.h"
diff --git a/builtin/verify-tag.c b/builtin/verify-tag.c
index 5199553..f9a5f75 100644
--- a/builtin/verify-tag.c
+++ b/builtin/verify-tag.c
@@ -6,6 +6,7 @@
* Based on git-verify-tag.sh
*/
#include "cache.h"
+#include "config.h"
#include "builtin.h"
#include "tag.h"
#include "run-command.h"
diff --git a/builtin/worktree.c b/builtin/worktree.c
index 793306e..0c5476e 100644
--- a/builtin/worktree.c
+++ b/builtin/worktree.c
@@ -1,4 +1,5 @@
#include "cache.h"
+#include "config.h"
#include "builtin.h"
#include "dir.h"
#include "parse-options.h"
diff --git a/builtin/write-tree.c b/builtin/write-tree.c
index 084c0df..bd0a78a 100644
--- a/builtin/write-tree.c
+++ b/builtin/write-tree.c
@@ -5,6 +5,7 @@
*/
#include "builtin.h"
#include "cache.h"
+#include "config.h"
#include "tree.h"
#include "cache-tree.h"
#include "parse-options.h"