diff options
Diffstat (limited to 'builtin')
-rw-r--r-- | builtin/am.c | 18 | ||||
-rw-r--r-- | builtin/branch.c | 21 | ||||
-rw-r--r-- | builtin/cat-file.c | 8 | ||||
-rw-r--r-- | builtin/checkout.c | 3 | ||||
-rw-r--r-- | builtin/clean.c | 22 | ||||
-rw-r--r-- | builtin/commit-tree.c | 4 | ||||
-rw-r--r-- | builtin/commit.c | 18 | ||||
-rw-r--r-- | builtin/describe.c | 9 | ||||
-rw-r--r-- | builtin/difftool.c | 37 | ||||
-rw-r--r-- | builtin/fmt-merge-msg.c | 3 | ||||
-rw-r--r-- | builtin/for-each-ref.c | 27 | ||||
-rw-r--r-- | builtin/fsck.c | 49 | ||||
-rw-r--r-- | builtin/gc.c | 4 | ||||
-rw-r--r-- | builtin/grep.c | 8 | ||||
-rw-r--r-- | builtin/log.c | 13 | ||||
-rw-r--r-- | builtin/ls-files.c | 5 | ||||
-rw-r--r-- | builtin/merge-tree.c | 6 | ||||
-rw-r--r-- | builtin/merge.c | 2 | ||||
-rw-r--r-- | builtin/notes.c | 2 | ||||
-rw-r--r-- | builtin/pack-objects.c | 7 | ||||
-rw-r--r-- | builtin/receive-pack.c | 6 | ||||
-rw-r--r-- | builtin/replace.c | 4 | ||||
-rw-r--r-- | builtin/reset.c | 10 | ||||
-rw-r--r-- | builtin/rev-list.c | 7 | ||||
-rw-r--r-- | builtin/rev-parse.c | 8 | ||||
-rw-r--r-- | builtin/revert.c | 2 | ||||
-rw-r--r-- | builtin/show-branch.c | 10 | ||||
-rw-r--r-- | builtin/submodule--helper.c | 59 | ||||
-rw-r--r-- | builtin/tag.c | 66 | ||||
-rw-r--r-- | builtin/unpack-file.c | 12 | ||||
-rw-r--r-- | builtin/update-ref.c | 69 | ||||
-rw-r--r-- | builtin/verify-tag.c | 21 |
32 files changed, 293 insertions, 247 deletions
diff --git a/builtin/am.c b/builtin/am.c index c973bd96dc..ff0869d46f 100644 --- a/builtin/am.c +++ b/builtin/am.c @@ -431,6 +431,14 @@ static void am_load(struct am_state *state) read_state_file(&sb, state, "utf8", 1); state->utf8 = !strcmp(sb.buf, "t"); + if (file_exists(am_path(state, "rerere-autoupdate"))) { + read_state_file(&sb, state, "rerere-autoupdate", 1); + state->allow_rerere_autoupdate = strcmp(sb.buf, "t") ? + RERERE_NOAUTOUPDATE : RERERE_AUTOUPDATE; + } else { + state->allow_rerere_autoupdate = 0; + } + read_state_file(&sb, state, "keep", 1); if (!strcmp(sb.buf, "t")) state->keep = KEEP_TRUE; @@ -1003,6 +1011,10 @@ static void am_setup(struct am_state *state, enum patch_format patch_format, write_state_bool(state, "sign", state->signoff); write_state_bool(state, "utf8", state->utf8); + if (state->allow_rerere_autoupdate) + write_state_bool(state, "rerere-autoupdate", + state->allow_rerere_autoupdate == RERERE_AUTOUPDATE); + switch (state->keep) { case KEEP_FALSE: str = "f"; @@ -1131,7 +1143,7 @@ static int index_has_changes(struct strbuf *sb) struct object_id head; int i; - if (!get_sha1_tree("HEAD", head.hash)) { + if (!get_oid_tree("HEAD", &head)) { struct diff_options opt; diff_setup(&opt); @@ -1432,7 +1444,7 @@ static void write_index_patch(const struct am_state *state) struct rev_info rev_info; FILE *fp; - if (!get_sha1_tree("HEAD", head.hash)) + if (!get_oid_tree("HEAD", &head)) tree = lookup_tree(&head); else tree = lookup_tree(&empty_tree_oid); @@ -1661,7 +1673,7 @@ static void do_commit(const struct am_state *state) if (write_cache_as_tree(tree.hash, 0, NULL)) die(_("git write-tree failed to write a tree")); - if (!get_sha1_commit("HEAD", parent.hash)) { + if (!get_oid_commit("HEAD", &parent)) { old_oid = &parent; commit_list_insert(lookup_commit(&parent), &parents); } else { diff --git a/builtin/branch.c b/builtin/branch.c index 8a0595e115..16d391b407 100644 --- a/builtin/branch.c +++ b/builtin/branch.c @@ -92,7 +92,7 @@ static int git_branch_config(const char *var, const char *value, void *cb) return config_error_nonbool(var); return color_parse(value, branch_colors[slot]); } - return git_color_default_config(var, value, cb); + return git_default_config(var, value, cb); } static const char *branch_get_color(enum color_branch ix) @@ -383,7 +383,7 @@ static char *build_format(struct ref_filter *filter, int maxwidth, const char *r return strbuf_detach(&fmt, NULL); } -static void print_ref_list(struct ref_filter *filter, struct ref_sorting *sorting, const char *format) +static void print_ref_list(struct ref_filter *filter, struct ref_sorting *sorting, struct ref_format *format) { int i; struct ref_array array; @@ -407,14 +407,17 @@ static void print_ref_list(struct ref_filter *filter, struct ref_sorting *sortin if (filter->verbose) maxwidth = calc_maxwidth(&array, strlen(remote_prefix)); - if (!format) - format = to_free = build_format(filter, maxwidth, remote_prefix); - verify_ref_format(format); + if (!format->format) + format->format = to_free = build_format(filter, maxwidth, remote_prefix); + format->use_color = branch_use_color; + + if (verify_ref_format(format)) + die(_("unable to parse format string")); ref_array_sort(sorting, &array); for (i = 0; i < array.nr; i++) { - format_ref_array_item(array.items[i], format, 0, &out); + format_ref_array_item(array.items[i], format, &out); if (column_active(colopts)) { assert(!filter->verbose && "--column and --verbose are incompatible"); /* format to a string_list to let print_columns() do its job */ @@ -549,7 +552,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix) struct ref_filter filter; int icase = 0; static struct ref_sorting *sorting = NULL, **sorting_tail = &sorting; - const char *format = NULL; + struct ref_format format = REF_FORMAT_INIT; struct option options[] = { OPT_GROUP(N_("Generic options")), @@ -593,7 +596,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix) N_("print only branches of the object"), 0, parse_opt_object_name }, OPT_BOOL('i', "ignore-case", &icase, N_("sorting and filtering are case insensitive")), - OPT_STRING( 0 , "format", &format, N_("format"), N_("format to use for the output")), + OPT_STRING( 0 , "format", &format.format, N_("format"), N_("format to use for the output")), OPT_END(), }; @@ -667,7 +670,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix) if (!sorting) sorting = ref_default_sorting(); sorting->ignore_case = icase; - print_ref_list(&filter, sorting, format); + print_ref_list(&filter, sorting, &format); print_columns(&output, colopts, NULL); string_list_clear(&output, 0); return 0; diff --git a/builtin/cat-file.c b/builtin/cat-file.c index 96b786e489..62c8cf0ebf 100644 --- a/builtin/cat-file.c +++ b/builtin/cat-file.c @@ -63,8 +63,8 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name, if (unknown_type) flags |= OBJECT_INFO_ALLOW_UNKNOWN_TYPE; - if (get_sha1_with_context(obj_name, GET_SHA1_RECORD_PATH, - oid.hash, &obj_context)) + if (get_oid_with_context(obj_name, GET_OID_RECORD_PATH, + &oid, &obj_context)) die("Not a valid object name %s", obj_name); if (!path) @@ -361,10 +361,10 @@ static void batch_one_object(const char *obj_name, struct batch_options *opt, struct expand_data *data) { struct object_context ctx; - int flags = opt->follow_symlinks ? GET_SHA1_FOLLOW_SYMLINKS : 0; + int flags = opt->follow_symlinks ? GET_OID_FOLLOW_SYMLINKS : 0; enum follow_symlinks_result result; - result = get_sha1_with_context(obj_name, flags, data->oid.hash, &ctx); + result = get_oid_with_context(obj_name, flags, &data->oid, &ctx); if (result != FOUND) { switch (result) { case MISSING_OBJECT: diff --git a/builtin/checkout.c b/builtin/checkout.c index 9661e1bcba..2d75ac66c7 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -358,6 +358,8 @@ static int checkout_paths(const struct checkout_opts *opts, state.force = 1; state.refresh_cache = 1; state.istate = &the_index; + + enable_delayed_checkout(&state); for (pos = 0; pos < active_nr; pos++) { struct cache_entry *ce = active_cache[pos]; if (ce->ce_flags & CE_MATCHED) { @@ -372,6 +374,7 @@ static int checkout_paths(const struct checkout_opts *opts, pos = skip_same_name(ce, pos) - 1; } } + errs |= finish_delayed_checkout(&state); if (write_locked_index(&the_index, lock_file, COMMIT_LOCK)) die(_("unable to write new index file")); diff --git a/builtin/clean.c b/builtin/clean.c index 057fc97fe4..21a7a32994 100644 --- a/builtin/clean.c +++ b/builtin/clean.c @@ -33,15 +33,6 @@ static const char *msg_skip_git_dir = N_("Skipping repository %s\n"); static const char *msg_would_skip_git_dir = N_("Would skip repository %s\n"); static const char *msg_warn_remove_failed = N_("failed to remove %s"); -static int clean_use_color = -1; -static char clean_colors[][COLOR_MAXLEN] = { - GIT_COLOR_RESET, - GIT_COLOR_NORMAL, /* PLAIN */ - GIT_COLOR_BOLD_BLUE, /* PROMPT */ - GIT_COLOR_BOLD, /* HEADER */ - GIT_COLOR_BOLD_RED, /* HELP */ - GIT_COLOR_BOLD_RED, /* ERROR */ -}; enum color_clean { CLEAN_COLOR_RESET = 0, CLEAN_COLOR_PLAIN = 1, @@ -51,6 +42,16 @@ enum color_clean { CLEAN_COLOR_ERROR = 5 }; +static int clean_use_color = -1; +static char clean_colors[][COLOR_MAXLEN] = { + [CLEAN_COLOR_ERROR] = GIT_COLOR_BOLD_RED, + [CLEAN_COLOR_HEADER] = GIT_COLOR_BOLD, + [CLEAN_COLOR_HELP] = GIT_COLOR_BOLD_RED, + [CLEAN_COLOR_PLAIN] = GIT_COLOR_NORMAL, + [CLEAN_COLOR_PROMPT] = GIT_COLOR_BOLD_BLUE, + [CLEAN_COLOR_RESET] = GIT_COLOR_RESET, +}; + #define MENU_OPTS_SINGLETON 01 #define MENU_OPTS_IMMEDIATE 02 #define MENU_OPTS_LIST_ONLY 04 @@ -125,8 +126,7 @@ static int git_clean_config(const char *var, const char *value, void *cb) return 0; } - /* inspect the color.ui config variable and others */ - return git_color_default_config(var, value, cb); + return git_default_config(var, value, cb); } static const char *clean_get_color(enum color_clean ix) diff --git a/builtin/commit-tree.c b/builtin/commit-tree.c index a4a923d7c0..19e898fa4e 100644 --- a/builtin/commit-tree.c +++ b/builtin/commit-tree.c @@ -56,7 +56,7 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix) struct object_id oid; if (argc <= ++i) usage(commit_tree_usage); - if (get_sha1_commit(argv[i], oid.hash)) + if (get_oid_commit(argv[i], &oid)) die("Not a valid object name %s", argv[i]); assert_sha1_type(oid.hash, OBJ_COMMIT); new_parent(lookup_commit(&oid), &parents); @@ -106,7 +106,7 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix) continue; } - if (get_sha1_tree(arg, tree_oid.hash)) + if (get_oid_tree(arg, &tree_oid)) die("Not a valid object name %s", arg); if (got_tree) die("Cannot give more than one trees"); diff --git a/builtin/commit.c b/builtin/commit.c index 8e93802511..e7a2cb6285 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -510,7 +510,7 @@ static int run_status(FILE *fp, const char *index_file, const char *prefix, int s->index_file = index_file; s->fp = fp; s->nowarn = nowarn; - s->is_initial = get_sha1(s->reference, oid.hash) ? 1 : 0; + s->is_initial = get_oid(s->reference, &oid) ? 1 : 0; if (!s->is_initial) hashcpy(s->sha1_commit, oid.hash); s->status_format = status_format; @@ -891,7 +891,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix, if (amend) parent = "HEAD^1"; - if (get_sha1(parent, oid.hash)) { + if (get_oid(parent, &oid)) { int i, ita_nr = 0; for (i = 0; i < active_nr; i++) @@ -1387,7 +1387,7 @@ int cmd_status(int argc, const char **argv, const char *prefix) fd = hold_locked_index(&index_lock, 0); - s.is_initial = get_sha1(s.reference, oid.hash) ? 1 : 0; + s.is_initial = get_oid(s.reference, &oid) ? 1 : 0; if (!s.is_initial) hashcpy(s.sha1_commit, oid.hash); @@ -1657,7 +1657,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix) status_format = STATUS_FORMAT_NONE; /* Ignore status.short */ s.colopts = 0; - if (get_sha1("HEAD", oid.hash)) + if (get_oid("HEAD", &oid)) current_head = NULL; else { current_head = lookup_commit_or_die(&oid, "HEAD"); @@ -1739,17 +1739,17 @@ int cmd_commit(int argc, const char **argv, const char *prefix) if (verbose || /* Truncate the message just before the diff, if any. */ cleanup_mode == CLEANUP_SCISSORS) strbuf_setlen(&sb, wt_status_locate_end(sb.buf, sb.len)); - if (cleanup_mode != CLEANUP_NONE) strbuf_stripspace(&sb, cleanup_mode == CLEANUP_ALL); - if (template_untouched(&sb) && !allow_empty_message) { + + if (message_is_empty(&sb) && !allow_empty_message) { rollback_index_files(); - fprintf(stderr, _("Aborting commit; you did not edit the message.\n")); + fprintf(stderr, _("Aborting commit due to empty commit message.\n")); exit(1); } - if (message_is_empty(&sb) && !allow_empty_message) { + if (template_untouched(&sb) && !allow_empty_message) { rollback_index_files(); - fprintf(stderr, _("Aborting commit due to empty commit message.\n")); + fprintf(stderr, _("Aborting commit; you did not edit the message.\n")); exit(1); } diff --git a/builtin/describe.c b/builtin/describe.c index 89ea1cdd60..9c13c6817b 100644 --- a/builtin/describe.c +++ b/builtin/describe.c @@ -55,10 +55,13 @@ static const char *prio_names[] = { }; static int commit_name_cmp(const void *unused_cmp_data, - const struct commit_name *cn1, - const struct commit_name *cn2, + const void *entry, + const void *entry_or_key, const void *peeled) { + const struct commit_name *cn1 = entry; + const struct commit_name *cn2 = entry_or_key; + return oidcmp(&cn1->peeled, peeled ? peeled : &cn2->peeled); } @@ -503,7 +506,7 @@ int cmd_describe(int argc, const char **argv, const char *prefix) return cmd_name_rev(args.argc, args.argv, prefix); } - hashmap_init(&names, (hashmap_cmp_fn) commit_name_cmp, NULL, 0); + hashmap_init(&names, commit_name_cmp, NULL, 0); for_each_rawref(get_name, NULL); if (!names.size && !always) die(_("No names found, cannot describe anything.")); diff --git a/builtin/difftool.c b/builtin/difftool.c index a1a26ba891..8864d846f8 100644 --- a/builtin/difftool.c +++ b/builtin/difftool.c @@ -131,10 +131,12 @@ struct working_tree_entry { }; static int working_tree_entry_cmp(const void *unused_cmp_data, - struct working_tree_entry *a, - struct working_tree_entry *b, - void *unused_keydata) + const void *entry, + const void *entry_or_key, + const void *unused_keydata) { + const struct working_tree_entry *a = entry; + const struct working_tree_entry *b = entry_or_key; return strcmp(a->path, b->path); } @@ -149,9 +151,13 @@ struct pair_entry { }; static int pair_cmp(const void *unused_cmp_data, - struct pair_entry *a, struct pair_entry *b, - void *unused_keydata) + const void *entry, + const void *entry_or_key, + const void *unused_keydata) { + const struct pair_entry *a = entry; + const struct pair_entry *b = entry_or_key; + return strcmp(a->path, b->path); } @@ -179,9 +185,13 @@ struct path_entry { }; static int path_entry_cmp(const void *unused_cmp_data, - struct path_entry *a, struct path_entry *b, - void *key) + const void *entry, + const void *entry_or_key, + const void *key) { + const struct path_entry *a = entry; + const struct path_entry *b = entry_or_key; + return strcmp(a->path, key ? key : b->path); } @@ -372,10 +382,9 @@ static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix, rdir_len = rdir.len; wtdir_len = wtdir.len; - hashmap_init(&working_tree_dups, - (hashmap_cmp_fn)working_tree_entry_cmp, NULL, 0); - hashmap_init(&submodules, (hashmap_cmp_fn)pair_cmp, NULL, 0); - hashmap_init(&symlinks2, (hashmap_cmp_fn)pair_cmp, NULL, 0); + hashmap_init(&working_tree_dups, working_tree_entry_cmp, NULL, 0); + hashmap_init(&submodules, pair_cmp, NULL, 0); + hashmap_init(&symlinks2, pair_cmp, NULL, 0); child.no_stdin = 1; child.git_cmd = 1; @@ -585,10 +594,8 @@ static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix, * in the common case of --symlinks and the difftool updating * files through the symlink. */ - hashmap_init(&wt_modified, (hashmap_cmp_fn)path_entry_cmp, - NULL, wtindex.cache_nr); - hashmap_init(&tmp_modified, (hashmap_cmp_fn)path_entry_cmp, - NULL, wtindex.cache_nr); + hashmap_init(&wt_modified, path_entry_cmp, NULL, wtindex.cache_nr); + hashmap_init(&tmp_modified, path_entry_cmp, NULL, wtindex.cache_nr); for (i = 0; i < wtindex.cache_nr; i++) { struct hashmap_entry dummy; diff --git a/builtin/fmt-merge-msg.c b/builtin/fmt-merge-msg.c index 10cbb43416..e99b5ddbf9 100644 --- a/builtin/fmt-merge-msg.c +++ b/builtin/fmt-merge-msg.c @@ -408,7 +408,8 @@ static void shortlog(const char *name, } static void fmt_merge_msg_title(struct strbuf *out, - const char *current_branch) { + const char *current_branch) +{ int i = 0; char *sep = ""; diff --git a/builtin/for-each-ref.c b/builtin/for-each-ref.c index 52be99cbac..5d7c921a77 100644 --- a/builtin/for-each-ref.c +++ b/builtin/for-each-ref.c @@ -17,25 +17,25 @@ static char const * const for_each_ref_usage[] = { int cmd_for_each_ref(int argc, const char **argv, const char *prefix) { int i; - const char *format = "%(objectname) %(objecttype)\t%(refname)"; struct ref_sorting *sorting = NULL, **sorting_tail = &sorting; - int maxcount = 0, quote_style = 0, icase = 0; + int maxcount = 0, icase = 0; struct ref_array array; struct ref_filter filter; + struct ref_format format = REF_FORMAT_INIT; struct option opts[] = { - OPT_BIT('s', "shell", "e_style, + OPT_BIT('s', "shell", &format.quote_style, N_("quote placeholders suitably for shells"), QUOTE_SHELL), - OPT_BIT('p', "perl", "e_style, + OPT_BIT('p', "perl", &format.quote_style, N_("quote placeholders suitably for perl"), QUOTE_PERL), - OPT_BIT(0 , "python", "e_style, + OPT_BIT(0 , "python", &format.quote_style, N_("quote placeholders suitably for python"), QUOTE_PYTHON), - OPT_BIT(0 , "tcl", "e_style, + OPT_BIT(0 , "tcl", &format.quote_style, N_("quote placeholders suitably for Tcl"), QUOTE_TCL), OPT_GROUP(""), OPT_INTEGER( 0 , "count", &maxcount, N_("show only <n> matched refs")), - OPT_STRING( 0 , "format", &format, N_("format"), N_("format to use for the output")), + OPT_STRING( 0 , "format", &format.format, N_("format"), N_("format to use for the output")), OPT_CALLBACK(0 , "sort", sorting_tail, N_("key"), N_("field name to sort on"), &parse_opt_ref_sorting), OPT_CALLBACK(0, "points-at", &filter.points_at, @@ -52,16 +52,20 @@ int cmd_for_each_ref(int argc, const char **argv, const char *prefix) memset(&array, 0, sizeof(array)); memset(&filter, 0, sizeof(filter)); + format.format = "%(objectname) %(objecttype)\t%(refname)"; + + git_config(git_default_config, NULL); + parse_options(argc, argv, prefix, opts, for_each_ref_usage, 0); if (maxcount < 0) { error("invalid --count argument: `%d'", maxcount); usage_with_options(for_each_ref_usage, opts); } - if (HAS_MULTI_BITS(quote_style)) { + if (HAS_MULTI_BITS(format.quote_style)) { error("more than one quoting style?"); usage_with_options(for_each_ref_usage, opts); } - if (verify_ref_format(format)) + if (verify_ref_format(&format)) usage_with_options(for_each_ref_usage, opts); if (!sorting) @@ -69,9 +73,6 @@ int cmd_for_each_ref(int argc, const char **argv, const char *prefix) sorting->ignore_case = icase; filter.ignore_case = icase; - /* for warn_ambiguous_refs */ - git_config(git_default_config, NULL); - filter.name_patterns = argv; filter.match_as_path = 1; filter_refs(&array, &filter, FILTER_REFS_ALL | FILTER_REFS_INCLUDE_BROKEN); @@ -80,7 +81,7 @@ int cmd_for_each_ref(int argc, const char **argv, const char *prefix) if (!maxcount || array.nr < maxcount) maxcount = array.nr; for (i = 0; i < maxcount; i++) - show_ref_array_item(array.items[i], format, quote_style); + show_ref_array_item(array.items[i], &format); ref_array_clear(&array); return 0; } diff --git a/builtin/fsck.c b/builtin/fsck.c index 99dea7adf6..a92f448186 100644 --- a/builtin/fsck.c +++ b/builtin/fsck.c @@ -19,6 +19,8 @@ #define REACHABLE 0x0001 #define SEEN 0x0002 #define HAS_OBJ 0x0004 +/* This flag is set if something points to this object. */ +#define USED 0x0008 static int show_root; static int show_tags; @@ -168,18 +170,7 @@ static void mark_object_reachable(struct object *obj) static int traverse_one_object(struct object *obj) { - int result; - struct tree *tree = NULL; - - if (obj->type == OBJ_TREE) { - tree = (struct tree *)obj; - if (parse_tree(tree) < 0) - return 1; /* error already displayed */ - } - result = fsck_walk(obj, obj, &fsck_walk_options); - if (tree) - free_tree_buffer(tree); - return result; + return fsck_walk(obj, obj, &fsck_walk_options); } static int traverse_reachable(void) @@ -206,7 +197,7 @@ static int mark_used(struct object *obj, int type, void *data, struct fsck_optio { if (!obj) return 1; - obj->used = 1; + obj->flags |= USED; return 0; } @@ -255,7 +246,7 @@ static void check_unreachable_object(struct object *obj) } /* - * "!used" means that nothing at all points to it, including + * "!USED" means that nothing at all points to it, including * other unreachable objects. In other words, it's the "tip" * of some set of unreachable objects, usually a commit that * got dropped. @@ -266,7 +257,7 @@ static void check_unreachable_object(struct object *obj) * deleted a branch by mistake, this is a prime candidate to * start looking at, for example. */ - if (!obj->used) { + if (!(obj->flags & USED)) { if (show_dangling) printf("dangling %s %s\n", printable_type(obj), describe_object(obj)); @@ -390,7 +381,8 @@ static int fsck_obj_buffer(const struct object_id *oid, enum object_type type, errors_found |= ERROR_OBJECT; return error("%s: object corrupt or missing", oid_to_hex(oid)); } - obj->flags = HAS_OBJ; + obj->flags &= ~(REACHABLE | SEEN); + obj->flags |= HAS_OBJ; return fsck_obj(obj); } @@ -408,7 +400,7 @@ static void fsck_handle_reflog_oid(const char *refname, struct object_id *oid, add_decoration(fsck_walk_options.object_names, obj, xstrfmt("%s@{%"PRItime"}", refname, timestamp)); - obj->used = 1; + obj->flags |= USED; mark_object_reachable(obj); } else { error("%s: invalid reflog entry %s", refname, oid_to_hex(oid)); @@ -456,7 +448,7 @@ static int fsck_handle_ref(const char *refname, const struct object_id *oid, errors_found |= ERROR_REFS; } default_refs++; - obj->used = 1; + obj->flags |= USED; if (name_objects) add_decoration(fsck_walk_options.object_names, obj, xstrdup(refname)); @@ -524,7 +516,8 @@ static int fsck_loose(const struct object_id *oid, const char *path, void *data) return 0; /* keep checking other objects */ } - obj->flags = HAS_OBJ; + obj->flags &= ~(REACHABLE | SEEN); + obj->flags |= HAS_OBJ; if (fsck_obj(obj)) errors_found |= ERROR_OBJECT; return 0; @@ -606,7 +599,7 @@ static int fsck_cache_tree(struct cache_tree *it) errors_found |= ERROR_REFS; return 1; } - obj->used = 1; + obj->flags |= USED; if (name_objects) add_decoration(fsck_walk_options.object_names, obj, xstrdup(":")); @@ -667,7 +660,7 @@ static struct option fsck_opts[] = { int cmd_fsck(int argc, const char **argv, const char *prefix) { - int i, heads; + int i; struct alternate_object_database *alt; errors_found = 0; @@ -735,25 +728,23 @@ int cmd_fsck(int argc, const char **argv, const char *prefix) } } - heads = 0; for (i = 0; i < argc; i++) { const char *arg = argv[i]; - unsigned char sha1[20]; - if (!get_sha1(arg, sha1)) { - struct object *obj = lookup_object(sha1); + struct object_id oid; + if (!get_oid(arg, &oid)) { + struct object *obj = lookup_object(oid.hash); if (!obj || !(obj->flags & HAS_OBJ)) { - error("%s: object missing", sha1_to_hex(sha1)); + error("%s: object missing", oid_to_hex(&oid)); errors_found |= ERROR_OBJECT; continue; } - obj->used = 1; + obj->flags |= USED; if (name_objects) add_decoration(fsck_walk_options.object_names, obj, xstrdup(arg)); mark_object_reachable(obj); - heads++; continue; } error("invalid parameter: expected sha1, got '%s'", arg); @@ -785,7 +776,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix) if (!blob) continue; obj = &blob->object; - obj->used = 1; + obj->flags |= USED; if (name_objects) add_decoration(fsck_walk_options.object_names, obj, diff --git a/builtin/gc.c b/builtin/gc.c index 2ba50a2873..e6b84475ae 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -414,8 +414,12 @@ int cmd_gc(int argc, const char **argv, const char *prefix) if (report_last_gc_error()) return -1; + if (lock_repo_for_gc(force, &pid)) + return 0; if (gc_before_repack()) return -1; + delete_tempfile(&pidfile); + /* * failure to daemonize is ok, we'll continue * in foreground diff --git a/builtin/grep.c b/builtin/grep.c index cd0e51f3c0..a70d8e2fba 100644 --- a/builtin/grep.c +++ b/builtin/grep.c @@ -275,7 +275,7 @@ static int wait_all(void) static int grep_cmd_config(const char *var, const char *value, void *cb) { int st = grep_config(var, value, cb); - if (git_color_default_config(var, value, cb) < 0) + if (git_default_config(var, value, cb) < 0) st = -1; if (!strcmp(var, "grep.threads")) { @@ -643,7 +643,7 @@ static int grep_objects(struct grep_opt *opt, const struct pathspec *pathspec, /* load the gitmodules file for this rev */ if (recurse_submodules) { submodule_free(); - gitmodules_config_sha1(real_obj->oid.hash); + gitmodules_config_oid(&real_obj->oid); } if (grep_object(opt, pathspec, real_obj, list->objects[i].name, list->objects[i].path, repo)) { @@ -983,8 +983,8 @@ int cmd_grep(int argc, const char **argv, const char *prefix) break; } - if (get_sha1_with_context(arg, GET_SHA1_RECORD_PATH, - oid.hash, &oc)) { + if (get_oid_with_context(arg, GET_OID_RECORD_PATH, + &oid, &oc)) { if (seen_dashdash) die(_("unable to resolve revision: %s"), arg); break; diff --git a/builtin/log.c b/builtin/log.c index c6362cf92e..725c7b8a1a 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -372,11 +372,14 @@ static int cmd_log_walk(struct rev_info *rev) */ rev->max_count++; if (!rev->reflog_info) { - /* we allow cycles in reflog ancestry */ + /* + * We may show a given commit multiple times when + * walking the reflogs. + */ free_commit_buffer(commit); + free_commit_list(commit->parents); + commit->parents = NULL; } - free_commit_list(commit->parents); - commit->parents = NULL; if (saved_nrl < rev->diffopt.needed_rename_limit) saved_nrl = rev->diffopt.needed_rename_limit; if (rev->diffopt.degraded_cc_to_c) @@ -484,8 +487,8 @@ static int show_blob_object(const struct object_id *oid, struct rev_info *rev, c !DIFF_OPT_TST(&rev->diffopt, ALLOW_TEXTCONV)) return stream_blob_to_fd(1, oid, NULL, 0); - if (get_sha1_with_context(obj_name, GET_SHA1_RECORD_PATH, - oidc.hash, &obj_context)) + if (get_oid_with_context(obj_name, GET_OID_RECORD_PATH, + &oidc, &obj_context)) die(_("Not a valid object name %s"), obj_name); if (!obj_context.path || !textconv_object(obj_context.path, obj_context.mode, &oidc, 1, &buf, &size)) { diff --git a/builtin/ls-files.c b/builtin/ls-files.c index b8514a0029..c6126eae55 100644 --- a/builtin/ls-files.c +++ b/builtin/ls-files.c @@ -362,7 +362,7 @@ static void prune_index(struct index_state *istate, int pos; unsigned int first, last; - if (!prefix) + if (!prefix || !istate->cache_nr) return; pos = index_name_pos(istate, prefix, prefixlen); if (pos < 0) @@ -378,8 +378,7 @@ static void prune_index(struct index_state *istate, } last = next; } - memmove(istate->cache, istate->cache + pos, - (last - pos) * sizeof(struct cache_entry *)); + MOVE_ARRAY(istate->cache, istate->cache + pos, last - pos); istate->cache_nr = last - pos; } diff --git a/builtin/merge-tree.c b/builtin/merge-tree.c index bad6735c76..f12da292cf 100644 --- a/builtin/merge-tree.c +++ b/builtin/merge-tree.c @@ -347,12 +347,12 @@ static void merge_trees(struct tree_desc t[3], const char *base) static void *get_tree_descriptor(struct tree_desc *desc, const char *rev) { - unsigned char sha1[20]; + struct object_id oid; void *buf; - if (get_sha1(rev, sha1)) + if (get_oid(rev, &oid)) die("unknown rev %s", rev); - buf = fill_tree_descriptor(desc, sha1); + buf = fill_tree_descriptor(desc, oid.hash); if (!buf) die("%s is not a tree", rev); return buf; diff --git a/builtin/merge.c b/builtin/merge.c index 900bafdb45..d5797b8fe7 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -537,7 +537,7 @@ static void parse_branch_merge_options(char *bmo) die(_("Bad branch.%s.mergeoptions string: %s"), branch, split_cmdline_strerror(argc)); REALLOC_ARRAY(argv, argc + 2); - memmove(argv + 1, argv, sizeof(*argv) * (argc + 1)); + MOVE_ARRAY(argv + 1, argv, argc + 1); argc++; argv[0] = "branch.*.mergeoptions"; parse_options(argc, argv, NULL, builtin_merge_options, diff --git a/builtin/notes.c b/builtin/notes.c index 77573cf1ea..4303848e04 100644 --- a/builtin/notes.c +++ b/builtin/notes.c @@ -456,7 +456,7 @@ static int add(int argc, const char **argv, const char *prefix) oid_to_hex(&object)); } - prepare_note_data(&object, &d, note->hash); + prepare_note_data(&object, &d, note ? note->hash : NULL); if (d.buf.len || allow_empty) { write_note_data(&d, new_note.hash); if (add_note(t, &object, &new_note, combine_notes_overwrite)) diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c index f4a8441fe9..c753e9237a 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -1289,7 +1289,7 @@ static int done_pbase_path_pos(unsigned hash) static int check_pbase_path(unsigned hash) { - int pos = (!done_pbase_paths) ? -1 : done_pbase_path_pos(hash); + int pos = done_pbase_path_pos(hash); if (0 <= pos) return 1; pos = -pos - 1; @@ -1298,9 +1298,8 @@ static int check_pbase_path(unsigned hash) done_pbase_paths_alloc); done_pbase_paths_num++; if (pos < done_pbase_paths_num) - memmove(done_pbase_paths + pos + 1, - done_pbase_paths + pos, - (done_pbase_paths_num - pos - 1) * sizeof(unsigned)); + MOVE_ARRAY(done_pbase_paths + pos + 1, done_pbase_paths + pos, + done_pbase_paths_num - pos - 1); done_pbase_paths[pos] = hash; return 0; } diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c index cabdc55e09..14b6e09b42 100644 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@ -919,9 +919,9 @@ static int update_shallow_ref(struct command *cmd, struct shallow_info *si) */ static int head_has_history(void) { - unsigned char sha1[20]; + struct object_id oid; - return !get_sha1("HEAD", sha1); + return !get_oid("HEAD", &oid); } static const char *push_to_deploy(unsigned char *sha1, @@ -1138,7 +1138,7 @@ static const char *update(struct command *cmd, struct shallow_info *si) } if (ref_transaction_delete(transaction, namespaced_name, - old_oid->hash, + old_oid ? old_oid->hash : NULL, 0, "push", &err)) { rp_error("%s", err.buf); strbuf_release(&err); diff --git a/builtin/replace.c b/builtin/replace.c index fba336a68a..f4a85a165b 100644 --- a/builtin/replace.c +++ b/builtin/replace.c @@ -50,7 +50,7 @@ static int show_reference(const char *refname, const struct object_id *oid, struct object_id object; enum object_type obj_type, repl_type; - if (get_sha1(refname, object.hash)) + if (get_oid(refname, &object)) return error("Failed to resolve '%s' as a valid ref.", refname); obj_type = sha1_object_info(object.hash, NULL); @@ -365,7 +365,7 @@ static void check_one_mergetag(struct commit *commit, /* iterate over new parents */ for (i = 1; i < mergetag_data->argc; i++) { struct object_id oid; - if (get_sha1(mergetag_data->argv[i], oid.hash) < 0) + if (get_oid(mergetag_data->argv[i], &oid) < 0) die(_("Not a valid object name: '%s'"), mergetag_data->argv[i]); if (!oidcmp(&tag->tagged->oid, &oid)) return; /* found */ diff --git a/builtin/reset.c b/builtin/reset.c index 7aeaea2737..046403ed68 100644 --- a/builtin/reset.c +++ b/builtin/reset.c @@ -219,8 +219,8 @@ static void parse_args(struct pathspec *pathspec, * has to be unambiguous. If there is a single argument, it * can not be a tree */ - else if ((!argv[1] && !get_sha1_committish(argv[0], unused.hash)) || - (argv[1] && !get_sha1_treeish(argv[0], unused.hash))) { + else if ((!argv[1] && !get_oid_committish(argv[0], &unused)) || + (argv[1] && !get_oid_treeish(argv[0], &unused))) { /* * Ok, argv[0] looks like a commit/tree; it should not * be a filename. @@ -310,13 +310,13 @@ int cmd_reset(int argc, const char **argv, const char *prefix) load_submodule_cache(); - unborn = !strcmp(rev, "HEAD") && get_sha1("HEAD", oid.hash); + unborn = !strcmp(rev, "HEAD") && get_oid("HEAD", &oid); if (unborn) { /* reset on unborn branch: treat as reset to empty tree */ hashcpy(oid.hash, EMPTY_TREE_SHA1_BIN); } else if (!pathspec.nr) { struct commit *commit; - if (get_sha1_committish(rev, oid.hash)) + if (get_oid_committish(rev, &oid)) die(_("Failed to resolve '%s' as a valid revision."), rev); commit = lookup_commit_reference(&oid); if (!commit) @@ -324,7 +324,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix) oidcpy(&oid, &commit->object.oid); } else { struct tree *tree; - if (get_sha1_treeish(rev, oid.hash)) + if (get_oid_treeish(rev, &oid)) die(_("Failed to resolve '%s' as a valid tree."), rev); tree = parse_tree_indirect(&oid); if (!tree) diff --git a/builtin/rev-list.c b/builtin/rev-list.c index 95d84d5cda..95b4128250 100644 --- a/builtin/rev-list.c +++ b/builtin/rev-list.c @@ -11,6 +11,7 @@ #include "graph.h" #include "bisect.h" #include "progress.h" +#include "reflog-walk.h" static const char rev_list_usage[] = "git rev-list [OPTION] <commit-id>... [ -- paths... ]\n" @@ -122,6 +123,7 @@ static void show_commit(struct commit *commit, void *data) ctx.date_mode_explicit = revs->date_mode_explicit; ctx.fmt = revs->commit_format; ctx.output_encoding = get_log_output_encoding(); + ctx.color = revs->diffopt.use_color; pretty_print_commit(&ctx, commit, &buf); if (buf.len) { if (revs->commit_format != CMIT_FMT_ONELINE) @@ -348,9 +350,10 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix) /* Only --header was specified */ revs.commit_format = CMIT_FMT_RAW; - if ((!revs.commits && + if ((!revs.commits && reflog_walk_empty(revs.reflog_info) && (!(revs.tag_objects || revs.tree_objects || revs.blob_objects) && - !revs.pending.nr)) || + !revs.pending.nr) && + !revs.rev_input_given) || revs.diff) usage(rev_list_usage); diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c index c78b7b33d6..2bd28d3c08 100644 --- a/builtin/rev-parse.c +++ b/builtin/rev-parse.c @@ -274,7 +274,7 @@ static int try_difference(const char *arg) return 0; } - if (!get_sha1_committish(this, oid.hash) && !get_sha1_committish(next, end.hash)) { + if (!get_oid_committish(this, &oid) && !get_oid_committish(next, &end)) { show_rev(NORMAL, &end, next); show_rev(symmetric ? NORMAL : REVERSED, &oid, this); if (symmetric) { @@ -328,7 +328,7 @@ static int try_parent_shorthands(const char *arg) return 0; *dotdot = 0; - if (get_sha1_committish(arg, oid.hash)) { + if (get_oid_committish(arg, &oid)) { *dotdot = '^'; return 0; } @@ -702,7 +702,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix) } if (!strcmp(arg, "--quiet") || !strcmp(arg, "-q")) { quiet = 1; - flags |= GET_SHA1_QUIETLY; + flags |= GET_OID_QUIETLY; continue; } if (opt_with_value(arg, "--short", &arg)) { @@ -911,7 +911,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix) name++; type = REVERSED; } - if (!get_sha1_with_context(name, flags, oid.hash, &unused)) { + if (!get_oid_with_context(name, flags, &oid, &unused)) { if (verify) revs_count++; else diff --git a/builtin/revert.c b/builtin/revert.c index 16028b9ea8..b9d927eb09 100644 --- a/builtin/revert.c +++ b/builtin/revert.c @@ -155,6 +155,8 @@ static int run_sequencer(int argc, const char **argv, struct replay_opts *opts) "--strategy-option", opts->xopts ? 1 : 0, "-x", opts->record_origin, "--ff", opts->allow_ff, + "--rerere-autoupdate", opts->allow_rerere_auto == RERERE_AUTOUPDATE, + "--no-rerere-autoupdate", opts->allow_rerere_auto == RERERE_NOAUTOUPDATE, NULL); } diff --git a/builtin/show-branch.c b/builtin/show-branch.c index 7073a3eb97..84547d6fba 100644 --- a/builtin/show-branch.c +++ b/builtin/show-branch.c @@ -393,7 +393,7 @@ static int append_head_ref(const char *refname, const struct object_id *oid, /* If both heads/foo and tags/foo exists, get_sha1 would * get confused. */ - if (get_sha1(refname + ofs, tmp.hash) || oidcmp(&tmp, oid)) + if (get_oid(refname + ofs, &tmp) || oidcmp(&tmp, oid)) ofs = 5; return append_ref(refname + ofs, oid, 0); } @@ -408,7 +408,7 @@ static int append_remote_ref(const char *refname, const struct object_id *oid, /* If both heads/foo and tags/foo exists, get_sha1 would * get confused. */ - if (get_sha1(refname + ofs, tmp.hash) || oidcmp(&tmp, oid)) + if (get_oid(refname + ofs, &tmp) || oidcmp(&tmp, oid)) ofs = 5; return append_ref(refname + ofs, oid, 0); } @@ -514,7 +514,7 @@ static int show_independent(struct commit **rev, static void append_one_rev(const char *av) { struct object_id revkey; - if (!get_sha1(av, revkey.hash)) { + if (!get_oid(av, &revkey)) { append_ref(av, &revkey, 0); return; } @@ -554,7 +554,7 @@ static int git_show_branch_config(const char *var, const char *value, void *cb) return 0; } - return git_color_default_config(var, value, cb); + return git_default_config(var, value, cb); } static int omit_in_dense(struct commit *commit, struct commit **rev, int n) @@ -808,7 +808,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix) die(Q_("cannot handle more than %d rev.", "cannot handle more than %d revs.", MAX_REVS), MAX_REVS); - if (get_sha1(ref_name[num_rev], revkey.hash)) + if (get_oid(ref_name[num_rev], &revkey)) die(_("'%s' is not a valid ref."), ref_name[num_rev]); commit = lookup_commit_reference(&revkey); if (!commit) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 6d9600d4fb..0ff9dd0b85 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -350,7 +350,7 @@ static void init_submodule(const char *path, const char *prefix, int quiet) } else displaypath = xstrdup(path); - sub = submodule_from_path(null_sha1, path); + sub = submodule_from_path(&null_oid, path); if (!sub) die(_("No url found for submodule path '%s' in .gitmodules"), @@ -476,7 +476,7 @@ static int module_name(int argc, const char **argv, const char *prefix) usage(_("git submodule--helper name <path>")); gitmodules_config(); - sub = submodule_from_path(null_sha1, argv[1]); + sub = submodule_from_path(&null_oid, argv[1]); if (!sub) die(_("no submodule mapping found in .gitmodules for path '%s'"), @@ -795,7 +795,7 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce, goto cleanup; } - sub = submodule_from_path(null_sha1, ce->name); + sub = submodule_from_path(&null_oid, ce->name); if (suc->recursive_prefix) displaypath = relative_path(suc->recursive_prefix, @@ -930,7 +930,7 @@ static int update_clone_task_finished(int result, const struct cache_entry *ce; struct submodule_update_clone *suc = suc_cb; - int *idxP = *(int**)idx_task_cb; + int *idxP = idx_task_cb; int idx = *idxP; free(idxP); @@ -1069,7 +1069,7 @@ static const char *remote_submodule_branch(const char *path) gitmodules_config(); git_config(submodule_config, NULL); - sub = submodule_from_path(null_sha1, path); + sub = submodule_from_path(&null_oid, path); if (!sub) return NULL; @@ -1117,9 +1117,28 @@ static int resolve_remote_submodule_branch(int argc, const char **argv, static int push_check(int argc, const char **argv, const char *prefix) { struct remote *remote; + const char *superproject_head; + char *head; + int detached_head = 0; + struct object_id head_oid; - if (argc < 2) - die("submodule--helper push-check requires at least 1 argument"); + if (argc < 3) + die("submodule--helper push-check requires at least 2 arguments"); + + /* + * superproject's resolved head ref. + * if HEAD then the superproject is in a detached head state, otherwise + * it will be the resolved head ref. + */ + superproject_head = argv[1]; + argv++; + argc--; + /* Get the submodule's head ref and determine if it is detached */ + head = resolve_refdup("HEAD", 0, head_oid.hash, NULL); + if (!head) + die(_("Failed to resolve HEAD as a valid ref.")); + if (!strcmp(head, "HEAD")) + detached_head = 1; /* * The remote must be configured. @@ -1142,18 +1161,30 @@ static int push_check(int argc, const char **argv, const char *prefix) if (rs->pattern || rs->matching) continue; - /* - * LHS must match a single ref - * NEEDSWORK: add logic to special case 'HEAD' once - * working with submodules in a detached head state - * ceases to be the norm. - */ - if (count_refspec_match(rs->src, local_refs, NULL) != 1) + /* LHS must match a single ref */ + switch (count_refspec_match(rs->src, local_refs, NULL)) { + case 1: + break; + case 0: + /* + * If LHS matches 'HEAD' then we need to ensure + * that it matches the same named branch + * checked out in the superproject. + */ + if (!strcmp(rs->src, "HEAD")) { + if (!detached_head && + !strcmp(head, superproject_head)) + break; + die("HEAD does not match the named branch in the superproject"); + } + default: die("src refspec '%s' must name a ref", rs->src); + } } free_refspec(refspec_nr, refspec); } + free(head); return 0; } diff --git a/builtin/tag.c b/builtin/tag.c index 01154ea8dc..c627794181 100644 --- a/builtin/tag.c +++ b/builtin/tag.c @@ -32,7 +32,8 @@ static const char * const git_tag_usage[] = { static unsigned int colopts; static int force_sign_annotate; -static int list_tags(struct ref_filter *filter, struct ref_sorting *sorting, const char *format) +static int list_tags(struct ref_filter *filter, struct ref_sorting *sorting, + struct ref_format *format) { struct ref_array array; char *to_free = NULL; @@ -43,23 +44,24 @@ static int list_tags(struct ref_filter *filter, struct ref_sorting *sorting, con if (filter->lines == -1) filter->lines = 0; - if (!format) { + if (!format->format) { if (filter->lines) { to_free = xstrfmt("%s %%(contents:lines=%d)", "%(align:15)%(refname:lstrip=2)%(end)", filter->lines); - format = to_free; + format->format = to_free; } else - format = "%(refname:lstrip=2)"; + format->format = "%(refname:lstrip=2)"; } - verify_ref_format(format); + if (verify_ref_format(format)) + die(_("unable to parse format string")); filter->with_commit_tag_algo = 1; filter_refs(&array, filter, FILTER_REFS_TAGS); ref_array_sort(sorting, &array); for (i = 0; i < array.nr; i++) - show_ref_array_item(array.items[i], format, 0); + show_ref_array_item(array.items[i], format); ref_array_clear(&array); free(to_free); @@ -105,17 +107,17 @@ static int verify_tag(const char *name, const char *ref, const struct object_id *oid, const void *cb_data) { int flags; - const char *fmt_pretty = cb_data; + const struct ref_format *format = cb_data; flags = GPG_VERIFY_VERBOSE; - if (fmt_pretty) + if (format->format) flags = GPG_VERIFY_OMIT_STATUS; - if (gpg_verify_tag(oid->hash, name, flags)) + if (gpg_verify_tag(oid, name, flags)) return -1; - if (fmt_pretty) - pretty_print_ref(name, oid->hash, fmt_pretty); + if (format->format) + pretty_print_ref(name, oid->hash, format); return 0; } @@ -134,30 +136,6 @@ static const char tag_template_nocleanup[] = "Lines starting with '%c' will be kept; you may remove them" " yourself if you want to.\n"); -/* Parse arg given and add it the ref_sorting array */ -static int parse_sorting_string(const char *arg, struct ref_sorting **sorting_tail) -{ - struct ref_sorting *s; - int len; - - s = xcalloc(1, sizeof(*s)); - s->next = *sorting_tail; - *sorting_tail = s; - - if (*arg == '-') { - s->reverse = 1; - arg++; - } - if (skip_prefix(arg, "version:", &arg) || - skip_prefix(arg, "v:", &arg)) - s->version = 1; - - len = strlen(arg); - s->atom = parse_ref_filter_atom(arg, arg+len); - - return 0; -} - static int git_tag_config(const char *var, const char *value, void *cb) { int status; @@ -166,7 +144,7 @@ static int git_tag_config(const char *var, const char *value, void *cb) if (!strcmp(var, "tag.sort")) { if (!value) return config_error_nonbool(var); - parse_sorting_string(value, sorting_tail); + parse_ref_sorting(sorting_tail, value); return 0; } @@ -392,7 +370,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix) struct strbuf err = STRBUF_INIT; struct ref_filter filter; static struct ref_sorting *sorting = NULL, **sorting_tail = &sorting; - const char *format = NULL; + struct ref_format format = REF_FORMAT_INIT; int icase = 0; struct option options[] = { OPT_CMDMODE('l', "list", &cmdmode, N_("list tag names"), 'l'), @@ -431,7 +409,8 @@ int cmd_tag(int argc, const char **argv, const char *prefix) N_("print only tags of the object"), PARSE_OPT_LASTARG_DEFAULT, parse_opt_object_name, (intptr_t) "HEAD" }, - OPT_STRING( 0 , "format", &format, N_("format"), N_("format to use for the output")), + OPT_STRING( 0 , "format", &format.format, N_("format"), + N_("format to use for the output")), OPT_BOOL('i', "ignore-case", &icase, N_("sorting and filtering are case insensitive")), OPT_END() }; @@ -461,6 +440,9 @@ int cmd_tag(int argc, const char **argv, const char *prefix) cmdmode = 'l'; } + if (cmdmode == 'l') + setup_auto_pager("tag", 1); + if ((create_tag_object || force) && (cmdmode != 0)) usage_with_options(git_tag_usage, options); @@ -483,7 +465,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix) run_column_filter(colopts, &copts); } filter.name_patterns = argv; - ret = list_tags(&filter, sorting, format); + ret = list_tags(&filter, sorting, &format); if (column_active(colopts)) stop_column_filter(); return ret; @@ -501,9 +483,9 @@ int cmd_tag(int argc, const char **argv, const char *prefix) if (cmdmode == 'd') return for_each_tag_name(argv, delete_tag, NULL); if (cmdmode == 'v') { - if (format) - verify_ref_format(format); - return for_each_tag_name(argv, verify_tag, format); + if (format.format && verify_ref_format(&format)) + usage_with_options(git_tag_usage, options); + return for_each_tag_name(argv, verify_tag, &format); } if (msg.given || msgfile) { diff --git a/builtin/unpack-file.c b/builtin/unpack-file.c index 73f1334191..281ca1db6c 100644 --- a/builtin/unpack-file.c +++ b/builtin/unpack-file.c @@ -1,7 +1,7 @@ #include "builtin.h" #include "config.h" -static char *create_temp_file(unsigned char *sha1) +static char *create_temp_file(struct object_id *oid) { static char path[50]; void *buf; @@ -9,9 +9,9 @@ static char *create_temp_file(unsigned char *sha1) unsigned long size; int fd; - buf = read_sha1_file(sha1, &type, &size); + buf = read_sha1_file(oid->hash, &type, &size); if (!buf || type != OBJ_BLOB) - die("unable to read blob object %s", sha1_to_hex(sha1)); + die("unable to read blob object %s", oid_to_hex(oid)); xsnprintf(path, sizeof(path), ".merge_file_XXXXXX"); fd = xmkstemp(path); @@ -23,15 +23,15 @@ static char *create_temp_file(unsigned char *sha1) int cmd_unpack_file(int argc, const char **argv, const char *prefix) { - unsigned char sha1[20]; + struct object_id oid; if (argc != 2 || !strcmp(argv[1], "-h")) usage("git unpack-file <sha1>"); - if (get_sha1(argv[1], sha1)) + if (get_oid(argv[1], &oid)) die("Not a valid object name %s", argv[1]); git_config(git_default_config, NULL); - puts(create_temp_file(sha1)); + puts(create_temp_file(&oid)); return 0; } diff --git a/builtin/update-ref.c b/builtin/update-ref.c index 40ccfc193b..6b90c5dead 100644 --- a/builtin/update-ref.c +++ b/builtin/update-ref.c @@ -94,10 +94,10 @@ static char *parse_refname(struct strbuf *input, const char **next) * provided but cannot be converted to a SHA-1, die. flags can * include PARSE_SHA1_OLD and/or PARSE_SHA1_ALLOW_EMPTY. */ -static int parse_next_sha1(struct strbuf *input, const char **next, - unsigned char *sha1, - const char *command, const char *refname, - int flags) +static int parse_next_oid(struct strbuf *input, const char **next, + struct object_id *oid, + const char *command, const char *refname, + int flags) { struct strbuf arg = STRBUF_INIT; int ret = 0; @@ -115,11 +115,11 @@ static int parse_next_sha1(struct strbuf *input, const char **next, (*next)++; *next = parse_arg(*next, &arg); if (arg.len) { - if (get_sha1(arg.buf, sha1)) + if (get_oid(arg.buf, oid)) goto invalid; } else { /* Without -z, an empty value means all zeros: */ - hashclr(sha1); + oidclr(oid); } } else { /* With -z, read the next NUL-terminated line */ @@ -133,13 +133,13 @@ static int parse_next_sha1(struct strbuf *input, const char **next, *next += arg.len; if (arg.len) { - if (get_sha1(arg.buf, sha1)) + if (get_oid(arg.buf, oid)) goto invalid; } else if (flags & PARSE_SHA1_ALLOW_EMPTY) { /* With -z, treat an empty value as all zeros: */ warning("%s %s: missing <newvalue>, treating as zero", command, refname); - hashclr(sha1); + oidclr(oid); } else { /* * With -z, an empty non-required value means @@ -182,26 +182,25 @@ static const char *parse_cmd_update(struct ref_transaction *transaction, { struct strbuf err = STRBUF_INIT; char *refname; - unsigned char new_sha1[20]; - unsigned char old_sha1[20]; + struct object_id new_oid, old_oid; int have_old; refname = parse_refname(input, &next); if (!refname) die("update: missing <ref>"); - if (parse_next_sha1(input, &next, new_sha1, "update", refname, - PARSE_SHA1_ALLOW_EMPTY)) + if (parse_next_oid(input, &next, &new_oid, "update", refname, + PARSE_SHA1_ALLOW_EMPTY)) die("update %s: missing <newvalue>", refname); - have_old = !parse_next_sha1(input, &next, old_sha1, "update", refname, - PARSE_SHA1_OLD); + have_old = !parse_next_oid(input, &next, &old_oid, "update", refname, + PARSE_SHA1_OLD); if (*next != line_termination) die("update %s: extra input: %s", refname, next); if (ref_transaction_update(transaction, refname, - new_sha1, have_old ? old_sha1 : NULL, + new_oid.hash, have_old ? old_oid.hash : NULL, update_flags | create_reflog_flag, msg, &err)) die("%s", err.buf); @@ -218,22 +217,22 @@ static const char *parse_cmd_create(struct ref_transaction *transaction, { struct strbuf err = STRBUF_INIT; char *refname; - unsigned char new_sha1[20]; + struct object_id new_oid; refname = parse_refname(input, &next); if (!refname) die("create: missing <ref>"); - if (parse_next_sha1(input, &next, new_sha1, "create", refname, 0)) + if (parse_next_oid(input, &next, &new_oid, "create", refname, 0)) die("create %s: missing <newvalue>", refname); - if (is_null_sha1(new_sha1)) + if (is_null_oid(&new_oid)) die("create %s: zero <newvalue>", refname); if (*next != line_termination) die("create %s: extra input: %s", refname, next); - if (ref_transaction_create(transaction, refname, new_sha1, + if (ref_transaction_create(transaction, refname, new_oid.hash, update_flags | create_reflog_flag, msg, &err)) die("%s", err.buf); @@ -250,18 +249,18 @@ static const char *parse_cmd_delete(struct ref_transaction *transaction, { struct strbuf err = STRBUF_INIT; char *refname; - unsigned char old_sha1[20]; + struct object_id old_oid; int have_old; refname = parse_refname(input, &next); if (!refname) die("delete: missing <ref>"); - if (parse_next_sha1(input, &next, old_sha1, "delete", refname, - PARSE_SHA1_OLD)) { + if (parse_next_oid(input, &next, &old_oid, "delete", refname, + PARSE_SHA1_OLD)) { have_old = 0; } else { - if (is_null_sha1(old_sha1)) + if (is_null_oid(&old_oid)) die("delete %s: zero <oldvalue>", refname); have_old = 1; } @@ -270,7 +269,7 @@ static const char *parse_cmd_delete(struct ref_transaction *transaction, die("delete %s: extra input: %s", refname, next); if (ref_transaction_delete(transaction, refname, - have_old ? old_sha1 : NULL, + have_old ? old_oid.hash : NULL, update_flags, msg, &err)) die("%s", err.buf); @@ -286,20 +285,20 @@ static const char *parse_cmd_verify(struct ref_transaction *transaction, { struct strbuf err = STRBUF_INIT; char *refname; - unsigned char old_sha1[20]; + struct object_id old_oid; refname = parse_refname(input, &next); if (!refname) die("verify: missing <ref>"); - if (parse_next_sha1(input, &next, old_sha1, "verify", refname, - PARSE_SHA1_OLD)) - hashclr(old_sha1); + if (parse_next_oid(input, &next, &old_oid, "verify", refname, + PARSE_SHA1_OLD)) + oidclr(&old_oid); if (*next != line_termination) die("verify %s: extra input: %s", refname, next); - if (ref_transaction_verify(transaction, refname, old_sha1, + if (ref_transaction_verify(transaction, refname, old_oid.hash, update_flags, &err)) die("%s", err.buf); @@ -355,7 +354,7 @@ static void update_refs_stdin(struct ref_transaction *transaction) int cmd_update_ref(int argc, const char **argv, const char *prefix) { const char *refname, *oldval; - unsigned char sha1[20], oldsha1[20]; + struct object_id oid, oldoid; int delete = 0, no_deref = 0, read_stdin = 0, end_null = 0; unsigned int flags = 0; int create_reflog = 0; @@ -412,7 +411,7 @@ int cmd_update_ref(int argc, const char **argv, const char *prefix) refname = argv[0]; value = argv[1]; oldval = argv[2]; - if (get_sha1(value, sha1)) + if (get_oid(value, &oid)) die("%s: not a valid SHA1", value); } @@ -422,8 +421,8 @@ int cmd_update_ref(int argc, const char **argv, const char *prefix) * The empty string implies that the reference * must not already exist: */ - hashclr(oldsha1); - else if (get_sha1(oldval, oldsha1)) + oidclr(&oldoid); + else if (get_oid(oldval, &oldoid)) die("%s: not a valid old SHA1", oldval); } @@ -435,10 +434,10 @@ int cmd_update_ref(int argc, const char **argv, const char *prefix) * NULL_SHA1 as "don't care" here: */ return delete_ref(msg, refname, - (oldval && !is_null_sha1(oldsha1)) ? oldsha1 : NULL, + (oldval && !is_null_oid(&oldoid)) ? oldoid.hash : NULL, flags); else - return update_ref(msg, refname, sha1, oldval ? oldsha1 : NULL, + return update_ref(msg, refname, oid.hash, oldval ? oldoid.hash : NULL, flags | create_reflog_flag, UPDATE_REFS_DIE_ON_ERR); } diff --git a/builtin/verify-tag.c b/builtin/verify-tag.c index f9a5f7535a..ad7b79fa5c 100644 --- a/builtin/verify-tag.c +++ b/builtin/verify-tag.c @@ -32,11 +32,11 @@ int cmd_verify_tag(int argc, const char **argv, const char *prefix) { int i = 1, verbose = 0, had_error = 0; unsigned flags = 0; - char *fmt_pretty = NULL; + struct ref_format format = REF_FORMAT_INIT; const struct option verify_tag_options[] = { OPT__VERBOSE(&verbose, N_("print tag contents")), OPT_BIT(0, "raw", &flags, N_("print raw gpg status output"), GPG_VERIFY_RAW), - OPT_STRING( 0 , "format", &fmt_pretty, N_("format"), N_("format to use for the output")), + OPT_STRING(0, "format", &format.format, N_("format"), N_("format to use for the output")), OPT_END() }; @@ -50,26 +50,29 @@ int cmd_verify_tag(int argc, const char **argv, const char *prefix) if (verbose) flags |= GPG_VERIFY_VERBOSE; - if (fmt_pretty) { - verify_ref_format(fmt_pretty); + if (format.format) { + if (verify_ref_format(&format)) + usage_with_options(verify_tag_usage, + verify_tag_options); flags |= GPG_VERIFY_OMIT_STATUS; } while (i < argc) { - unsigned char sha1[20]; + struct object_id oid; const char *name = argv[i++]; - if (get_sha1(name, sha1)) { + + if (get_oid(name, &oid)) { had_error = !!error("tag '%s' not found.", name); continue; } - if (gpg_verify_tag(sha1, name, flags)) { + if (gpg_verify_tag(&oid, name, flags)) { had_error = 1; continue; } - if (fmt_pretty) - pretty_print_ref(name, sha1, fmt_pretty); + if (format.format) + pretty_print_ref(name, oid.hash, &format); } return had_error; } |