提交 99d1a986 编写于 作者: B brian m. carlson 提交者: Junio C Hamano

cache: convert struct cache_entry to use struct object_id

Convert struct cache_entry to use struct object_id by applying the
following semantic patch and the object_id transforms from contrib, plus
the actual change to the struct:

@@
struct cache_entry E1;
@@
- E1.sha1
+ E1.oid.hash

@@
struct cache_entry *E1;
@@
- E1->sha1
+ E1->oid.hash
Signed-off-by: Nbrian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: NJunio C Hamano <gitster@pobox.com>
上级 6ebdac1b
...@@ -3220,7 +3220,7 @@ static int read_file_or_gitlink(const struct cache_entry *ce, struct strbuf *buf ...@@ -3220,7 +3220,7 @@ static int read_file_or_gitlink(const struct cache_entry *ce, struct strbuf *buf
{ {
if (!ce) if (!ce)
return 0; return 0;
return read_blob_object(buf, ce->sha1, ce->ce_mode); return read_blob_object(buf, ce->oid.hash, ce->ce_mode);
} }
static struct patch *in_fn_table(struct apply_state *state, const char *name) static struct patch *in_fn_table(struct apply_state *state, const char *name)
...@@ -3959,7 +3959,7 @@ static int get_current_sha1(const char *path, unsigned char *sha1) ...@@ -3959,7 +3959,7 @@ static int get_current_sha1(const char *path, unsigned char *sha1)
pos = cache_name_pos(path, strlen(path)); pos = cache_name_pos(path, strlen(path));
if (pos < 0) if (pos < 0)
return -1; return -1;
hashcpy(sha1, active_cache[pos]->sha1); hashcpy(sha1, active_cache[pos]->oid.hash);
return 0; return 0;
} }
...@@ -4211,7 +4211,7 @@ static void add_index_file(struct apply_state *state, ...@@ -4211,7 +4211,7 @@ static void add_index_file(struct apply_state *state,
const char *s; const char *s;
if (!skip_prefix(buf, "Subproject commit ", &s) || if (!skip_prefix(buf, "Subproject commit ", &s) ||
get_sha1_hex(s, ce->sha1)) get_sha1_hex(s, ce->oid.hash))
die(_("corrupt patch for submodule %s"), path); die(_("corrupt patch for submodule %s"), path);
} else { } else {
if (!state->cached) { if (!state->cached) {
...@@ -4220,7 +4220,7 @@ static void add_index_file(struct apply_state *state, ...@@ -4220,7 +4220,7 @@ static void add_index_file(struct apply_state *state,
path); path);
fill_stat_cache_info(ce, &st); fill_stat_cache_info(ce, &st);
} }
if (write_sha1_file(buf, size, blob_type, ce->sha1) < 0) if (write_sha1_file(buf, size, blob_type, ce->oid.hash) < 0)
die(_("unable to create backing store for newly created file %s"), path); die(_("unable to create backing store for newly created file %s"), path);
} }
if (add_cache_entry(ce, ADD_CACHE_OK_TO_ADD) < 0) if (add_cache_entry(ce, ADD_CACHE_OK_TO_ADD) < 0)
...@@ -4335,7 +4335,7 @@ static void add_conflicted_stages_file(struct apply_state *state, ...@@ -4335,7 +4335,7 @@ static void add_conflicted_stages_file(struct apply_state *state,
ce->ce_mode = create_ce_mode(mode); ce->ce_mode = create_ce_mode(mode);
ce->ce_flags = create_ce_flags(stage); ce->ce_flags = create_ce_flags(stage);
ce->ce_namelen = namelen; ce->ce_namelen = namelen;
hashcpy(ce->sha1, patch->threeway_stage[stage - 1].hash); oidcpy(&ce->oid, &patch->threeway_stage[stage - 1]);
if (add_cache_entry(ce, ADD_CACHE_OK_TO_ADD) < 0) if (add_cache_entry(ce, ADD_CACHE_OK_TO_ADD) < 0)
die(_("unable to add cache entry for %s"), patch->new_name); die(_("unable to add cache entry for %s"), patch->new_name);
} }
......
...@@ -2410,7 +2410,7 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt, ...@@ -2410,7 +2410,7 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt,
} }
size = cache_entry_size(len); size = cache_entry_size(len);
ce = xcalloc(1, size); ce = xcalloc(1, size);
hashcpy(ce->sha1, origin->blob_sha1); hashcpy(ce->oid.hash, origin->blob_sha1);
memcpy(ce->name, path, len); memcpy(ce->name, path, len);
ce->ce_flags = create_ce_flags(0); ce->ce_flags = create_ce_flags(0);
ce->ce_namelen = len; ce->ce_namelen = len;
......
...@@ -76,7 +76,7 @@ static int update_some(const unsigned char *sha1, struct strbuf *base, ...@@ -76,7 +76,7 @@ static int update_some(const unsigned char *sha1, struct strbuf *base,
len = base->len + strlen(pathname); len = base->len + strlen(pathname);
ce = xcalloc(1, cache_entry_size(len)); ce = xcalloc(1, cache_entry_size(len));
hashcpy(ce->sha1, sha1); hashcpy(ce->oid.hash, sha1);
memcpy(ce->name, base->buf, base->len); memcpy(ce->name, base->buf, base->len);
memcpy(ce->name + base->len, pathname, len - base->len); memcpy(ce->name + base->len, pathname, len - base->len);
ce->ce_flags = create_ce_flags(0) | CE_UPDATE; ce->ce_flags = create_ce_flags(0) | CE_UPDATE;
...@@ -92,7 +92,7 @@ static int update_some(const unsigned char *sha1, struct strbuf *base, ...@@ -92,7 +92,7 @@ static int update_some(const unsigned char *sha1, struct strbuf *base,
if (pos >= 0) { if (pos >= 0) {
struct cache_entry *old = active_cache[pos]; struct cache_entry *old = active_cache[pos];
if (ce->ce_mode == old->ce_mode && if (ce->ce_mode == old->ce_mode &&
!hashcmp(ce->sha1, old->sha1)) { !oidcmp(&ce->oid, &old->oid)) {
old->ce_flags |= CE_UPDATE; old->ce_flags |= CE_UPDATE;
free(ce); free(ce);
return 0; return 0;
...@@ -186,7 +186,7 @@ static int checkout_merged(int pos, struct checkout *state) ...@@ -186,7 +186,7 @@ static int checkout_merged(int pos, struct checkout *state)
stage = ce_stage(ce); stage = ce_stage(ce);
if (!stage || strcmp(path, ce->name)) if (!stage || strcmp(path, ce->name))
break; break;
hashcpy(threeway[stage - 1], ce->sha1); hashcpy(threeway[stage - 1], ce->oid.hash);
if (stage == 2) if (stage == 2)
mode = create_ce_mode(ce->ce_mode); mode = create_ce_mode(ce->ce_mode);
pos++; pos++;
......
...@@ -722,7 +722,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix) ...@@ -722,7 +722,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
mode = active_cache[i]->ce_mode; mode = active_cache[i]->ce_mode;
if (S_ISGITLINK(mode)) if (S_ISGITLINK(mode))
continue; continue;
blob = lookup_blob(active_cache[i]->sha1); blob = lookup_blob(active_cache[i]->oid.hash);
if (!blob) if (!blob)
continue; continue;
obj = &blob->object; obj = &blob->object;
......
...@@ -398,7 +398,8 @@ static int grep_cache(struct grep_opt *opt, const struct pathspec *pathspec, int ...@@ -398,7 +398,8 @@ static int grep_cache(struct grep_opt *opt, const struct pathspec *pathspec, int
if (cached || (ce->ce_flags & CE_VALID) || ce_skip_worktree(ce)) { if (cached || (ce->ce_flags & CE_VALID) || ce_skip_worktree(ce)) {
if (ce_stage(ce) || ce_intent_to_add(ce)) if (ce_stage(ce) || ce_intent_to_add(ce))
continue; continue;
hit |= grep_sha1(opt, ce->sha1, ce->name, 0, ce->name); hit |= grep_sha1(opt, ce->oid.hash, ce->name, 0,
ce->name);
} }
else else
hit |= grep_file(opt, ce->name); hit |= grep_file(opt, ce->name);
......
...@@ -187,7 +187,7 @@ static void show_ce_entry(const char *tag, const struct cache_entry *ce) ...@@ -187,7 +187,7 @@ static void show_ce_entry(const char *tag, const struct cache_entry *ce)
printf("%s%06o %s %d\t", printf("%s%06o %s %d\t",
tag, tag,
ce->ce_mode, ce->ce_mode,
find_unique_abbrev(ce->sha1,abbrev), find_unique_abbrev(ce->oid.hash,abbrev),
ce_stage(ce)); ce_stage(ce));
} }
write_eolinfo(ce, ce->name); write_eolinfo(ce, ce->name);
......
...@@ -22,7 +22,7 @@ static int merge_entry(int pos, const char *path) ...@@ -22,7 +22,7 @@ static int merge_entry(int pos, const char *path)
if (strcmp(ce->name, path)) if (strcmp(ce->name, path))
break; break;
found++; found++;
sha1_to_hex_r(hexbuf[stage], ce->sha1); sha1_to_hex_r(hexbuf[stage], ce->oid.hash);
xsnprintf(ownbuf[stage], sizeof(ownbuf[stage]), "%o", ce->ce_mode); xsnprintf(ownbuf[stage], sizeof(ownbuf[stage]), "%o", ce->ce_mode);
arguments[stage] = hexbuf[stage]; arguments[stage] = hexbuf[stage];
arguments[stage + 4] = ownbuf[stage]; arguments[stage + 4] = ownbuf[stage];
......
...@@ -78,7 +78,7 @@ static void debug_stage(const char *label, const struct cache_entry *ce, ...@@ -78,7 +78,7 @@ static void debug_stage(const char *label, const struct cache_entry *ce,
else else
printf("%06o #%d %s %.8s\n", printf("%06o #%d %s %.8s\n",
ce->ce_mode, ce_stage(ce), ce->name, ce->ce_mode, ce_stage(ce), ce->name,
sha1_to_hex(ce->sha1)); oid_to_hex(&ce->oid));
} }
static int debug_merge(const struct cache_entry * const *stages, static int debug_merge(const struct cache_entry * const *stages,
......
...@@ -199,7 +199,7 @@ static int check_local_mod(unsigned char *head, int index_only) ...@@ -199,7 +199,7 @@ static int check_local_mod(unsigned char *head, int index_only)
if (no_head if (no_head
|| get_tree_entry(head, name, sha1, &mode) || get_tree_entry(head, name, sha1, &mode)
|| ce->ce_mode != create_ce_mode(mode) || ce->ce_mode != create_ce_mode(mode)
|| hashcmp(ce->sha1, sha1)) || hashcmp(ce->oid.hash, sha1))
staged_changes = 1; staged_changes = 1;
/* /*
......
...@@ -296,7 +296,8 @@ static int module_list(int argc, const char **argv, const char *prefix) ...@@ -296,7 +296,8 @@ static int module_list(int argc, const char **argv, const char *prefix)
if (ce_stage(ce)) if (ce_stage(ce))
printf("%06o %s U\t", ce->ce_mode, sha1_to_hex(null_sha1)); printf("%06o %s U\t", ce->ce_mode, sha1_to_hex(null_sha1));
else else
printf("%06o %s %d\t", ce->ce_mode, sha1_to_hex(ce->sha1), ce_stage(ce)); printf("%06o %s %d\t", ce->ce_mode,
oid_to_hex(&ce->oid), ce_stage(ce));
utf8_fprintf(stdout, "%s\n", ce->name); utf8_fprintf(stdout, "%s\n", ce->name);
} }
...@@ -683,7 +684,7 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce, ...@@ -683,7 +684,7 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,
strbuf_reset(&sb); strbuf_reset(&sb);
strbuf_addf(&sb, "%06o %s %d %d\t%s\n", ce->ce_mode, strbuf_addf(&sb, "%06o %s %d %d\t%s\n", ce->ce_mode,
sha1_to_hex(ce->sha1), ce_stage(ce), oid_to_hex(&ce->oid), ce_stage(ce),
needs_cloning, ce->name); needs_cloning, ce->name);
string_list_append(&suc->projectlines, sb.buf); string_list_append(&suc->projectlines, sb.buf);
......
...@@ -275,7 +275,7 @@ static int add_one_path(const struct cache_entry *old, const char *path, int len ...@@ -275,7 +275,7 @@ static int add_one_path(const struct cache_entry *old, const char *path, int len
fill_stat_cache_info(ce, st); fill_stat_cache_info(ce, st);
ce->ce_mode = ce_mode_from_stat(old, st->st_mode); ce->ce_mode = ce_mode_from_stat(old, st->st_mode);
if (index_path(ce->sha1, path, st, if (index_path(ce->oid.hash, path, st,
info_only ? 0 : HASH_WRITE_OBJECT)) { info_only ? 0 : HASH_WRITE_OBJECT)) {
free(ce); free(ce);
return -1; return -1;
...@@ -403,7 +403,7 @@ static int add_cacheinfo(unsigned int mode, const unsigned char *sha1, ...@@ -403,7 +403,7 @@ static int add_cacheinfo(unsigned int mode, const unsigned char *sha1,
size = cache_entry_size(len); size = cache_entry_size(len);
ce = xcalloc(1, size); ce = xcalloc(1, size);
hashcpy(ce->sha1, sha1); hashcpy(ce->oid.hash, sha1);
memcpy(ce->name, path, len); memcpy(ce->name, path, len);
ce->ce_flags = create_ce_flags(stage); ce->ce_flags = create_ce_flags(stage);
ce->ce_namelen = len; ce->ce_namelen = len;
...@@ -601,7 +601,7 @@ static struct cache_entry *read_one_ent(const char *which, ...@@ -601,7 +601,7 @@ static struct cache_entry *read_one_ent(const char *which,
size = cache_entry_size(namelen); size = cache_entry_size(namelen);
ce = xcalloc(1, size); ce = xcalloc(1, size);
hashcpy(ce->sha1, sha1); hashcpy(ce->oid.hash, sha1);
memcpy(ce->name, path, namelen); memcpy(ce->name, path, namelen);
ce->ce_flags = create_ce_flags(stage); ce->ce_flags = create_ce_flags(stage);
ce->ce_namelen = namelen; ce->ce_namelen = namelen;
...@@ -658,7 +658,7 @@ static int unresolve_one(const char *path) ...@@ -658,7 +658,7 @@ static int unresolve_one(const char *path)
ret = -1; ret = -1;
goto free_return; goto free_return;
} }
if (!hashcmp(ce_2->sha1, ce_3->sha1) && if (!oidcmp(&ce_2->oid, &ce_3->oid) &&
ce_2->ce_mode == ce_3->ce_mode) { ce_2->ce_mode == ce_3->ce_mode) {
fprintf(stderr, "%s: identical in both, skipping.\n", fprintf(stderr, "%s: identical in both, skipping.\n",
path); path);
...@@ -743,7 +743,7 @@ static int do_reupdate(int ac, const char **av, ...@@ -743,7 +743,7 @@ static int do_reupdate(int ac, const char **av,
old = read_one_ent(NULL, head_sha1, old = read_one_ent(NULL, head_sha1,
ce->name, ce_namelen(ce), 0); ce->name, ce_namelen(ce), 0);
if (old && ce->ce_mode == old->ce_mode && if (old && ce->ce_mode == old->ce_mode &&
!hashcmp(ce->sha1, old->sha1)) { !oidcmp(&ce->oid, &old->oid)) {
free(old); free(old);
continue; /* unchanged */ continue; /* unchanged */
} }
......
...@@ -168,7 +168,7 @@ static int verify_cache(struct cache_entry **cache, ...@@ -168,7 +168,7 @@ static int verify_cache(struct cache_entry **cache,
break; break;
} }
fprintf(stderr, "%s: unmerged (%s)\n", fprintf(stderr, "%s: unmerged (%s)\n",
ce->name, sha1_to_hex(ce->sha1)); ce->name, oid_to_hex(&ce->oid));
} }
} }
if (funny) if (funny)
...@@ -349,7 +349,7 @@ static int update_one(struct cache_tree *it, ...@@ -349,7 +349,7 @@ static int update_one(struct cache_tree *it,
} }
} }
else { else {
sha1 = ce->sha1; sha1 = ce->oid.hash;
mode = ce->ce_mode; mode = ce->ce_mode;
entlen = pathlen - baselen; entlen = pathlen - baselen;
i++; i++;
......
...@@ -173,7 +173,7 @@ struct cache_entry { ...@@ -173,7 +173,7 @@ struct cache_entry {
unsigned int ce_flags; unsigned int ce_flags;
unsigned int ce_namelen; unsigned int ce_namelen;
unsigned int index; /* for link extension */ unsigned int index; /* for link extension */
unsigned char sha1[20]; struct object_id oid;
char name[FLEX_ARRAY]; /* more */ char name[FLEX_ARRAY]; /* more */
}; };
......
...@@ -155,7 +155,8 @@ int run_diff_files(struct rev_info *revs, unsigned int option) ...@@ -155,7 +155,8 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
if (2 <= stage) { if (2 <= stage) {
int mode = nce->ce_mode; int mode = nce->ce_mode;
num_compare_stages++; num_compare_stages++;
hashcpy(dpath->parent[stage-2].oid.hash, nce->sha1); oidcpy(&dpath->parent[stage - 2].oid,
&nce->oid);
dpath->parent[stage-2].mode = ce_mode_from_stat(nce, mode); dpath->parent[stage-2].mode = ce_mode_from_stat(nce, mode);
dpath->parent[stage-2].status = dpath->parent[stage-2].status =
DIFF_STATUS_MODIFIED; DIFF_STATUS_MODIFIED;
...@@ -209,7 +210,8 @@ int run_diff_files(struct rev_info *revs, unsigned int option) ...@@ -209,7 +210,8 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
continue; continue;
} }
diff_addremove(&revs->diffopt, '-', ce->ce_mode, diff_addremove(&revs->diffopt, '-', ce->ce_mode,
ce->sha1, !is_null_sha1(ce->sha1), ce->oid.hash,
!is_null_oid(&ce->oid),
ce->name, 0); ce->name, 0);
continue; continue;
} }
...@@ -225,8 +227,8 @@ int run_diff_files(struct rev_info *revs, unsigned int option) ...@@ -225,8 +227,8 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
continue; continue;
} }
oldmode = ce->ce_mode; oldmode = ce->ce_mode;
old_sha1 = ce->sha1; old_sha1 = ce->oid.hash;
new_sha1 = changed ? null_sha1 : ce->sha1; new_sha1 = changed ? null_sha1 : ce->oid.hash;
diff_change(&revs->diffopt, oldmode, newmode, diff_change(&revs->diffopt, oldmode, newmode,
old_sha1, new_sha1, old_sha1, new_sha1,
!is_null_sha1(old_sha1), !is_null_sha1(old_sha1),
...@@ -261,7 +263,7 @@ static int get_stat_data(const struct cache_entry *ce, ...@@ -261,7 +263,7 @@ static int get_stat_data(const struct cache_entry *ce,
int cached, int match_missing, int cached, int match_missing,
unsigned *dirty_submodule, struct diff_options *diffopt) unsigned *dirty_submodule, struct diff_options *diffopt)
{ {
const unsigned char *sha1 = ce->sha1; const unsigned char *sha1 = ce->oid.hash;
unsigned int mode = ce->ce_mode; unsigned int mode = ce->ce_mode;
if (!cached && !ce_uptodate(ce)) { if (!cached && !ce_uptodate(ce)) {
...@@ -324,12 +326,13 @@ static int show_modified(struct rev_info *revs, ...@@ -324,12 +326,13 @@ static int show_modified(struct rev_info *revs,
&dirty_submodule, &revs->diffopt) < 0) { &dirty_submodule, &revs->diffopt) < 0) {
if (report_missing) if (report_missing)
diff_index_show_file(revs, "-", old, diff_index_show_file(revs, "-", old,
old->sha1, 1, old->ce_mode, 0); old->oid.hash, 1, old->ce_mode,
0);
return -1; return -1;
} }
if (revs->combine_merges && !cached && if (revs->combine_merges && !cached &&
(hashcmp(sha1, old->sha1) || hashcmp(old->sha1, new->sha1))) { (hashcmp(sha1, old->oid.hash) || oidcmp(&old->oid, &new->oid))) {
struct combine_diff_path *p; struct combine_diff_path *p;
int pathlen = ce_namelen(new); int pathlen = ce_namelen(new);
...@@ -343,22 +346,22 @@ static int show_modified(struct rev_info *revs, ...@@ -343,22 +346,22 @@ static int show_modified(struct rev_info *revs,
memset(p->parent, 0, 2 * sizeof(struct combine_diff_parent)); memset(p->parent, 0, 2 * sizeof(struct combine_diff_parent));
p->parent[0].status = DIFF_STATUS_MODIFIED; p->parent[0].status = DIFF_STATUS_MODIFIED;
p->parent[0].mode = new->ce_mode; p->parent[0].mode = new->ce_mode;
hashcpy(p->parent[0].oid.hash, new->sha1); oidcpy(&p->parent[0].oid, &new->oid);
p->parent[1].status = DIFF_STATUS_MODIFIED; p->parent[1].status = DIFF_STATUS_MODIFIED;
p->parent[1].mode = old->ce_mode; p->parent[1].mode = old->ce_mode;
hashcpy(p->parent[1].oid.hash, old->sha1); oidcpy(&p->parent[1].oid, &old->oid);
show_combined_diff(p, 2, revs->dense_combined_merges, revs); show_combined_diff(p, 2, revs->dense_combined_merges, revs);
free(p); free(p);
return 0; return 0;
} }
oldmode = old->ce_mode; oldmode = old->ce_mode;
if (mode == oldmode && !hashcmp(sha1, old->sha1) && !dirty_submodule && if (mode == oldmode && !hashcmp(sha1, old->oid.hash) && !dirty_submodule &&
!DIFF_OPT_TST(&revs->diffopt, FIND_COPIES_HARDER)) !DIFF_OPT_TST(&revs->diffopt, FIND_COPIES_HARDER))
return 0; return 0;
diff_change(&revs->diffopt, oldmode, mode, diff_change(&revs->diffopt, oldmode, mode,
old->sha1, sha1, 1, !is_null_sha1(sha1), old->oid.hash, sha1, 1, !is_null_sha1(sha1),
old->name, 0, dirty_submodule); old->name, 0, dirty_submodule);
return 0; return 0;
} }
...@@ -392,7 +395,8 @@ static void do_oneway_diff(struct unpack_trees_options *o, ...@@ -392,7 +395,8 @@ static void do_oneway_diff(struct unpack_trees_options *o,
struct diff_filepair *pair; struct diff_filepair *pair;
pair = diff_unmerge(&revs->diffopt, idx->name); pair = diff_unmerge(&revs->diffopt, idx->name);
if (tree) if (tree)
fill_filespec(pair->one, tree->sha1, 1, tree->ce_mode); fill_filespec(pair->one, tree->oid.hash, 1,
tree->ce_mode);
return; return;
} }
...@@ -408,7 +412,8 @@ static void do_oneway_diff(struct unpack_trees_options *o, ...@@ -408,7 +412,8 @@ static void do_oneway_diff(struct unpack_trees_options *o,
* Something removed from the tree? * Something removed from the tree?
*/ */
if (!idx) { if (!idx) {
diff_index_show_file(revs, "-", tree, tree->sha1, 1, tree->ce_mode, 0); diff_index_show_file(revs, "-", tree, tree->oid.hash, 1,
tree->ce_mode, 0);
return; return;
} }
......
...@@ -2700,7 +2700,7 @@ static int reuse_worktree_file(const char *name, const unsigned char *sha1, int ...@@ -2700,7 +2700,7 @@ static int reuse_worktree_file(const char *name, const unsigned char *sha1, int
* This is not the sha1 we are looking for, or * This is not the sha1 we are looking for, or
* unreusable because it is not a regular file. * unreusable because it is not a regular file.
*/ */
if (hashcmp(sha1, ce->sha1) || !S_ISREG(ce->ce_mode)) if (hashcmp(sha1, ce->oid.hash) || !S_ISREG(ce->ce_mode))
return 0; return 0;
/* /*
......
...@@ -525,7 +525,7 @@ static void *read_skip_worktree_file_from_index(const char *path, size_t *size, ...@@ -525,7 +525,7 @@ static void *read_skip_worktree_file_from_index(const char *path, size_t *size,
return NULL; return NULL;
if (!ce_skip_worktree(active_cache[pos])) if (!ce_skip_worktree(active_cache[pos]))
return NULL; return NULL;
data = read_sha1_file(active_cache[pos]->sha1, &type, &sz); data = read_sha1_file(active_cache[pos]->oid.hash, &type, &sz);
if (!data || type != OBJ_BLOB) { if (!data || type != OBJ_BLOB) {
free(data); free(data);
return NULL; return NULL;
...@@ -533,7 +533,7 @@ static void *read_skip_worktree_file_from_index(const char *path, size_t *size, ...@@ -533,7 +533,7 @@ static void *read_skip_worktree_file_from_index(const char *path, size_t *size,
*size = xsize_t(sz); *size = xsize_t(sz);
if (sha1_stat) { if (sha1_stat) {
memset(&sha1_stat->stat, 0, sizeof(sha1_stat->stat)); memset(&sha1_stat->stat, 0, sizeof(sha1_stat->stat));
hashcpy(sha1_stat->sha1, active_cache[pos]->sha1); hashcpy(sha1_stat->sha1, active_cache[pos]->oid.hash);
} }
return data; return data;
} }
...@@ -713,7 +713,8 @@ static int add_excludes(const char *fname, const char *base, int baselen, ...@@ -713,7 +713,8 @@ static int add_excludes(const char *fname, const char *base, int baselen,
!ce_stage(active_cache[pos]) && !ce_stage(active_cache[pos]) &&
ce_uptodate(active_cache[pos]) && ce_uptodate(active_cache[pos]) &&
!would_convert_to_git(fname)) !would_convert_to_git(fname))
hashcpy(sha1_stat->sha1, active_cache[pos]->sha1); hashcpy(sha1_stat->sha1,
active_cache[pos]->oid.hash);
else else
hash_sha1_file(buf, size, "blob", sha1_stat->sha1); hash_sha1_file(buf, size, "blob", sha1_stat->sha1);
fill_stat_data(&sha1_stat->stat, &st); fill_stat_data(&sha1_stat->stat, &st);
......
...@@ -82,7 +82,7 @@ static int create_file(const char *path, unsigned int mode) ...@@ -82,7 +82,7 @@ static int create_file(const char *path, unsigned int mode)
static void *read_blob_entry(const struct cache_entry *ce, unsigned long *size) static void *read_blob_entry(const struct cache_entry *ce, unsigned long *size)
{ {
enum object_type type; enum object_type type;
void *new = read_sha1_file(ce->sha1, &type, size); void *new = read_sha1_file(ce->oid.hash, &type, size);
if (new) { if (new) {
if (type == OBJ_BLOB) if (type == OBJ_BLOB)
...@@ -127,7 +127,7 @@ static int streaming_write_entry(const struct cache_entry *ce, char *path, ...@@ -127,7 +127,7 @@ static int streaming_write_entry(const struct cache_entry *ce, char *path,
if (fd < 0) if (fd < 0)
return -1; return -1;
result |= stream_blob_to_fd(fd, ce->sha1, filter, 1); result |= stream_blob_to_fd(fd, ce->oid.hash, filter, 1);
*fstat_done = fstat_output(fd, state, statbuf); *fstat_done = fstat_output(fd, state, statbuf);
result |= close(fd); result |= close(fd);
...@@ -148,7 +148,8 @@ static int write_entry(struct cache_entry *ce, ...@@ -148,7 +148,8 @@ static int write_entry(struct cache_entry *ce,
struct stat st; struct stat st;
if (ce_mode_s_ifmt == S_IFREG) { if (ce_mode_s_ifmt == S_IFREG) {
struct stream_filter *filter = get_stream_filter(ce->name, ce->sha1); struct stream_filter *filter = get_stream_filter(ce->name,
ce->oid.hash);
if (filter && if (filter &&
!streaming_write_entry(ce, path, filter, !streaming_write_entry(ce, path, filter,
state, to_tempfile, state, to_tempfile,
...@@ -162,7 +163,7 @@ static int write_entry(struct cache_entry *ce, ...@@ -162,7 +163,7 @@ static int write_entry(struct cache_entry *ce,
new = read_blob_entry(ce, &size); new = read_blob_entry(ce, &size);
if (!new) if (!new)
return error("unable to read sha1 file of %s (%s)", return error("unable to read sha1 file of %s (%s)",
path, sha1_to_hex(ce->sha1)); path, oid_to_hex(&ce->oid));
if (ce_mode_s_ifmt == S_IFLNK && has_symlinks && !to_tempfile) { if (ce_mode_s_ifmt == S_IFLNK && has_symlinks && !to_tempfile) {
ret = symlink(new, path); ret = symlink(new, path);
......
...@@ -382,7 +382,7 @@ static struct string_list *get_unmerged(void) ...@@ -382,7 +382,7 @@ static struct string_list *get_unmerged(void)
} }
e = item->util; e = item->util;
e->stages[ce_stage(ce)].mode = ce->ce_mode; e->stages[ce_stage(ce)].mode = ce->ce_mode;
hashcpy(e->stages[ce_stage(ce)].oid.hash, ce->sha1); oidcpy(&e->stages[ce_stage(ce)].oid, &ce->oid);
} }
return unmerged; return unmerged;
......
...@@ -161,7 +161,7 @@ static int ce_compare_data(const struct cache_entry *ce, struct stat *st) ...@@ -161,7 +161,7 @@ static int ce_compare_data(const struct cache_entry *ce, struct stat *st)
if (fd >= 0) { if (fd >= 0) {
unsigned char sha1[20]; unsigned char sha1[20];
if (!index_fd(sha1, fd, st, OBJ_BLOB, ce->name, 0)) if (!index_fd(sha1, fd, st, OBJ_BLOB, ce->name, 0))
match = hashcmp(sha1, ce->sha1); match = hashcmp(sha1, ce->oid.hash);
/* index_fd() closed the file descriptor already */ /* index_fd() closed the file descriptor already */
} }
return match; return match;
...@@ -178,7 +178,7 @@ static int ce_compare_link(const struct cache_entry *ce, size_t expected_size) ...@@ -178,7 +178,7 @@ static int ce_compare_link(const struct cache_entry *ce, size_t expected_size)
if (strbuf_readlink(&sb, ce->name, expected_size)) if (strbuf_readlink(&sb, ce->name, expected_size))
return -1; return -1;
buffer = read_sha1_file(ce->sha1, &type, &size); buffer = read_sha1_file(ce->oid.hash, &type, &size);
if (buffer) { if (buffer) {
if (size == sb.len) if (size == sb.len)
match = memcmp(buffer, sb.buf, size); match = memcmp(buffer, sb.buf, size);
...@@ -202,7 +202,7 @@ static int ce_compare_gitlink(const struct cache_entry *ce) ...@@ -202,7 +202,7 @@ static int ce_compare_gitlink(const struct cache_entry *ce)
*/ */
if (resolve_gitlink_ref(ce->name, "HEAD", sha1) < 0) if (resolve_gitlink_ref(ce->name, "HEAD", sha1) < 0)
return 0; return 0;
return hashcmp(sha1, ce->sha1); return hashcmp(sha1, ce->oid.hash);
} }
static int ce_modified_check_fs(const struct cache_entry *ce, struct stat *st) static int ce_modified_check_fs(const struct cache_entry *ce, struct stat *st)
...@@ -262,7 +262,7 @@ static int ce_match_stat_basic(const struct cache_entry *ce, struct stat *st) ...@@ -262,7 +262,7 @@ static int ce_match_stat_basic(const struct cache_entry *ce, struct stat *st)
/* Racily smudged entry? */ /* Racily smudged entry? */
if (!ce->ce_stat_data.sd_size) { if (!ce->ce_stat_data.sd_size) {
if (!is_empty_blob_sha1(ce->sha1)) if (!is_empty_blob_sha1(ce->oid.hash))
changed |= DATA_CHANGED; changed |= DATA_CHANGED;
} }
...@@ -624,7 +624,7 @@ void set_object_name_for_intent_to_add_entry(struct cache_entry *ce) ...@@ -624,7 +624,7 @@ void set_object_name_for_intent_to_add_entry(struct cache_entry *ce)
unsigned char sha1[20]; unsigned char sha1[20];
if (write_sha1_file("", 0, blob_type, sha1)) if (write_sha1_file("", 0, blob_type, sha1))
die("cannot create an empty blob in the object database"); die("cannot create an empty blob in the object database");
hashcpy(ce->sha1, sha1); hashcpy(ce->oid.hash, sha1);
} }
int add_to_index(struct index_state *istate, const char *path, struct stat *st, int flags, int force_mode) int add_to_index(struct index_state *istate, const char *path, struct stat *st, int flags, int force_mode)
...@@ -691,7 +691,7 @@ int add_to_index(struct index_state *istate, const char *path, struct stat *st, ...@@ -691,7 +691,7 @@ int add_to_index(struct index_state *istate, const char *path, struct stat *st,
return 0; return 0;
} }
if (!intent_only) { if (!intent_only) {
if (index_path(ce->sha1, path, st, HASH_WRITE_OBJECT)) { if (index_path(ce->oid.hash, path, st, HASH_WRITE_OBJECT)) {
free(ce); free(ce);
return error("unable to index file %s", path); return error("unable to index file %s", path);
} }
...@@ -705,7 +705,7 @@ int add_to_index(struct index_state *istate, const char *path, struct stat *st, ...@@ -705,7 +705,7 @@ int add_to_index(struct index_state *istate, const char *path, struct stat *st,
/* It was suspected to be racily clean, but it turns out to be Ok */ /* It was suspected to be racily clean, but it turns out to be Ok */
was_same = (alias && was_same = (alias &&
!ce_stage(alias) && !ce_stage(alias) &&
!hashcmp(alias->sha1, ce->sha1) && !oidcmp(&alias->oid, &ce->oid) &&
ce->ce_mode == alias->ce_mode); ce->ce_mode == alias->ce_mode);
if (pretend) if (pretend)
...@@ -744,7 +744,7 @@ struct cache_entry *make_cache_entry(unsigned int mode, ...@@ -744,7 +744,7 @@ struct cache_entry *make_cache_entry(unsigned int mode,
size = cache_entry_size(len); size = cache_entry_size(len);
ce = xcalloc(1, size); ce = xcalloc(1, size);
hashcpy(ce->sha1, sha1); hashcpy(ce->oid.hash, sha1);
memcpy(ce->name, path, len); memcpy(ce->name, path, len);
ce->ce_flags = create_ce_flags(stage); ce->ce_flags = create_ce_flags(stage);
ce->ce_namelen = len; ce->ce_namelen = len;
...@@ -1424,7 +1424,7 @@ static struct cache_entry *cache_entry_from_ondisk(struct ondisk_cache_entry *on ...@@ -1424,7 +1424,7 @@ static struct cache_entry *cache_entry_from_ondisk(struct ondisk_cache_entry *on
ce->ce_flags = flags & ~CE_NAMEMASK; ce->ce_flags = flags & ~CE_NAMEMASK;
ce->ce_namelen = len; ce->ce_namelen = len;
ce->index = 0; ce->index = 0;
hashcpy(ce->sha1, ondisk->sha1); hashcpy(ce->oid.hash, ondisk->sha1);
memcpy(ce->name, name, len); memcpy(ce->name, name, len);
ce->name[len] = '\0'; ce->name[len] = '\0';
return ce; return ce;
...@@ -1849,7 +1849,7 @@ static char *copy_cache_entry_to_ondisk(struct ondisk_cache_entry *ondisk, ...@@ -1849,7 +1849,7 @@ static char *copy_cache_entry_to_ondisk(struct ondisk_cache_entry *ondisk,
ondisk->uid = htonl(ce->ce_stat_data.sd_uid); ondisk->uid = htonl(ce->ce_stat_data.sd_uid);
ondisk->gid = htonl(ce->ce_stat_data.sd_gid); ondisk->gid = htonl(ce->ce_stat_data.sd_gid);
ondisk->size = htonl(ce->ce_stat_data.sd_size); ondisk->size = htonl(ce->ce_stat_data.sd_size);
hashcpy(ondisk->sha1, ce->sha1); hashcpy(ondisk->sha1, ce->oid.hash);
flags = ce->ce_flags & ~CE_NAMEMASK; flags = ce->ce_flags & ~CE_NAMEMASK;
flags |= (ce_namelen(ce) >= CE_NAMEMASK ? CE_NAMEMASK : ce_namelen(ce)); flags |= (ce_namelen(ce) >= CE_NAMEMASK ? CE_NAMEMASK : ce_namelen(ce));
...@@ -2038,7 +2038,7 @@ static int do_write_index(struct index_state *istate, int newfd, ...@@ -2038,7 +2038,7 @@ static int do_write_index(struct index_state *istate, int newfd,
continue; continue;
if (!ce_uptodate(ce) && is_racy_timestamp(istate, ce)) if (!ce_uptodate(ce) && is_racy_timestamp(istate, ce))
ce_smudge_racily_clean_entry(ce); ce_smudge_racily_clean_entry(ce);
if (is_null_sha1(ce->sha1)) { if (is_null_oid(&ce->oid)) {
static const char msg[] = "cache entry has null sha1: %s"; static const char msg[] = "cache entry has null sha1: %s";
static int allow = -1; static int allow = -1;
...@@ -2285,7 +2285,7 @@ void *read_blob_data_from_index(struct index_state *istate, const char *path, un ...@@ -2285,7 +2285,7 @@ void *read_blob_data_from_index(struct index_state *istate, const char *path, un
} }
if (pos < 0) if (pos < 0)
return NULL; return NULL;
data = read_sha1_file(istate->cache[pos]->sha1, &type, &sz); data = read_sha1_file(istate->cache[pos]->oid.hash, &type, &sz);
if (!data || type != OBJ_BLOB) { if (!data || type != OBJ_BLOB) {
free(data); free(data);
return NULL; return NULL;
......
...@@ -980,7 +980,8 @@ static int handle_cache(const char *path, unsigned char *sha1, const char *outpu ...@@ -980,7 +980,8 @@ static int handle_cache(const char *path, unsigned char *sha1, const char *outpu
break; break;
i = ce_stage(ce) - 1; i = ce_stage(ce) - 1;
if (!mmfile[i].ptr) { if (!mmfile[i].ptr) {
mmfile[i].ptr = read_sha1_file(ce->sha1, &type, &size); mmfile[i].ptr = read_sha1_file(ce->oid.hash, &type,
&size);
mmfile[i].size = size; mmfile[i].size = size;
} }
} }
......
...@@ -24,7 +24,7 @@ void record_resolve_undo(struct index_state *istate, struct cache_entry *ce) ...@@ -24,7 +24,7 @@ void record_resolve_undo(struct index_state *istate, struct cache_entry *ce)
if (!lost->util) if (!lost->util)
lost->util = xcalloc(1, sizeof(*ui)); lost->util = xcalloc(1, sizeof(*ui));
ui = lost->util; ui = lost->util;
hashcpy(ui->sha1[stage - 1], ce->sha1); hashcpy(ui->sha1[stage - 1], ce->oid.hash);
ui->mode[stage - 1] = ce->ce_mode; ui->mode[stage - 1] = ce->ce_mode;
} }
......
...@@ -1275,7 +1275,7 @@ void add_index_objects_to_pending(struct rev_info *revs, unsigned flags) ...@@ -1275,7 +1275,7 @@ void add_index_objects_to_pending(struct rev_info *revs, unsigned flags)
if (S_ISGITLINK(ce->ce_mode)) if (S_ISGITLINK(ce->ce_mode))
continue; continue;
blob = lookup_blob(ce->sha1); blob = lookup_blob(ce->oid.hash);
if (!blob) if (!blob)
die("unable to add index blob to traversal"); die("unable to add index blob to traversal");
add_pending_object_with_path(revs, &blob->object, "", add_pending_object_with_path(revs, &blob->object, "",
......
...@@ -1435,7 +1435,7 @@ static int get_sha1_with_context_1(const char *name, ...@@ -1435,7 +1435,7 @@ static int get_sha1_with_context_1(const char *name,
memcmp(ce->name, cp, namelen)) memcmp(ce->name, cp, namelen))
break; break;
if (ce_stage(ce) == stage) { if (ce_stage(ce) == stage) {
hashcpy(sha1, ce->sha1); hashcpy(sha1, ce->oid.hash);
oc->mode = ce->ce_mode; oc->mode = ce->ce_mode;
free(new_path); free(new_path);
return 0; return 0;
......
...@@ -23,7 +23,7 @@ int cmd_main(int ac, const char **av) ...@@ -23,7 +23,7 @@ int cmd_main(int ac, const char **av)
for (i = 0; i < the_index.cache_nr; i++) { for (i = 0; i < the_index.cache_nr; i++) {
struct cache_entry *ce = the_index.cache[i]; struct cache_entry *ce = the_index.cache[i];
printf("%06o %s %d\t%s\n", ce->ce_mode, printf("%06o %s %d\t%s\n", ce->ce_mode,
sha1_to_hex(ce->sha1), ce_stage(ce), ce->name); oid_to_hex(&ce->oid), ce_stage(ce), ce->name);
} }
printf("replacements:"); printf("replacements:");
if (si->replace_bitmap) if (si->replace_bitmap)
......
...@@ -26,7 +26,7 @@ static int read_one_entry_opt(const unsigned char *sha1, const char *base, int b ...@@ -26,7 +26,7 @@ static int read_one_entry_opt(const unsigned char *sha1, const char *base, int b
ce->ce_namelen = baselen + len; ce->ce_namelen = baselen + len;
memcpy(ce->name, base, baselen); memcpy(ce->name, base, baselen);
memcpy(ce->name + baselen, pathname, len+1); memcpy(ce->name + baselen, pathname, len+1);
hashcpy(ce->sha1, sha1); hashcpy(ce->oid.hash, sha1);
return add_cache_entry(ce, opt); return add_cache_entry(ce, opt);
} }
......
...@@ -625,7 +625,7 @@ static struct cache_entry *create_ce_entry(const struct traverse_info *info, con ...@@ -625,7 +625,7 @@ static struct cache_entry *create_ce_entry(const struct traverse_info *info, con
ce->ce_mode = create_ce_mode(n->mode); ce->ce_mode = create_ce_mode(n->mode);
ce->ce_flags = create_ce_flags(stage); ce->ce_flags = create_ce_flags(stage);
ce->ce_namelen = len; ce->ce_namelen = len;
hashcpy(ce->sha1, n->oid->hash); oidcpy(&ce->oid, n->oid);
make_traverse_path(ce->name, info, n); make_traverse_path(ce->name, info, n);
return ce; return ce;
...@@ -1287,7 +1287,7 @@ static int same(const struct cache_entry *a, const struct cache_entry *b) ...@@ -1287,7 +1287,7 @@ static int same(const struct cache_entry *a, const struct cache_entry *b)
if ((a->ce_flags | b->ce_flags) & CE_CONFLICTED) if ((a->ce_flags | b->ce_flags) & CE_CONFLICTED)
return 0; return 0;
return a->ce_mode == b->ce_mode && return a->ce_mode == b->ce_mode &&
!hashcmp(a->sha1, b->sha1); !oidcmp(&a->oid, &b->oid);
} }
...@@ -1393,7 +1393,7 @@ static int verify_clean_subdirectory(const struct cache_entry *ce, ...@@ -1393,7 +1393,7 @@ static int verify_clean_subdirectory(const struct cache_entry *ce,
/* If we are not going to update the submodule, then /* If we are not going to update the submodule, then
* we don't care. * we don't care.
*/ */
if (!hashcmp(sha1, ce->sha1)) if (!hashcmp(sha1, ce->oid.hash))
return 0; return 0;
return verify_clean_submodule(ce, error_type, o); return verify_clean_submodule(ce, error_type, o);
} }
...@@ -1665,7 +1665,7 @@ static void show_stage_entry(FILE *o, ...@@ -1665,7 +1665,7 @@ static void show_stage_entry(FILE *o,
fprintf(o, "%s%06o %s %d\t%s\n", fprintf(o, "%s%06o %s %d\t%s\n",
label, label,
ce->ce_mode, ce->ce_mode,
sha1_to_hex(ce->sha1), oid_to_hex(&ce->oid),
ce_stage(ce), ce_stage(ce),
ce->name); ce->name);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册