From: Junio C Hamano Date: Fri, 19 Oct 2018 04:34:02 +0000 (+0900) Subject: Merge branch 'nd/the-index' X-Git-Tag: v2.20.0-rc0~164 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/11877b9ebec87175a9cc55676311ef2d98585cca Merge branch 'nd/the-index' Various codepaths in the core-ish part learn to work on an arbitrary in-core index structure, not necessarily the default instance "the_index". * nd/the-index: (23 commits) revision.c: reduce implicit dependency the_repository revision.c: remove implicit dependency on the_index ws.c: remove implicit dependency on the_index tree-diff.c: remove implicit dependency on the_index submodule.c: remove implicit dependency on the_index line-range.c: remove implicit dependency on the_index userdiff.c: remove implicit dependency on the_index rerere.c: remove implicit dependency on the_index sha1-file.c: remove implicit dependency on the_index patch-ids.c: remove implicit dependency on the_index merge.c: remove implicit dependency on the_index merge-blobs.c: remove implicit dependency on the_index ll-merge.c: remove implicit dependency on the_index diff-lib.c: remove implicit dependency on the_index read-cache.c: remove implicit dependency on the_index diff.c: remove implicit dependency on the_index grep.c: remove implicit dependency on the_index diff.c: remove the_index dependency in textconv() functions blame.c: rename "repo" argument to "r" combine-diff.c: remove implicit dependency on the_index ... --- 11877b9ebec87175a9cc55676311ef2d98585cca diff --cc blame.c index d5f7b7237c,c229a10c0e..d84c937780 --- a/blame.c +++ b/blame.c @@@ -1454,10 -1457,10 +1457,10 @@@ static void pass_blame(struct blame_sco continue; if (parse_commit(p)) continue; - porigin = find(p, origin); + porigin = find(sb->repo, p, origin); if (!porigin) continue; - if (!oidcmp(&porigin->blob_oid, &origin->blob_oid)) { + if (oideq(&porigin->blob_oid, &origin->blob_oid)) { pass_whole_blame(sb, origin, porigin); blame_origin_decref(porigin); goto finish; diff --cc builtin/commit.c index 1d5292e4d8,9d8ce6cb3b..79d557fb2b --- a/builtin/commit.c +++ b/builtin/commit.c @@@ -1654,10 -1651,7 +1654,10 @@@ int cmd_commit(int argc, const char **a "new_index file. Check that disk is not full and quota is\n" "not exceeded, and then \"git reset HEAD\" to recover.")); + if (git_env_bool(GIT_TEST_COMMIT_GRAPH, 0)) + write_commit_graph_reachable(get_object_directory(), 0, 0); + - rerere(0); + repo_rerere(the_repository, 0); run_command_v_opt(argv_gc_auto, RUN_GIT_CMD); run_commit_hook(use_editor, get_index_file(), "post-commit", NULL); if (amend && !no_post_rewrite) { diff --cc builtin/range-diff.c index 96af537493,1c477c4dc5..f01a0be851 --- a/builtin/range-diff.c +++ b/builtin/range-diff.c @@@ -28,7 -34,12 +28,7 @@@ int cmd_range_diff(int argc, const cha git_config(git_diff_ui_config, NULL); - diff_setup(&diffopt); + repo_diff_setup(the_repository, &diffopt); - diffopt.output_format = DIFF_FORMAT_PATCH; - diffopt.flags.suppress_diff_headers = 1; - diffopt.output_prefix = output_prefix_cb; - strbuf_addstr(&four_spaces, " "); - diffopt.output_prefix_data = &four_spaces; argc = parse_options(argc, argv, NULL, options, builtin_range_diff_usage, PARSE_OPT_KEEP_UNKNOWN | diff --cc builtin/rerere.c index 5ed941b91f,1ca271b711..e89ccbc524 --- a/builtin/rerere.c +++ b/builtin/rerere.c @@@ -75,10 -75,10 +75,10 @@@ int cmd_rerere(int argc, const char **a if (!strcmp(argv[0], "forget")) { struct pathspec pathspec; if (argc < 2) - warning("'git rerere forget' without paths is deprecated"); + warning(_("'git rerere forget' without paths is deprecated")); parse_pathspec(&pathspec, 0, PATHSPEC_PREFER_CWD, prefix, argv + 1); - return rerere_forget(&pathspec); + return rerere_forget(the_repository, &pathspec); } if (!strcmp(argv[0], "clear")) { diff --cc diff.c index f0c7557b40,c5b5e7ac41..42ba9e48d7 --- a/diff.c +++ b/diff.c @@@ -3580,9 -3578,10 +3589,10 @@@ static void builtin_diffstat(const cha return; } - same_contents = !oidcmp(&one->oid, &two->oid); + same_contents = oideq(&one->oid, &two->oid); - if (diff_filespec_is_binary(one) || diff_filespec_is_binary(two)) { + if (diff_filespec_is_binary(o->repo, one) || + diff_filespec_is_binary(o->repo, two)) { data->is_binary = 1; if (same_contents) { data->added = 0; @@@ -4385,10 -4401,8 +4412,11 @@@ void repo_diff_setup(struct repository memcpy(options, &default_diff_options, sizeof(*options)); options->file = stdout; + options->repo = r; + options->output_indicators[OUTPUT_INDICATOR_NEW] = '+'; + options->output_indicators[OUTPUT_INDICATOR_OLD] = '-'; + options->output_indicators[OUTPUT_INDICATOR_CONTEXT] = ' '; options->abbrev = DEFAULT_ABBREV; options->line_termination = '\n'; options->break_opt = -1; diff --cc diffcore-break.c index e11fcfdb39,b580d92154..875aefd3fe --- a/diffcore-break.c +++ b/diffcore-break.c @@@ -58,10 -59,11 +59,11 @@@ static int should_break(struct reposito } if (src->oid_valid && dst->oid_valid && - !oidcmp(&src->oid, &dst->oid)) + oideq(&src->oid, &dst->oid)) return 0; /* they are the same */ - if (diff_populate_filespec(src, 0) || diff_populate_filespec(dst, 0)) + if (diff_populate_filespec(r, src, 0) || + diff_populate_filespec(r, dst, 0)) return 0; /* error but caught downstream */ max_size = ((src->size > dst->size) ? src->size : dst->size); diff --cc ll-merge.c index 1936fee9e1,c339ef8ae8..3c8fb917e9 --- a/ll-merge.c +++ b/ll-merge.c @@@ -371,12 -372,13 +372,12 @@@ int ll_merge(mmbuffer_t *result_buf if (!check) check = attr_check_initl("merge", "conflict-marker-size", NULL); - git_check_attr(&the_index, path, check); - if (!git_check_attr(istate, path, check)) { - ll_driver_name = check->items[0].value; - if (check->items[1].value) { - marker_size = atoi(check->items[1].value); - if (marker_size <= 0) - marker_size = DEFAULT_CONFLICT_MARKER_SIZE; - } ++ git_check_attr(istate, path, check); + ll_driver_name = check->items[0].value; + if (check->items[1].value) { + marker_size = atoi(check->items[1].value); + if (marker_size <= 0) + marker_size = DEFAULT_CONFLICT_MARKER_SIZE; } driver = find_ll_merge_driver(ll_driver_name); @@@ -397,8 -399,7 +398,8 @@@ int ll_merge_marker_size(struct index_s if (!check) check = attr_check_initl("conflict-marker-size", NULL); - git_check_attr(&the_index, path, check); - if (!git_check_attr(istate, path, check) && check->items[0].value) { ++ git_check_attr(istate, path, check); + if (check->items[0].value) { marker_size = atoi(check->items[0].value); if (marker_size <= 0) marker_size = DEFAULT_CONFLICT_MARKER_SIZE; diff --cc patch-ids.c index 960ea24054,7da86047d9..c262e1be9c --- a/patch-ids.c +++ b/patch-ids.c @@@ -53,13 -53,13 +53,13 @@@ static int patch_id_neq(const void *cmp commit_patch_id(b->commit, opt, &b->patch_id, 0)) return error("Could not get patch ID for %s", oid_to_hex(&b->commit->object.oid)); - return oidcmp(&a->patch_id, &b->patch_id); + return !oideq(&a->patch_id, &b->patch_id); } - int init_patch_ids(struct patch_ids *ids) + int init_patch_ids(struct repository *r, struct patch_ids *ids) { memset(ids, 0, sizeof(*ids)); - diff_setup(&ids->diffopts); + repo_diff_setup(r, &ids->diffopts); ids->diffopts.detect_rename = 0; ids->diffopts.flags.recursive = 1; diff_setup_done(&ids->diffopts); diff --cc read-cache.c index 8d04d78a58,b707edd044..01859b7703 --- a/read-cache.c +++ b/read-cache.c @@@ -212,8 -214,8 +214,8 @@@ static int ce_compare_data(struct index if (fd >= 0) { struct object_id oid; - if (!index_fd(&oid, fd, st, OBJ_BLOB, ce->name, 0)) + if (!index_fd(istate, &oid, fd, st, OBJ_BLOB, ce->name, 0)) - match = oidcmp(&oid, &ce->oid); + match = !oideq(&oid, &ce->oid); /* index_fd() closed the file descriptor already */ } return match; @@@ -254,10 -256,12 +256,12 @@@ static int ce_compare_gitlink(const str */ if (resolve_gitlink_ref(ce->name, "HEAD", &oid) < 0) return 0; - return oidcmp(&oid, &ce->oid); + return !oideq(&oid, &ce->oid); } - static int ce_modified_check_fs(const struct cache_entry *ce, struct stat *st) + static int ce_modified_check_fs(struct index_state *istate, + const struct cache_entry *ce, + struct stat *st) { switch (st->st_mode & S_IFMT) { case S_IFREG: diff --cc rerere.c index 7aa149e849,8d4ac8426b..887e26d45b --- a/rerere.c +++ b/rerere.c @@@ -462,11 -474,12 +462,12 @@@ static int handle_path(unsigned char *s * Scan the path for conflicts, do the "handle_path()" thing above, and * return the number of conflict hunks found. */ - static int handle_file(const char *path, unsigned char *sha1, const char *output) + static int handle_file(struct index_state *istate, const char *path, + unsigned char *sha1, const char *output) { - int hunk_no = 0; + int has_conflicts = 0; struct rerere_io_file io; - int marker_size = ll_merge_marker_size(path); + int marker_size = ll_merge_marker_size(istate, path); memset(&io, 0, sizeof(io)); io.io.getline = rerere_file_getline; @@@ -521,7 -534,7 +522,7 @@@ static int check_one_conflict(struct in } *type = PUNTED; - while (i < active_nr && ce_stage(active_cache[i]) == 1) - while (ce_stage(istate->cache[i]) == 1) ++ while (i < istate->cache_nr && ce_stage(istate->cache[i]) == 1) i++; /* Only handle regular files with both stages #2 and #3 */ @@@ -553,16 -566,17 +554,17 @@@ * are identical to the previous round, might want to be handled, * though. */ - static int find_conflict(struct string_list *conflict) + static int find_conflict(struct repository *r, struct string_list *conflict) { int i; - if (read_cache() < 0) + + if (read_index(r->index) < 0) - return error("Could not read index"); + return error(_("index file corrupt")); - for (i = 0; i < active_nr;) { + for (i = 0; i < r->index->cache_nr;) { int conflict_type; - const struct cache_entry *e = active_cache[i]; - i = check_one_conflict(i, &conflict_type); + const struct cache_entry *e = r->index->cache[i]; + i = check_one_conflict(r->index, i, &conflict_type); if (conflict_type == THREE_STAGED) string_list_insert(conflict, (const char *)e->name); } @@@ -584,18 -598,19 +586,19 @@@ * NEEDSWORK: we may want to fix the caller that implements "rerere * remaining" to do this without abusing merge_rr. */ - int rerere_remaining(struct string_list *merge_rr) + int rerere_remaining(struct repository *r, struct string_list *merge_rr) { int i; + if (setup_rerere(merge_rr, RERERE_READONLY)) return 0; - if (read_cache() < 0) + if (read_index(r->index) < 0) - return error("Could not read index"); + return error(_("index file corrupt")); - for (i = 0; i < active_nr;) { + for (i = 0; i < r->index->cache_nr;) { int conflict_type; - const struct cache_entry *e = active_cache[i]; - i = check_one_conflict(i, &conflict_type); + const struct cache_entry *e = r->index->cache[i]; + i = check_one_conflict(r->index, i, &conflict_type); if (conflict_type == PUNTED) string_list_insert(merge_rr, (const char *)e->name); else if (conflict_type == RESOLVED) { @@@ -701,15 -718,15 +706,15 @@@ static void update_paths(struct reposit for (i = 0; i < update->nr; i++) { struct string_list_item *item = &update->items[i]; - if (add_file_to_cache(item->string, 0)) + if (add_file_to_index(r->index, item->string, 0)) exit(128); - fprintf(stderr, "Staged '%s' using previous resolution.\n", + fprintf_ln(stderr, _("Staged '%s' using previous resolution."), item->string); } - if (write_locked_index(&the_index, &index_lock, + if (write_locked_index(r->index, &index_lock, COMMIT_LOCK | SKIP_IF_UNCHANGED)) - die("Unable to write new index file"); + die(_("unable to write new index file")); } static void remove_variant(struct rerere_id *id) @@@ -738,10 -756,10 +744,10 @@@ static void do_rerere_one_path(struct i /* Has the user resolved it already? */ if (variant >= 0) { - if (!handle_file(path, NULL, NULL)) { + if (!handle_file(istate, path, NULL, NULL)) { copy_file(rerere_path(id, "postimage"), path, 0666); id->collection->status[variant] |= RR_HAS_POSTIMAGE; - fprintf(stderr, "Recorded resolution for '%s'.\n", path); + fprintf_ln(stderr, _("Recorded resolution for '%s'."), path); free_rerere_id(rr_item); rr_item->util = NULL; return; @@@ -795,10 -813,11 +801,11 @@@ id->collection->status[variant] &= ~RR_HAS_POSTIMAGE; } id->collection->status[variant] |= RR_HAS_PREIMAGE; - fprintf(stderr, "Recorded preimage for '%s'\n", path); + fprintf_ln(stderr, _("Recorded preimage for '%s'"), path); } - static int do_plain_rerere(struct string_list *rr, int fd) + static int do_plain_rerere(struct repository *r, + struct string_list *rr, int fd) { struct string_list conflict = STRING_LIST_INIT_DUP; struct string_list update = STRING_LIST_INIT_DUP; @@@ -823,11 -845,7 +830,11 @@@ * conflict ID. No need to write anything out * yet. */ - ret = handle_file(path, sha1, NULL); + ret = handle_file(r->index, path, sha1, NULL); + if (ret != 0 && string_list_has_string(rr, path)) { + remove_variant(string_list_lookup(rr, path)->util); + string_list_remove(rr, path, 1); + } if (ret < 1) continue; @@@ -947,9 -966,9 +955,9 @@@ static int handle_cache(struct index_st mmfile_t mmfile[3] = {{NULL}}; mmbuffer_t result = {NULL, 0}; const struct cache_entry *ce; - int pos, len, i, hunk_no; + int pos, len, i, has_conflicts; struct rerere_io_mem io; - int marker_size = ll_merge_marker_size(path); + int marker_size = ll_merge_marker_size(istate, path); /* * Reproduce the conflicted merge in-core @@@ -1005,10 -1025,12 +1014,12 @@@ strbuf_release(&io.input); if (io.io.output) fclose(io.io.output); - return hunk_no; + return has_conflicts; } - static int rerere_forget_one_path(const char *path, struct string_list *rr) + static int rerere_forget_one_path(struct index_state *istate, + const char *path, + struct string_list *rr) { const char *filename; struct rerere_id *id; @@@ -1020,9 -1042,9 +1031,9 @@@ * Recreate the original conflict from the stages in the * index and compute the conflict ID */ - ret = handle_cache(path, sha1, NULL); + ret = handle_cache(istate, path, sha1, NULL); if (ret < 1) - return error("Could not parse conflict hunks in '%s'", path); + return error(_("could not parse conflict hunks in '%s'"), path); /* Nuke the recorded resolution for the conflict */ id = new_rerere_id(sha1); @@@ -1037,13 -1059,13 +1048,13 @@@ if (!has_rerere_resolution(id)) continue; - handle_cache(path, sha1, rerere_path(id, "thisimage")); + handle_cache(istate, path, sha1, rerere_path(id, "thisimage")); if (read_mmfile(&cur, rerere_path(id, "thisimage"))) { free(cur.ptr); - error("Failed to update conflicted state in '%s'", path); + error(_("failed to update conflicted state in '%s'"), path); goto fail_exit; } - cleanly_resolved = !try_merge(id, path, &cur, &result); + cleanly_resolved = !try_merge(istate, id, path, &cur, &result); free(result.ptr); free(cur.ptr); if (cleanly_resolved) @@@ -1069,8 -1091,8 +1080,8 @@@ * conflict in the working tree, run us again to record * the postimage. */ - handle_cache(path, sha1, rerere_path(id, "preimage")); + handle_cache(istate, path, sha1, rerere_path(id, "preimage")); - fprintf(stderr, "Updated preimage for '%s'\n", path); + fprintf_ln(stderr, _("Updated preimage for '%s'"), path); /* * And remember that we can record resolution for this @@@ -1093,8 -1115,8 +1104,8 @@@ int rerere_forget(struct repository *r struct string_list conflict = STRING_LIST_INIT_DUP; struct string_list merge_rr = STRING_LIST_INIT_DUP; - if (read_cache() < 0) + if (read_index(r->index) < 0) - return error("Could not read index"); + return error(_("index file corrupt")); fd = setup_rerere(&merge_rr, RERERE_NOAUTOUPDATE); if (fd < 0) diff --cc userdiff.c index f565f6731d,c913232396..46d34cc2a4 --- a/userdiff.c +++ b/userdiff.c @@@ -278,7 -279,8 +279,7 @@@ struct userdiff_driver *userdiff_find_b check = attr_check_initl("diff", NULL); if (!path) return NULL; - git_check_attr(&the_index, path, check); - if (git_check_attr(istate, path, check)) - return NULL; ++ git_check_attr(istate, path, check); if (ATTR_TRUE(check->items[0].value)) return &driver_true; diff --cc ws.c index a64ab51e09,55349b4c5d..6e69877f25 --- a/ws.c +++ b/ws.c @@@ -71,34 -70,38 +70,34 @@@ unsigned parse_whitespace_rule(const ch return rule; } - unsigned whitespace_rule(const char *pathname) + unsigned whitespace_rule(struct index_state *istate, const char *pathname) { static struct attr_check *attr_whitespace_rule; + const char *value; if (!attr_whitespace_rule) attr_whitespace_rule = attr_check_initl("whitespace", NULL); - git_check_attr(&the_index, pathname, attr_whitespace_rule); - if (!git_check_attr(istate, pathname, attr_whitespace_rule)) { - const char *value; - - value = attr_whitespace_rule->items[0].value; - if (ATTR_TRUE(value)) { - /* true (whitespace) */ - unsigned all_rule = ws_tab_width(whitespace_rule_cfg); - int i; - for (i = 0; i < ARRAY_SIZE(whitespace_rule_names); i++) - if (!whitespace_rule_names[i].loosens_error && - !whitespace_rule_names[i].exclude_default) - all_rule |= whitespace_rule_names[i].rule_bits; - return all_rule; - } else if (ATTR_FALSE(value)) { - /* false (-whitespace) */ - return ws_tab_width(whitespace_rule_cfg); - } else if (ATTR_UNSET(value)) { - /* reset to default (!whitespace) */ - return whitespace_rule_cfg; - } else { - /* string */ - return parse_whitespace_rule(value); - } - } else { ++ git_check_attr(istate, pathname, attr_whitespace_rule); + value = attr_whitespace_rule->items[0].value; + if (ATTR_TRUE(value)) { + /* true (whitespace) */ + unsigned all_rule = ws_tab_width(whitespace_rule_cfg); + int i; + for (i = 0; i < ARRAY_SIZE(whitespace_rule_names); i++) + if (!whitespace_rule_names[i].loosens_error && + !whitespace_rule_names[i].exclude_default) + all_rule |= whitespace_rule_names[i].rule_bits; + return all_rule; + } else if (ATTR_FALSE(value)) { + /* false (-whitespace) */ + return ws_tab_width(whitespace_rule_cfg); + } else if (ATTR_UNSET(value)) { + /* reset to default (!whitespace) */ return whitespace_rule_cfg; + } else { + /* string */ + return parse_whitespace_rule(value); } }