Skip to content

Commit

Permalink
cache: convert struct cache_entry to use struct object_id
Browse files Browse the repository at this point in the history
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: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
bk2204 authored and gitster committed Sep 7, 2016
1 parent 6ebdac1 commit 99d1a98
Show file tree
Hide file tree
Showing 26 changed files with 79 additions and 69 deletions.
10 changes: 5 additions & 5 deletions builtin/apply.c
Original file line number Diff line number Diff line change
Expand Up @@ -3220,7 +3220,7 @@ static int read_file_or_gitlink(const struct cache_entry *ce, struct strbuf *buf
{
if (!ce)
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)
Expand Down Expand Up @@ -3959,7 +3959,7 @@ static int get_current_sha1(const char *path, unsigned char *sha1)
pos = cache_name_pos(path, strlen(path));
if (pos < 0)
return -1;
hashcpy(sha1, active_cache[pos]->sha1);
hashcpy(sha1, active_cache[pos]->oid.hash);
return 0;
}

Expand Down Expand Up @@ -4211,7 +4211,7 @@ static void add_index_file(struct apply_state *state,
const char *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);
} else {
if (!state->cached) {
Expand All @@ -4220,7 +4220,7 @@ static void add_index_file(struct apply_state *state,
path);
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);
}
if (add_cache_entry(ce, ADD_CACHE_OK_TO_ADD) < 0)
Expand Down Expand Up @@ -4335,7 +4335,7 @@ static void add_conflicted_stages_file(struct apply_state *state,
ce->ce_mode = create_ce_mode(mode);
ce->ce_flags = create_ce_flags(stage);
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)
die(_("unable to add cache entry for %s"), patch->new_name);
}
Expand Down
2 changes: 1 addition & 1 deletion builtin/blame.c
Original file line number Diff line number Diff line change
Expand Up @@ -2410,7 +2410,7 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt,
}
size = cache_entry_size(len);
ce = xcalloc(1, size);
hashcpy(ce->sha1, origin->blob_sha1);
hashcpy(ce->oid.hash, origin->blob_sha1);
memcpy(ce->name, path, len);
ce->ce_flags = create_ce_flags(0);
ce->ce_namelen = len;
Expand Down
6 changes: 3 additions & 3 deletions builtin/checkout.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ static int update_some(const unsigned char *sha1, struct strbuf *base,

len = base->len + strlen(pathname);
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->len, pathname, len - base->len);
ce->ce_flags = create_ce_flags(0) | CE_UPDATE;
Expand All @@ -92,7 +92,7 @@ static int update_some(const unsigned char *sha1, struct strbuf *base,
if (pos >= 0) {
struct cache_entry *old = active_cache[pos];
if (ce->ce_mode == old->ce_mode &&
!hashcmp(ce->sha1, old->sha1)) {
!oidcmp(&ce->oid, &old->oid)) {
old->ce_flags |= CE_UPDATE;
free(ce);
return 0;
Expand Down Expand Up @@ -186,7 +186,7 @@ static int checkout_merged(int pos, struct checkout *state)
stage = ce_stage(ce);
if (!stage || strcmp(path, ce->name))
break;
hashcpy(threeway[stage - 1], ce->sha1);
hashcpy(threeway[stage - 1], ce->oid.hash);
if (stage == 2)
mode = create_ce_mode(ce->ce_mode);
pos++;
Expand Down
2 changes: 1 addition & 1 deletion builtin/fsck.c
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
mode = active_cache[i]->ce_mode;
if (S_ISGITLINK(mode))
continue;
blob = lookup_blob(active_cache[i]->sha1);
blob = lookup_blob(active_cache[i]->oid.hash);
if (!blob)
continue;
obj = &blob->object;
Expand Down
3 changes: 2 additions & 1 deletion builtin/grep.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 (ce_stage(ce) || ce_intent_to_add(ce))
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
hit |= grep_file(opt, ce->name);
Expand Down
2 changes: 1 addition & 1 deletion builtin/ls-files.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ static void show_ce_entry(const char *tag, const struct cache_entry *ce)
printf("%s%06o %s %d\t",
tag,
ce->ce_mode,
find_unique_abbrev(ce->sha1,abbrev),
find_unique_abbrev(ce->oid.hash,abbrev),
ce_stage(ce));
}
write_eolinfo(ce, ce->name);
Expand Down
2 changes: 1 addition & 1 deletion builtin/merge-index.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ static int merge_entry(int pos, const char *path)
if (strcmp(ce->name, path))
break;
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);
arguments[stage] = hexbuf[stage];
arguments[stage + 4] = ownbuf[stage];
Expand Down
2 changes: 1 addition & 1 deletion builtin/read-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ static void debug_stage(const char *label, const struct cache_entry *ce,
else
printf("%06o #%d %s %.8s\n",
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,
Expand Down
2 changes: 1 addition & 1 deletion builtin/rm.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ static int check_local_mod(unsigned char *head, int index_only)
if (no_head
|| get_tree_entry(head, name, sha1, &mode)
|| ce->ce_mode != create_ce_mode(mode)
|| hashcmp(ce->sha1, sha1))
|| hashcmp(ce->oid.hash, sha1))
staged_changes = 1;

/*
Expand Down
5 changes: 3 additions & 2 deletions builtin/submodule--helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,8 @@ static int module_list(int argc, const char **argv, const char *prefix)
if (ce_stage(ce))
printf("%06o %s U\t", ce->ce_mode, sha1_to_hex(null_sha1));
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);
}
Expand Down Expand Up @@ -683,7 +684,7 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,

strbuf_reset(&sb);
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);
string_list_append(&suc->projectlines, sb.buf);

Expand Down
10 changes: 5 additions & 5 deletions builtin/update-index.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
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)) {
free(ce);
return -1;
Expand Down Expand Up @@ -403,7 +403,7 @@ static int add_cacheinfo(unsigned int mode, const unsigned char *sha1,
size = cache_entry_size(len);
ce = xcalloc(1, size);

hashcpy(ce->sha1, sha1);
hashcpy(ce->oid.hash, sha1);
memcpy(ce->name, path, len);
ce->ce_flags = create_ce_flags(stage);
ce->ce_namelen = len;
Expand Down Expand Up @@ -601,7 +601,7 @@ static struct cache_entry *read_one_ent(const char *which,
size = cache_entry_size(namelen);
ce = xcalloc(1, size);

hashcpy(ce->sha1, sha1);
hashcpy(ce->oid.hash, sha1);
memcpy(ce->name, path, namelen);
ce->ce_flags = create_ce_flags(stage);
ce->ce_namelen = namelen;
Expand Down Expand Up @@ -658,7 +658,7 @@ static int unresolve_one(const char *path)
ret = -1;
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) {
fprintf(stderr, "%s: identical in both, skipping.\n",
path);
Expand Down Expand Up @@ -743,7 +743,7 @@ static int do_reupdate(int ac, const char **av,
old = read_one_ent(NULL, head_sha1,
ce->name, ce_namelen(ce), 0);
if (old && ce->ce_mode == old->ce_mode &&
!hashcmp(ce->sha1, old->sha1)) {
!oidcmp(&ce->oid, &old->oid)) {
free(old);
continue; /* unchanged */
}
Expand Down
4 changes: 2 additions & 2 deletions cache-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ static int verify_cache(struct cache_entry **cache,
break;
}
fprintf(stderr, "%s: unmerged (%s)\n",
ce->name, sha1_to_hex(ce->sha1));
ce->name, oid_to_hex(&ce->oid));
}
}
if (funny)
Expand Down Expand Up @@ -349,7 +349,7 @@ static int update_one(struct cache_tree *it,
}
}
else {
sha1 = ce->sha1;
sha1 = ce->oid.hash;
mode = ce->ce_mode;
entlen = pathlen - baselen;
i++;
Expand Down
2 changes: 1 addition & 1 deletion cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ struct cache_entry {
unsigned int ce_flags;
unsigned int ce_namelen;
unsigned int index; /* for link extension */
unsigned char sha1[20];
struct object_id oid;
char name[FLEX_ARRAY]; /* more */
};

Expand Down
31 changes: 18 additions & 13 deletions diff-lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
if (2 <= stage) {
int mode = nce->ce_mode;
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].status =
DIFF_STATUS_MODIFIED;
Expand Down Expand Up @@ -209,7 +210,8 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
continue;
}
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);
continue;
}
Expand All @@ -225,8 +227,8 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
continue;
}
oldmode = ce->ce_mode;
old_sha1 = ce->sha1;
new_sha1 = changed ? null_sha1 : ce->sha1;
old_sha1 = ce->oid.hash;
new_sha1 = changed ? null_sha1 : ce->oid.hash;
diff_change(&revs->diffopt, oldmode, newmode,
old_sha1, new_sha1,
!is_null_sha1(old_sha1),
Expand Down Expand Up @@ -261,7 +263,7 @@ static int get_stat_data(const struct cache_entry *ce,
int cached, int match_missing,
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;

if (!cached && !ce_uptodate(ce)) {
Expand Down Expand Up @@ -324,12 +326,13 @@ static int show_modified(struct rev_info *revs,
&dirty_submodule, &revs->diffopt) < 0) {
if (report_missing)
diff_index_show_file(revs, "-", old,
old->sha1, 1, old->ce_mode, 0);
old->oid.hash, 1, old->ce_mode,
0);
return -1;
}

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;
int pathlen = ce_namelen(new);

Expand All @@ -343,22 +346,22 @@ static int show_modified(struct rev_info *revs,
memset(p->parent, 0, 2 * sizeof(struct combine_diff_parent));
p->parent[0].status = DIFF_STATUS_MODIFIED;
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].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);
free(p);
return 0;
}

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))
return 0;

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);
return 0;
}
Expand Down Expand Up @@ -392,7 +395,8 @@ static void do_oneway_diff(struct unpack_trees_options *o,
struct diff_filepair *pair;
pair = diff_unmerge(&revs->diffopt, idx->name);
if (tree)
fill_filespec(pair->one, tree->sha1, 1, tree->ce_mode);
fill_filespec(pair->one, tree->oid.hash, 1,
tree->ce_mode);
return;
}

Expand All @@ -408,7 +412,8 @@ static void do_oneway_diff(struct unpack_trees_options *o,
* Something removed from the tree?
*/
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;
}

Expand Down
2 changes: 1 addition & 1 deletion diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
* 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;

/*
Expand Down
7 changes: 4 additions & 3 deletions dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -525,15 +525,15 @@ static void *read_skip_worktree_file_from_index(const char *path, size_t *size,
return NULL;
if (!ce_skip_worktree(active_cache[pos]))
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) {
free(data);
return NULL;
}
*size = xsize_t(sz);
if (sha1_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;
}
Expand Down Expand Up @@ -713,7 +713,8 @@ static int add_excludes(const char *fname, const char *base, int baselen,
!ce_stage(active_cache[pos]) &&
ce_uptodate(active_cache[pos]) &&
!would_convert_to_git(fname))
hashcpy(sha1_stat->sha1, active_cache[pos]->sha1);
hashcpy(sha1_stat->sha1,
active_cache[pos]->oid.hash);
else
hash_sha1_file(buf, size, "blob", sha1_stat->sha1);
fill_stat_data(&sha1_stat->stat, &st);
Expand Down
Loading

0 comments on commit 99d1a98

Please sign in to comment.