Merge branch 'bc/object-id'

"uchar [40]" to "struct object_id" conversion continues.

* bc/object-id:
  wt-status: convert to struct object_id
  builtin/merge-base: convert to struct object_id
  Convert object iteration callbacks to struct object_id
  sha1_file: introduce an nth_packed_object_oid function
  refs: simplify parsing of reflog entries
  refs: convert each_reflog_ent_fn to struct object_id
  reflog-walk: convert struct reflog_info to struct object_id
  builtin/replace: convert to struct object_id
  Convert remaining callers of resolve_refdup to object_id
  builtin/merge: convert to struct object_id
  builtin/clone: convert to struct object_id
  builtin/branch: convert to struct object_id
  builtin/grep: convert to struct object_id
  builtin/fmt-merge-message: convert to struct object_id
  builtin/fast-export: convert to struct object_id
  builtin/describe: convert to struct object_id
  builtin/diff-tree: convert to struct object_id
  builtin/commit: convert to struct object_id
  hex: introduce parse_oid_hex
This commit is contained in:
Junio C Hamano 2017-03-17 13:50:24 -07:00
commit e1fae93019
33 changed files with 493 additions and 461 deletions

View File

@ -33,7 +33,7 @@ static const char * const builtin_branch_usage[] = {
}; };
static const char *head; static const char *head;
static unsigned char head_sha1[20]; static struct object_id head_oid;
static int branch_use_color = -1; static int branch_use_color = -1;
static char branch_colors[][COLOR_MAXLEN] = { static char branch_colors[][COLOR_MAXLEN] = {
@ -118,13 +118,13 @@ static int branch_merged(int kind, const char *name,
if (kind == FILTER_REFS_BRANCHES) { if (kind == FILTER_REFS_BRANCHES) {
struct branch *branch = branch_get(name); struct branch *branch = branch_get(name);
const char *upstream = branch_get_upstream(branch, NULL); const char *upstream = branch_get_upstream(branch, NULL);
unsigned char sha1[20]; struct object_id oid;
if (upstream && if (upstream &&
(reference_name = reference_name_to_free = (reference_name = reference_name_to_free =
resolve_refdup(upstream, RESOLVE_REF_READING, resolve_refdup(upstream, RESOLVE_REF_READING,
sha1, NULL)) != NULL) oid.hash, NULL)) != NULL)
reference_rev = lookup_commit_reference(sha1); reference_rev = lookup_commit_reference(oid.hash);
} }
if (!reference_rev) if (!reference_rev)
reference_rev = head_rev; reference_rev = head_rev;
@ -154,10 +154,10 @@ static int branch_merged(int kind, const char *name,
} }
static int check_branch_commit(const char *branchname, const char *refname, static int check_branch_commit(const char *branchname, const char *refname,
const unsigned char *sha1, struct commit *head_rev, const struct object_id *oid, struct commit *head_rev,
int kinds, int force) int kinds, int force)
{ {
struct commit *rev = lookup_commit_reference(sha1); struct commit *rev = lookup_commit_reference(oid->hash);
if (!rev) { if (!rev) {
error(_("Couldn't look up commit object for '%s'"), refname); error(_("Couldn't look up commit object for '%s'"), refname);
return -1; return -1;
@ -184,7 +184,7 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
int quiet) int quiet)
{ {
struct commit *head_rev = NULL; struct commit *head_rev = NULL;
unsigned char sha1[20]; struct object_id oid;
char *name = NULL; char *name = NULL;
const char *fmt; const char *fmt;
int i; int i;
@ -211,7 +211,7 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
} }
if (!force) { if (!force) {
head_rev = lookup_commit_reference(head_sha1); head_rev = lookup_commit_reference(head_oid.hash);
if (!head_rev) if (!head_rev)
die(_("Couldn't look up commit object for HEAD")); die(_("Couldn't look up commit object for HEAD"));
} }
@ -239,7 +239,7 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
RESOLVE_REF_READING RESOLVE_REF_READING
| RESOLVE_REF_NO_RECURSE | RESOLVE_REF_NO_RECURSE
| RESOLVE_REF_ALLOW_BAD_NAME, | RESOLVE_REF_ALLOW_BAD_NAME,
sha1, &flags); oid.hash, &flags);
if (!target) { if (!target) {
error(remote_branch error(remote_branch
? _("remote-tracking branch '%s' not found.") ? _("remote-tracking branch '%s' not found.")
@ -249,13 +249,13 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
} }
if (!(flags & (REF_ISSYMREF|REF_ISBROKEN)) && if (!(flags & (REF_ISSYMREF|REF_ISBROKEN)) &&
check_branch_commit(bname.buf, name, sha1, head_rev, kinds, check_branch_commit(bname.buf, name, &oid, head_rev, kinds,
force)) { force)) {
ret = 1; ret = 1;
goto next; goto next;
} }
if (delete_ref(NULL, name, is_null_sha1(sha1) ? NULL : sha1, if (delete_ref(NULL, name, is_null_oid(&oid) ? NULL : oid.hash,
REF_NODEREF)) { REF_NODEREF)) {
error(remote_branch error(remote_branch
? _("Error deleting remote-tracking branch '%s'") ? _("Error deleting remote-tracking branch '%s'")
@ -271,7 +271,7 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
bname.buf, bname.buf,
(flags & REF_ISBROKEN) ? "broken" (flags & REF_ISBROKEN) ? "broken"
: (flags & REF_ISSYMREF) ? target : (flags & REF_ISSYMREF) ? target
: find_unique_abbrev(sha1, DEFAULT_ABBREV)); : find_unique_abbrev(oid.hash, DEFAULT_ABBREV));
} }
delete_branch_config(bname.buf); delete_branch_config(bname.buf);
@ -604,7 +604,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
track = git_branch_track; track = git_branch_track;
head = resolve_refdup("HEAD", 0, head_sha1, NULL); head = resolve_refdup("HEAD", 0, head_oid.hash, NULL);
if (!head) if (!head)
die(_("Failed to resolve HEAD as a valid ref.")); die(_("Failed to resolve HEAD as a valid ref."));
if (!strcmp(head, "HEAD")) if (!strcmp(head, "HEAD"))

View File

@ -409,20 +409,20 @@ static int batch_object_cb(const unsigned char sha1[20], void *vdata)
return 0; return 0;
} }
static int batch_loose_object(const unsigned char *sha1, static int batch_loose_object(const struct object_id *oid,
const char *path, const char *path,
void *data) void *data)
{ {
sha1_array_append(data, sha1); sha1_array_append(data, oid->hash);
return 0; return 0;
} }
static int batch_packed_object(const unsigned char *sha1, static int batch_packed_object(const struct object_id *oid,
struct packed_git *pack, struct packed_git *pack,
uint32_t pos, uint32_t pos,
void *data) void *data)
{ {
sha1_array_append(data, sha1); sha1_array_append(data, oid->hash);
return 0; return 0;
} }

View File

@ -681,7 +681,7 @@ static void update_head(const struct ref *our, const struct ref *remote,
static int checkout(int submodule_progress) static int checkout(int submodule_progress)
{ {
unsigned char sha1[20]; struct object_id oid;
char *head; char *head;
struct lock_file *lock_file; struct lock_file *lock_file;
struct unpack_trees_options opts; struct unpack_trees_options opts;
@ -692,7 +692,7 @@ static int checkout(int submodule_progress)
if (option_no_checkout) if (option_no_checkout)
return 0; return 0;
head = resolve_refdup("HEAD", RESOLVE_REF_READING, sha1, NULL); head = resolve_refdup("HEAD", RESOLVE_REF_READING, oid.hash, NULL);
if (!head) { if (!head) {
warning(_("remote HEAD refers to nonexistent ref, " warning(_("remote HEAD refers to nonexistent ref, "
"unable to checkout.\n")); "unable to checkout.\n"));
@ -700,7 +700,7 @@ static int checkout(int submodule_progress)
} }
if (!strcmp(head, "HEAD")) { if (!strcmp(head, "HEAD")) {
if (advice_detached_head) if (advice_detached_head)
detach_advice(sha1_to_hex(sha1)); detach_advice(oid_to_hex(&oid));
} else { } else {
if (!starts_with(head, "refs/heads/")) if (!starts_with(head, "refs/heads/"))
die(_("HEAD not found below refs/heads!")); die(_("HEAD not found below refs/heads!"));
@ -721,7 +721,7 @@ static int checkout(int submodule_progress)
opts.src_index = &the_index; opts.src_index = &the_index;
opts.dst_index = &the_index; opts.dst_index = &the_index;
tree = parse_tree_indirect(sha1); tree = parse_tree_indirect(oid.hash);
parse_tree(tree); parse_tree(tree);
init_tree_desc(&t, tree->buffer, tree->size); init_tree_desc(&t, tree->buffer, tree->size);
if (unpack_trees(1, &t, &opts) < 0) if (unpack_trees(1, &t, &opts) < 0)
@ -731,7 +731,7 @@ static int checkout(int submodule_progress)
die(_("unable to write new index file")); die(_("unable to write new index file"));
err |= run_hook_le(NULL, "post-checkout", sha1_to_hex(null_sha1), err |= run_hook_le(NULL, "post-checkout", sha1_to_hex(null_sha1),
sha1_to_hex(sha1), "1", NULL); oid_to_hex(&oid), "1", NULL);
if (!err && option_recursive) { if (!err && option_recursive) {
struct argv_array args = ARGV_ARRAY_INIT; struct argv_array args = ARGV_ARRAY_INIT;

View File

@ -496,7 +496,7 @@ static const char *prepare_index(int argc, const char **argv, const char *prefix
static int run_status(FILE *fp, const char *index_file, const char *prefix, int nowarn, static int run_status(FILE *fp, const char *index_file, const char *prefix, int nowarn,
struct wt_status *s) struct wt_status *s)
{ {
unsigned char sha1[20]; struct object_id oid;
if (s->relative_paths) if (s->relative_paths)
s->prefix = prefix; s->prefix = prefix;
@ -509,9 +509,9 @@ static int run_status(FILE *fp, const char *index_file, const char *prefix, int
s->index_file = index_file; s->index_file = index_file;
s->fp = fp; s->fp = fp;
s->nowarn = nowarn; s->nowarn = nowarn;
s->is_initial = get_sha1(s->reference, sha1) ? 1 : 0; s->is_initial = get_sha1(s->reference, oid.hash) ? 1 : 0;
if (!s->is_initial) if (!s->is_initial)
hashcpy(s->sha1_commit, sha1); hashcpy(s->sha1_commit, oid.hash);
s->status_format = status_format; s->status_format = status_format;
s->ignore_submodule_arg = ignore_submodule_arg; s->ignore_submodule_arg = ignore_submodule_arg;
@ -885,7 +885,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
commitable = run_status(s->fp, index_file, prefix, 1, s); commitable = run_status(s->fp, index_file, prefix, 1, s);
s->use_color = saved_color_setting; s->use_color = saved_color_setting;
} else { } else {
unsigned char sha1[20]; struct object_id oid;
const char *parent = "HEAD"; const char *parent = "HEAD";
if (!active_nr && read_cache() < 0) if (!active_nr && read_cache() < 0)
@ -894,7 +894,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
if (amend) if (amend)
parent = "HEAD^1"; parent = "HEAD^1";
if (get_sha1(parent, sha1)) { if (get_sha1(parent, oid.hash)) {
int i, ita_nr = 0; int i, ita_nr = 0;
for (i = 0; i < active_nr; i++) for (i = 0; i < active_nr; i++)
@ -1332,7 +1332,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
{ {
static struct wt_status s; static struct wt_status s;
int fd; int fd;
unsigned char sha1[20]; struct object_id oid;
static struct option builtin_status_options[] = { static struct option builtin_status_options[] = {
OPT__VERBOSE(&verbose, N_("be verbose")), OPT__VERBOSE(&verbose, N_("be verbose")),
OPT_SET_INT('s', "short", &status_format, OPT_SET_INT('s', "short", &status_format,
@ -1382,9 +1382,9 @@ int cmd_status(int argc, const char **argv, const char *prefix)
fd = hold_locked_index(&index_lock, 0); fd = hold_locked_index(&index_lock, 0);
s.is_initial = get_sha1(s.reference, sha1) ? 1 : 0; s.is_initial = get_sha1(s.reference, oid.hash) ? 1 : 0;
if (!s.is_initial) if (!s.is_initial)
hashcpy(s.sha1_commit, sha1); hashcpy(s.sha1_commit, oid.hash);
s.ignore_submodule_arg = ignore_submodule_arg; s.ignore_submodule_arg = ignore_submodule_arg;
s.status_format = status_format; s.status_format = status_format;
@ -1418,19 +1418,19 @@ static const char *implicit_ident_advice(void)
} }
static void print_summary(const char *prefix, const unsigned char *sha1, static void print_summary(const char *prefix, const struct object_id *oid,
int initial_commit) int initial_commit)
{ {
struct rev_info rev; struct rev_info rev;
struct commit *commit; struct commit *commit;
struct strbuf format = STRBUF_INIT; struct strbuf format = STRBUF_INIT;
unsigned char junk_sha1[20]; struct object_id junk_oid;
const char *head; const char *head;
struct pretty_print_context pctx = {0}; struct pretty_print_context pctx = {0};
struct strbuf author_ident = STRBUF_INIT; struct strbuf author_ident = STRBUF_INIT;
struct strbuf committer_ident = STRBUF_INIT; struct strbuf committer_ident = STRBUF_INIT;
commit = lookup_commit(sha1); commit = lookup_commit(oid->hash);
if (!commit) if (!commit)
die(_("couldn't look up newly created commit")); die(_("couldn't look up newly created commit"));
if (parse_commit(commit)) if (parse_commit(commit))
@ -1477,7 +1477,7 @@ static void print_summary(const char *prefix, const unsigned char *sha1,
rev.diffopt.break_opt = 0; rev.diffopt.break_opt = 0;
diff_setup_done(&rev.diffopt); diff_setup_done(&rev.diffopt);
head = resolve_ref_unsafe("HEAD", 0, junk_sha1, NULL); head = resolve_ref_unsafe("HEAD", 0, junk_oid.hash, NULL);
if (!strcmp(head, "HEAD")) if (!strcmp(head, "HEAD"))
head = _("detached HEAD"); head = _("detached HEAD");
else else
@ -1522,8 +1522,8 @@ static int git_commit_config(const char *k, const char *v, void *cb)
return git_status_config(k, v, s); return git_status_config(k, v, s);
} }
static int run_rewrite_hook(const unsigned char *oldsha1, static int run_rewrite_hook(const struct object_id *oldoid,
const unsigned char *newsha1) const struct object_id *newoid)
{ {
struct child_process proc = CHILD_PROCESS_INIT; struct child_process proc = CHILD_PROCESS_INIT;
const char *argv[3]; const char *argv[3];
@ -1544,7 +1544,7 @@ static int run_rewrite_hook(const unsigned char *oldsha1,
code = start_command(&proc); code = start_command(&proc);
if (code) if (code)
return code; return code;
strbuf_addf(&sb, "%s %s\n", sha1_to_hex(oldsha1), sha1_to_hex(newsha1)); strbuf_addf(&sb, "%s %s\n", oid_to_hex(oldoid), oid_to_hex(newoid));
sigchain_push(SIGPIPE, SIG_IGN); sigchain_push(SIGPIPE, SIG_IGN);
write_in_full(proc.in, sb.buf, sb.len); write_in_full(proc.in, sb.buf, sb.len);
close(proc.in); close(proc.in);
@ -1636,7 +1636,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
struct strbuf author_ident = STRBUF_INIT; struct strbuf author_ident = STRBUF_INIT;
const char *index_file, *reflog_msg; const char *index_file, *reflog_msg;
char *nl; char *nl;
unsigned char sha1[20]; struct object_id oid;
struct commit_list *parents = NULL; struct commit_list *parents = NULL;
struct stat statbuf; struct stat statbuf;
struct commit *current_head = NULL; struct commit *current_head = NULL;
@ -1651,10 +1651,10 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
status_format = STATUS_FORMAT_NONE; /* Ignore status.short */ status_format = STATUS_FORMAT_NONE; /* Ignore status.short */
s.colopts = 0; s.colopts = 0;
if (get_sha1("HEAD", sha1)) if (get_sha1("HEAD", oid.hash))
current_head = NULL; current_head = NULL;
else { else {
current_head = lookup_commit_or_die(sha1, "HEAD"); current_head = lookup_commit_or_die(oid.hash, "HEAD");
if (parse_commit(current_head)) if (parse_commit(current_head))
die(_("could not parse HEAD commit")); die(_("could not parse HEAD commit"));
} }
@ -1759,7 +1759,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
} }
if (commit_tree_extended(sb.buf, sb.len, active_cache_tree->sha1, if (commit_tree_extended(sb.buf, sb.len, active_cache_tree->sha1,
parents, sha1, author_ident.buf, sign_commit, extra)) { parents, oid.hash, author_ident.buf, sign_commit, extra)) {
rollback_index_files(); rollback_index_files();
die(_("failed to write commit object")); die(_("failed to write commit object"));
} }
@ -1776,7 +1776,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
transaction = ref_transaction_begin(&err); transaction = ref_transaction_begin(&err);
if (!transaction || if (!transaction ||
ref_transaction_update(transaction, "HEAD", sha1, ref_transaction_update(transaction, "HEAD", oid.hash,
current_head current_head
? current_head->object.oid.hash : null_sha1, ? current_head->object.oid.hash : null_sha1,
0, sb.buf, &err) || 0, sb.buf, &err) ||
@ -1805,13 +1805,13 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
cfg = init_copy_notes_for_rewrite("amend"); cfg = init_copy_notes_for_rewrite("amend");
if (cfg) { if (cfg) {
/* we are amending, so current_head is not NULL */ /* we are amending, so current_head is not NULL */
copy_note_for_rewrite(cfg, current_head->object.oid.hash, sha1); copy_note_for_rewrite(cfg, current_head->object.oid.hash, oid.hash);
finish_copy_notes_for_rewrite(cfg, "Notes added by 'git commit --amend'"); finish_copy_notes_for_rewrite(cfg, "Notes added by 'git commit --amend'");
} }
run_rewrite_hook(current_head->object.oid.hash, sha1); run_rewrite_hook(&current_head->object.oid, &oid);
} }
if (!quiet) if (!quiet)
print_summary(prefix, sha1, !current_head); print_summary(prefix, &oid, !current_head);
strbuf_release(&err); strbuf_release(&err);
return 0; return 0;

View File

@ -53,7 +53,7 @@ static void loose_garbage(const char *path)
report_garbage(PACKDIR_FILE_GARBAGE, path); report_garbage(PACKDIR_FILE_GARBAGE, path);
} }
static int count_loose(const unsigned char *sha1, const char *path, void *data) static int count_loose(const struct object_id *oid, const char *path, void *data)
{ {
struct stat st; struct stat st;
@ -62,7 +62,7 @@ static int count_loose(const unsigned char *sha1, const char *path, void *data)
else { else {
loose_size += on_disk_bytes(st); loose_size += on_disk_bytes(st);
loose++; loose++;
if (verbose && has_sha1_pack(sha1)) if (verbose && has_sha1_pack(oid->hash))
packed_loose++; packed_loose++;
} }
return 0; return 0;

View File

@ -40,11 +40,11 @@ static const char *diff_index_args[] = {
struct commit_name { struct commit_name {
struct hashmap_entry entry; struct hashmap_entry entry;
unsigned char peeled[20]; struct object_id peeled;
struct tag *tag; struct tag *tag;
unsigned prio:2; /* annotated tag = 2, tag = 1, head = 0 */ unsigned prio:2; /* annotated tag = 2, tag = 1, head = 0 */
unsigned name_checked:1; unsigned name_checked:1;
unsigned char sha1[20]; struct object_id oid;
char *path; char *path;
}; };
@ -55,17 +55,17 @@ static const char *prio_names[] = {
static int commit_name_cmp(const struct commit_name *cn1, static int commit_name_cmp(const struct commit_name *cn1,
const struct commit_name *cn2, const void *peeled) const struct commit_name *cn2, const void *peeled)
{ {
return hashcmp(cn1->peeled, peeled ? peeled : cn2->peeled); return oidcmp(&cn1->peeled, peeled ? peeled : &cn2->peeled);
} }
static inline struct commit_name *find_commit_name(const unsigned char *peeled) static inline struct commit_name *find_commit_name(const struct object_id *peeled)
{ {
return hashmap_get_from_hash(&names, sha1hash(peeled), peeled); return hashmap_get_from_hash(&names, sha1hash(peeled->hash), peeled->hash);
} }
static int replace_name(struct commit_name *e, static int replace_name(struct commit_name *e,
int prio, int prio,
const unsigned char *sha1, const struct object_id *oid,
struct tag **tag) struct tag **tag)
{ {
if (!e || e->prio < prio) if (!e || e->prio < prio)
@ -78,13 +78,13 @@ static int replace_name(struct commit_name *e,
struct tag *t; struct tag *t;
if (!e->tag) { if (!e->tag) {
t = lookup_tag(e->sha1); t = lookup_tag(e->oid.hash);
if (!t || parse_tag(t)) if (!t || parse_tag(t))
return 1; return 1;
e->tag = t; e->tag = t;
} }
t = lookup_tag(sha1); t = lookup_tag(oid->hash);
if (!t || parse_tag(t)) if (!t || parse_tag(t))
return 0; return 0;
*tag = t; *tag = t;
@ -97,24 +97,24 @@ static int replace_name(struct commit_name *e,
} }
static void add_to_known_names(const char *path, static void add_to_known_names(const char *path,
const unsigned char *peeled, const struct object_id *peeled,
int prio, int prio,
const unsigned char *sha1) const struct object_id *oid)
{ {
struct commit_name *e = find_commit_name(peeled); struct commit_name *e = find_commit_name(peeled);
struct tag *tag = NULL; struct tag *tag = NULL;
if (replace_name(e, prio, sha1, &tag)) { if (replace_name(e, prio, oid, &tag)) {
if (!e) { if (!e) {
e = xmalloc(sizeof(struct commit_name)); e = xmalloc(sizeof(struct commit_name));
hashcpy(e->peeled, peeled); oidcpy(&e->peeled, peeled);
hashmap_entry_init(e, sha1hash(peeled)); hashmap_entry_init(e, sha1hash(peeled->hash));
hashmap_add(&names, e); hashmap_add(&names, e);
e->path = NULL; e->path = NULL;
} }
e->tag = tag; e->tag = tag;
e->prio = prio; e->prio = prio;
e->name_checked = 0; e->name_checked = 0;
hashcpy(e->sha1, sha1); oidcpy(&e->oid, oid);
free(e->path); free(e->path);
e->path = xstrdup(path); e->path = xstrdup(path);
} }
@ -186,7 +186,7 @@ static int get_name(const char *path, const struct object_id *oid, int flag, voi
else else
prio = 0; prio = 0;
add_to_known_names(all ? path + 5 : path + 10, peeled.hash, prio, oid->hash); add_to_known_names(all ? path + 5 : path + 10, &peeled, prio, oid);
return 0; return 0;
} }
@ -244,7 +244,7 @@ static unsigned long finish_depth_computation(
static void display_name(struct commit_name *n) static void display_name(struct commit_name *n)
{ {
if (n->prio == 2 && !n->tag) { if (n->prio == 2 && !n->tag) {
n->tag = lookup_tag(n->sha1); n->tag = lookup_tag(n->oid.hash);
if (!n->tag || parse_tag(n->tag)) if (!n->tag || parse_tag(n->tag))
die(_("annotated tag %s not available"), n->path); die(_("annotated tag %s not available"), n->path);
} }
@ -262,14 +262,14 @@ static void display_name(struct commit_name *n)
printf("%s", n->path); printf("%s", n->path);
} }
static void show_suffix(int depth, const unsigned char *sha1) static void show_suffix(int depth, const struct object_id *oid)
{ {
printf("-%d-g%s", depth, find_unique_abbrev(sha1, abbrev)); printf("-%d-g%s", depth, find_unique_abbrev(oid->hash, abbrev));
} }
static void describe(const char *arg, int last_one) static void describe(const char *arg, int last_one)
{ {
unsigned char sha1[20]; struct object_id oid;
struct commit *cmit, *gave_up_on = NULL; struct commit *cmit, *gave_up_on = NULL;
struct commit_list *list; struct commit_list *list;
struct commit_name *n; struct commit_name *n;
@ -278,20 +278,20 @@ static void describe(const char *arg, int last_one)
unsigned long seen_commits = 0; unsigned long seen_commits = 0;
unsigned int unannotated_cnt = 0; unsigned int unannotated_cnt = 0;
if (get_sha1(arg, sha1)) if (get_oid(arg, &oid))
die(_("Not a valid object name %s"), arg); die(_("Not a valid object name %s"), arg);
cmit = lookup_commit_reference(sha1); cmit = lookup_commit_reference(oid.hash);
if (!cmit) if (!cmit)
die(_("%s is not a valid '%s' object"), arg, commit_type); die(_("%s is not a valid '%s' object"), arg, commit_type);
n = find_commit_name(cmit->object.oid.hash); n = find_commit_name(&cmit->object.oid);
if (n && (tags || all || n->prio == 2)) { if (n && (tags || all || n->prio == 2)) {
/* /*
* Exact match to an existing ref. * Exact match to an existing ref.
*/ */
display_name(n); display_name(n);
if (longformat) if (longformat)
show_suffix(0, n->tag ? n->tag->tagged->oid.hash : sha1); show_suffix(0, n->tag ? &n->tag->tagged->oid : &oid);
if (dirty) if (dirty)
printf("%s", dirty); printf("%s", dirty);
printf("\n"); printf("\n");
@ -308,7 +308,7 @@ static void describe(const char *arg, int last_one)
struct commit *c; struct commit *c;
struct commit_name *n = hashmap_iter_first(&names, &iter); struct commit_name *n = hashmap_iter_first(&names, &iter);
for (; n; n = hashmap_iter_next(&iter)) { for (; n; n = hashmap_iter_next(&iter)) {
c = lookup_commit_reference_gently(n->peeled, 1); c = lookup_commit_reference_gently(n->peeled.hash, 1);
if (c) if (c)
c->util = n; c->util = n;
} }
@ -412,7 +412,7 @@ static void describe(const char *arg, int last_one)
display_name(all_matches[0].name); display_name(all_matches[0].name);
if (abbrev) if (abbrev)
show_suffix(all_matches[0].depth, cmit->object.oid.hash); show_suffix(all_matches[0].depth, &cmit->object.oid);
if (dirty) if (dirty)
printf("%s", dirty); printf("%s", dirty);
printf("\n"); printf("\n");

View File

@ -7,46 +7,44 @@
static struct rev_info log_tree_opt; static struct rev_info log_tree_opt;
static int diff_tree_commit_sha1(const unsigned char *sha1) static int diff_tree_commit_sha1(const struct object_id *oid)
{ {
struct commit *commit = lookup_commit_reference(sha1); struct commit *commit = lookup_commit_reference(oid->hash);
if (!commit) if (!commit)
return -1; return -1;
return log_tree_commit(&log_tree_opt, commit); return log_tree_commit(&log_tree_opt, commit);
} }
/* Diff one or more commits. */ /* Diff one or more commits. */
static int stdin_diff_commit(struct commit *commit, char *line, int len) static int stdin_diff_commit(struct commit *commit, const char *p)
{ {
unsigned char sha1[20]; struct object_id oid;
if (isspace(line[40]) && !get_sha1_hex(line+41, sha1)) { struct commit_list **pptr = NULL;
/* Graft the fake parents locally to the commit */
int pos = 41;
struct commit_list **pptr;
/* Free the real parent list */ /* Graft the fake parents locally to the commit */
free_commit_list(commit->parents); while (isspace(*p++) && !parse_oid_hex(p, &oid, &p)) {
commit->parents = NULL; struct commit *parent = lookup_commit(oid.hash);
pptr = &(commit->parents); if (!pptr) {
while (line[pos] && !get_sha1_hex(line + pos, sha1)) { /* Free the real parent list */
struct commit *parent = lookup_commit(sha1); free_commit_list(commit->parents);
if (parent) { commit->parents = NULL;
pptr = &commit_list_insert(parent, pptr)->next; pptr = &(commit->parents);
} }
pos += 41; if (parent) {
pptr = &commit_list_insert(parent, pptr)->next;
} }
} }
return log_tree_commit(&log_tree_opt, commit); return log_tree_commit(&log_tree_opt, commit);
} }
/* Diff two trees. */ /* Diff two trees. */
static int stdin_diff_trees(struct tree *tree1, char *line, int len) static int stdin_diff_trees(struct tree *tree1, const char *p)
{ {
unsigned char sha1[20]; struct object_id oid;
struct tree *tree2; struct tree *tree2;
if (len != 82 || !isspace(line[40]) || get_sha1_hex(line + 41, sha1)) if (!isspace(*p++) || parse_oid_hex(p, &oid, &p) || *p)
return error("Need exactly two trees, separated by a space"); return error("Need exactly two trees, separated by a space");
tree2 = lookup_tree(sha1); tree2 = lookup_tree(oid.hash);
if (!tree2 || parse_tree(tree2)) if (!tree2 || parse_tree(tree2))
return -1; return -1;
printf("%s %s\n", oid_to_hex(&tree1->object.oid), printf("%s %s\n", oid_to_hex(&tree1->object.oid),
@ -60,23 +58,24 @@ static int stdin_diff_trees(struct tree *tree1, char *line, int len)
static int diff_tree_stdin(char *line) static int diff_tree_stdin(char *line)
{ {
int len = strlen(line); int len = strlen(line);
unsigned char sha1[20]; struct object_id oid;
struct object *obj; struct object *obj;
const char *p;
if (!len || line[len-1] != '\n') if (!len || line[len-1] != '\n')
return -1; return -1;
line[len-1] = 0; line[len-1] = 0;
if (get_sha1_hex(line, sha1)) if (parse_oid_hex(line, &oid, &p))
return -1; return -1;
obj = parse_object(sha1); obj = parse_object(oid.hash);
if (!obj) if (!obj)
return -1; return -1;
if (obj->type == OBJ_COMMIT) if (obj->type == OBJ_COMMIT)
return stdin_diff_commit((struct commit *)obj, line, len); return stdin_diff_commit((struct commit *)obj, p);
if (obj->type == OBJ_TREE) if (obj->type == OBJ_TREE)
return stdin_diff_trees((struct tree *)obj, line, len); return stdin_diff_trees((struct tree *)obj, p);
error("Object %s is a %s, not a commit or tree", error("Object %s is a %s, not a commit or tree",
sha1_to_hex(sha1), typename(obj->type)); oid_to_hex(&oid), typename(obj->type));
return -1; return -1;
} }
@ -141,7 +140,7 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix)
break; break;
case 1: case 1:
tree1 = opt->pending.objects[0].item; tree1 = opt->pending.objects[0].item;
diff_tree_commit_sha1(tree1->oid.hash); diff_tree_commit_sha1(&tree1->oid);
break; break;
case 2: case 2:
tree1 = opt->pending.objects[0].item; tree1 = opt->pending.objects[0].item;
@ -164,9 +163,9 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix)
opt->diffopt.setup |= (DIFF_SETUP_USE_SIZE_CACHE | opt->diffopt.setup |= (DIFF_SETUP_USE_SIZE_CACHE |
DIFF_SETUP_USE_CACHE); DIFF_SETUP_USE_CACHE);
while (fgets(line, sizeof(line), stdin)) { while (fgets(line, sizeof(line), stdin)) {
unsigned char sha1[20]; struct object_id oid;
if (get_sha1_hex(line, sha1)) { if (get_oid_hex(line, &oid)) {
fputs(line, stdout); fputs(line, stdout);
fflush(stdout); fflush(stdout);
} }

View File

@ -212,7 +212,7 @@ static char *anonymize_blob(unsigned long *size)
return strbuf_detach(&out, NULL); return strbuf_detach(&out, NULL);
} }
static void export_blob(const unsigned char *sha1) static void export_blob(const struct object_id *oid)
{ {
unsigned long size; unsigned long size;
enum object_type type; enum object_type type;
@ -223,34 +223,34 @@ static void export_blob(const unsigned char *sha1)
if (no_data) if (no_data)
return; return;
if (is_null_sha1(sha1)) if (is_null_oid(oid))
return; return;
object = lookup_object(sha1); object = lookup_object(oid->hash);
if (object && object->flags & SHOWN) if (object && object->flags & SHOWN)
return; return;
if (anonymize) { if (anonymize) {
buf = anonymize_blob(&size); buf = anonymize_blob(&size);
object = (struct object *)lookup_blob(sha1); object = (struct object *)lookup_blob(oid->hash);
eaten = 0; eaten = 0;
} else { } else {
buf = read_sha1_file(sha1, &type, &size); buf = read_sha1_file(oid->hash, &type, &size);
if (!buf) if (!buf)
die ("Could not read blob %s", sha1_to_hex(sha1)); die ("Could not read blob %s", oid_to_hex(oid));
if (check_sha1_signature(sha1, buf, size, typename(type)) < 0) if (check_sha1_signature(oid->hash, buf, size, typename(type)) < 0)
die("sha1 mismatch in blob %s", sha1_to_hex(sha1)); die("sha1 mismatch in blob %s", oid_to_hex(oid));
object = parse_object_buffer(sha1, type, size, buf, &eaten); object = parse_object_buffer(oid->hash, type, size, buf, &eaten);
} }
if (!object) if (!object)
die("Could not read blob %s", sha1_to_hex(sha1)); die("Could not read blob %s", oid_to_hex(oid));
mark_next_object(object); mark_next_object(object);
printf("blob\nmark :%"PRIu32"\ndata %lu\n", last_idnum, size); printf("blob\nmark :%"PRIu32"\ndata %lu\n", last_idnum, size);
if (size && fwrite(buf, size, 1, stdout) != 1) if (size && fwrite(buf, size, 1, stdout) != 1)
die_errno ("Could not write blob '%s'", sha1_to_hex(sha1)); die_errno ("Could not write blob '%s'", oid_to_hex(oid));
printf("\n"); printf("\n");
show_progress(); show_progress();
@ -323,19 +323,19 @@ static void print_path(const char *path)
} }
} }
static void *generate_fake_sha1(const void *old, size_t *len) static void *generate_fake_oid(const void *old, size_t *len)
{ {
static uint32_t counter = 1; /* avoid null sha1 */ static uint32_t counter = 1; /* avoid null sha1 */
unsigned char *out = xcalloc(20, 1); unsigned char *out = xcalloc(GIT_SHA1_RAWSZ, 1);
put_be32(out + 16, counter++); put_be32(out + GIT_SHA1_RAWSZ - 4, counter++);
return out; return out;
} }
static const unsigned char *anonymize_sha1(const unsigned char *sha1) static const unsigned char *anonymize_sha1(const struct object_id *oid)
{ {
static struct hashmap sha1s; static struct hashmap sha1s;
size_t len = 20; size_t len = GIT_SHA1_RAWSZ;
return anonymize_mem(&sha1s, generate_fake_sha1, sha1, &len); return anonymize_mem(&sha1s, generate_fake_oid, oid, &len);
} }
static void show_filemodify(struct diff_queue_struct *q, static void show_filemodify(struct diff_queue_struct *q,
@ -383,7 +383,7 @@ static void show_filemodify(struct diff_queue_struct *q,
if (no_data || S_ISGITLINK(spec->mode)) if (no_data || S_ISGITLINK(spec->mode))
printf("M %06o %s ", spec->mode, printf("M %06o %s ", spec->mode,
sha1_to_hex(anonymize ? sha1_to_hex(anonymize ?
anonymize_sha1(spec->oid.hash) : anonymize_sha1(&spec->oid) :
spec->oid.hash)); spec->oid.hash));
else { else {
struct object *object = lookup_object(spec->oid.hash); struct object *object = lookup_object(spec->oid.hash);
@ -572,7 +572,7 @@ static void handle_commit(struct commit *commit, struct rev_info *rev)
/* Export the referenced blobs, and remember the marks. */ /* Export the referenced blobs, and remember the marks. */
for (i = 0; i < diff_queued_diff.nr; i++) for (i = 0; i < diff_queued_diff.nr; i++)
if (!S_ISGITLINK(diff_queued_diff.queue[i]->two->mode)) if (!S_ISGITLINK(diff_queued_diff.queue[i]->two->mode))
export_blob(diff_queued_diff.queue[i]->two->oid.hash); export_blob(&diff_queued_diff.queue[i]->two->oid);
refname = commit->util; refname = commit->util;
if (anonymize) { if (anonymize) {
@ -797,14 +797,14 @@ static void get_tags_and_duplicates(struct rev_cmdline_info *info)
for (i = 0; i < info->nr; i++) { for (i = 0; i < info->nr; i++) {
struct rev_cmdline_entry *e = info->rev + i; struct rev_cmdline_entry *e = info->rev + i;
unsigned char sha1[20]; struct object_id oid;
struct commit *commit; struct commit *commit;
char *full_name; char *full_name;
if (e->flags & UNINTERESTING) if (e->flags & UNINTERESTING)
continue; continue;
if (dwim_ref(e->name, strlen(e->name), sha1, &full_name) != 1) if (dwim_ref(e->name, strlen(e->name), oid.hash, &full_name) != 1)
continue; continue;
if (refspecs) { if (refspecs) {
@ -828,7 +828,7 @@ static void get_tags_and_duplicates(struct rev_cmdline_info *info)
case OBJ_COMMIT: case OBJ_COMMIT:
break; break;
case OBJ_BLOB: case OBJ_BLOB:
export_blob(commit->object.oid.hash); export_blob(&commit->object.oid);
continue; continue;
default: /* OBJ_TAG (nested tags) is already handled */ default: /* OBJ_TAG (nested tags) is already handled */
warning("Tag points to object of unexpected type %s, skipping.", warning("Tag points to object of unexpected type %s, skipping.",
@ -912,7 +912,7 @@ static void import_marks(char *input_file)
while (fgets(line, sizeof(line), f)) { while (fgets(line, sizeof(line), f)) {
uint32_t mark; uint32_t mark;
char *line_end, *mark_end; char *line_end, *mark_end;
unsigned char sha1[20]; struct object_id oid;
struct object *object; struct object *object;
struct commit *commit; struct commit *commit;
enum object_type type; enum object_type type;
@ -924,28 +924,28 @@ static void import_marks(char *input_file)
mark = strtoumax(line + 1, &mark_end, 10); mark = strtoumax(line + 1, &mark_end, 10);
if (!mark || mark_end == line + 1 if (!mark || mark_end == line + 1
|| *mark_end != ' ' || get_sha1_hex(mark_end + 1, sha1)) || *mark_end != ' ' || get_oid_hex(mark_end + 1, &oid))
die("corrupt mark line: %s", line); die("corrupt mark line: %s", line);
if (last_idnum < mark) if (last_idnum < mark)
last_idnum = mark; last_idnum = mark;
type = sha1_object_info(sha1, NULL); type = sha1_object_info(oid.hash, NULL);
if (type < 0) if (type < 0)
die("object not found: %s", sha1_to_hex(sha1)); die("object not found: %s", oid_to_hex(&oid));
if (type != OBJ_COMMIT) if (type != OBJ_COMMIT)
/* only commits */ /* only commits */
continue; continue;
commit = lookup_commit(sha1); commit = lookup_commit(oid.hash);
if (!commit) if (!commit)
die("not a commit? can't happen: %s", sha1_to_hex(sha1)); die("not a commit? can't happen: %s", oid_to_hex(&oid));
object = &commit->object; object = &commit->object;
if (object->flags & SHOWN) if (object->flags & SHOWN)
error("Object %s already has a mark", sha1_to_hex(sha1)); error("Object %s already has a mark", oid_to_hex(&oid));
mark_object(object, mark); mark_object(object, mark);

View File

@ -41,7 +41,7 @@ struct src_data {
}; };
struct origin_data { struct origin_data {
unsigned char sha1[20]; struct object_id oid;
unsigned is_local_branch:1; unsigned is_local_branch:1;
}; };
@ -59,8 +59,8 @@ static struct string_list origins = STRING_LIST_INIT_DUP;
struct merge_parents { struct merge_parents {
int alloc, nr; int alloc, nr;
struct merge_parent { struct merge_parent {
unsigned char given[20]; struct object_id given;
unsigned char commit[20]; struct object_id commit;
unsigned char used; unsigned char used;
} *item; } *item;
}; };
@ -70,14 +70,14 @@ struct merge_parents {
* hundreds of heads at a time anyway. * hundreds of heads at a time anyway.
*/ */
static struct merge_parent *find_merge_parent(struct merge_parents *table, static struct merge_parent *find_merge_parent(struct merge_parents *table,
unsigned char *given, struct object_id *given,
unsigned char *commit) struct object_id *commit)
{ {
int i; int i;
for (i = 0; i < table->nr; i++) { for (i = 0; i < table->nr; i++) {
if (given && hashcmp(table->item[i].given, given)) if (given && oidcmp(&table->item[i].given, given))
continue; continue;
if (commit && hashcmp(table->item[i].commit, commit)) if (commit && oidcmp(&table->item[i].commit, commit))
continue; continue;
return &table->item[i]; return &table->item[i];
} }
@ -85,14 +85,14 @@ static struct merge_parent *find_merge_parent(struct merge_parents *table,
} }
static void add_merge_parent(struct merge_parents *table, static void add_merge_parent(struct merge_parents *table,
unsigned char *given, struct object_id *given,
unsigned char *commit) struct object_id *commit)
{ {
if (table->nr && find_merge_parent(table, given, commit)) if (table->nr && find_merge_parent(table, given, commit))
return; return;
ALLOC_GROW(table->item, table->nr + 1, table->alloc); ALLOC_GROW(table->item, table->nr + 1, table->alloc);
hashcpy(table->item[table->nr].given, given); oidcpy(&table->item[table->nr].given, given);
hashcpy(table->item[table->nr].commit, commit); oidcpy(&table->item[table->nr].commit, commit);
table->item[table->nr].used = 0; table->item[table->nr].used = 0;
table->nr++; table->nr++;
} }
@ -106,30 +106,30 @@ static int handle_line(char *line, struct merge_parents *merge_parents)
struct src_data *src_data; struct src_data *src_data;
struct string_list_item *item; struct string_list_item *item;
int pulling_head = 0; int pulling_head = 0;
unsigned char sha1[20]; struct object_id oid;
if (len < 43 || line[40] != '\t') if (len < GIT_SHA1_HEXSZ + 3 || line[GIT_SHA1_HEXSZ] != '\t')
return 1; return 1;
if (starts_with(line + 41, "not-for-merge")) if (starts_with(line + GIT_SHA1_HEXSZ + 1, "not-for-merge"))
return 0; return 0;
if (line[41] != '\t') if (line[GIT_SHA1_HEXSZ + 1] != '\t')
return 2; return 2;
i = get_sha1_hex(line, sha1); i = get_oid_hex(line, &oid);
if (i) if (i)
return 3; return 3;
if (!find_merge_parent(merge_parents, sha1, NULL)) if (!find_merge_parent(merge_parents, &oid, NULL))
return 0; /* subsumed by other parents */ return 0; /* subsumed by other parents */
origin_data = xcalloc(1, sizeof(struct origin_data)); origin_data = xcalloc(1, sizeof(struct origin_data));
hashcpy(origin_data->sha1, sha1); oidcpy(&origin_data->oid, &oid);
if (line[len - 1] == '\n') if (line[len - 1] == '\n')
line[len - 1] = 0; line[len - 1] = 0;
line += 42; line += GIT_SHA1_HEXSZ + 2;
/* /*
* At this point, line points at the beginning of comment e.g. * At this point, line points at the beginning of comment e.g.
@ -338,10 +338,10 @@ static void shortlog(const char *name,
struct string_list committers = STRING_LIST_INIT_DUP; struct string_list committers = STRING_LIST_INIT_DUP;
int flags = UNINTERESTING | TREESAME | SEEN | SHOWN | ADDED; int flags = UNINTERESTING | TREESAME | SEEN | SHOWN | ADDED;
struct strbuf sb = STRBUF_INIT; struct strbuf sb = STRBUF_INIT;
const unsigned char *sha1 = origin_data->sha1; const struct object_id *oid = &origin_data->oid;
int limit = opts->shortlog_len; int limit = opts->shortlog_len;
branch = deref_tag(parse_object(sha1), sha1_to_hex(sha1), 40); branch = deref_tag(parse_object(oid->hash), oid_to_hex(oid), GIT_SHA1_HEXSZ);
if (!branch || branch->type != OBJ_COMMIT) if (!branch || branch->type != OBJ_COMMIT)
return; return;
@ -531,7 +531,7 @@ static void fmt_merge_msg_sigs(struct strbuf *out)
} }
static void find_merge_parents(struct merge_parents *result, static void find_merge_parents(struct merge_parents *result,
struct strbuf *in, unsigned char *head) struct strbuf *in, struct object_id *head)
{ {
struct commit_list *parents; struct commit_list *parents;
struct commit *head_commit; struct commit *head_commit;
@ -542,31 +542,31 @@ static void find_merge_parents(struct merge_parents *result,
int len; int len;
char *p = in->buf + pos; char *p = in->buf + pos;
char *newline = strchr(p, '\n'); char *newline = strchr(p, '\n');
unsigned char sha1[20]; struct object_id oid;
struct commit *parent; struct commit *parent;
struct object *obj; struct object *obj;
len = newline ? newline - p : strlen(p); len = newline ? newline - p : strlen(p);
pos += len + !!newline; pos += len + !!newline;
if (len < 43 || if (len < GIT_SHA1_HEXSZ + 3 ||
get_sha1_hex(p, sha1) || get_oid_hex(p, &oid) ||
p[40] != '\t' || p[GIT_SHA1_HEXSZ] != '\t' ||
p[41] != '\t') p[GIT_SHA1_HEXSZ + 1] != '\t')
continue; /* skip not-for-merge */ continue; /* skip not-for-merge */
/* /*
* Do not use get_merge_parent() here; we do not have * Do not use get_merge_parent() here; we do not have
* "name" here and we do not want to contaminate its * "name" here and we do not want to contaminate its
* util field yet. * util field yet.
*/ */
obj = parse_object(sha1); obj = parse_object(oid.hash);
parent = (struct commit *)peel_to_type(NULL, 0, obj, OBJ_COMMIT); parent = (struct commit *)peel_to_type(NULL, 0, obj, OBJ_COMMIT);
if (!parent) if (!parent)
continue; continue;
commit_list_insert(parent, &parents); commit_list_insert(parent, &parents);
add_merge_parent(result, obj->oid.hash, parent->object.oid.hash); add_merge_parent(result, &obj->oid, &parent->object.oid);
} }
head_commit = lookup_commit(head); head_commit = lookup_commit(head->hash);
if (head_commit) if (head_commit)
commit_list_insert(head_commit, &parents); commit_list_insert(head_commit, &parents);
parents = reduce_heads(parents); parents = reduce_heads(parents);
@ -574,7 +574,7 @@ static void find_merge_parents(struct merge_parents *result,
while (parents) { while (parents) {
struct commit *cmit = pop_commit(&parents); struct commit *cmit = pop_commit(&parents);
for (i = 0; i < result->nr; i++) for (i = 0; i < result->nr; i++)
if (!hashcmp(result->item[i].commit, cmit->object.oid.hash)) if (!oidcmp(&result->item[i].commit, &cmit->object.oid))
result->item[i].used = 1; result->item[i].used = 1;
} }
@ -592,7 +592,7 @@ int fmt_merge_msg(struct strbuf *in, struct strbuf *out,
struct fmt_merge_msg_opts *opts) struct fmt_merge_msg_opts *opts)
{ {
int i = 0, pos = 0; int i = 0, pos = 0;
unsigned char head_sha1[20]; struct object_id head_oid;
const char *current_branch; const char *current_branch;
void *current_branch_to_free; void *current_branch_to_free;
struct merge_parents merge_parents; struct merge_parents merge_parents;
@ -601,13 +601,13 @@ int fmt_merge_msg(struct strbuf *in, struct strbuf *out,
/* get current branch */ /* get current branch */
current_branch = current_branch_to_free = current_branch = current_branch_to_free =
resolve_refdup("HEAD", RESOLVE_REF_READING, head_sha1, NULL); resolve_refdup("HEAD", RESOLVE_REF_READING, head_oid.hash, NULL);
if (!current_branch) if (!current_branch)
die("No current branch"); die("No current branch");
if (starts_with(current_branch, "refs/heads/")) if (starts_with(current_branch, "refs/heads/"))
current_branch += 11; current_branch += 11;
find_merge_parents(&merge_parents, in, head_sha1); find_merge_parents(&merge_parents, in, &head_oid);
/* get a line */ /* get a line */
while (pos < in->len) { while (pos < in->len) {
@ -633,7 +633,7 @@ int fmt_merge_msg(struct strbuf *in, struct strbuf *out,
struct commit *head; struct commit *head;
struct rev_info rev; struct rev_info rev;
head = lookup_commit_or_die(head_sha1, "HEAD"); head = lookup_commit_or_die(head_oid.hash, "HEAD");
init_revisions(&rev, NULL); init_revisions(&rev, NULL);
rev.commit_format = CMIT_FMT_ONELINE; rev.commit_format = CMIT_FMT_ONELINE;
rev.ignore_merges = 1; rev.ignore_merges = 1;

View File

@ -396,13 +396,13 @@ static int fsck_obj_buffer(const unsigned char *sha1, enum object_type type,
static int default_refs; static int default_refs;
static void fsck_handle_reflog_sha1(const char *refname, unsigned char *sha1, static void fsck_handle_reflog_oid(const char *refname, struct object_id *oid,
unsigned long timestamp) unsigned long timestamp)
{ {
struct object *obj; struct object *obj;
if (!is_null_sha1(sha1)) { if (!is_null_oid(oid)) {
obj = lookup_object(sha1); obj = lookup_object(oid->hash);
if (obj && (obj->flags & HAS_OBJ)) { if (obj && (obj->flags & HAS_OBJ)) {
if (timestamp && name_objects) if (timestamp && name_objects)
add_decoration(fsck_walk_options.object_names, add_decoration(fsck_walk_options.object_names,
@ -411,13 +411,13 @@ static void fsck_handle_reflog_sha1(const char *refname, unsigned char *sha1,
obj->used = 1; obj->used = 1;
mark_object_reachable(obj); mark_object_reachable(obj);
} else { } else {
error("%s: invalid reflog entry %s", refname, sha1_to_hex(sha1)); error("%s: invalid reflog entry %s", refname, oid_to_hex(oid));
errors_found |= ERROR_REACHABLE; errors_found |= ERROR_REACHABLE;
} }
} }
} }
static int fsck_handle_reflog_ent(unsigned char *osha1, unsigned char *nsha1, static int fsck_handle_reflog_ent(struct object_id *ooid, struct object_id *noid,
const char *email, unsigned long timestamp, int tz, const char *email, unsigned long timestamp, int tz,
const char *message, void *cb_data) const char *message, void *cb_data)
{ {
@ -425,10 +425,10 @@ static int fsck_handle_reflog_ent(unsigned char *osha1, unsigned char *nsha1,
if (verbose) if (verbose)
fprintf(stderr, "Checking reflog %s->%s\n", fprintf(stderr, "Checking reflog %s->%s\n",
sha1_to_hex(osha1), sha1_to_hex(nsha1)); oid_to_hex(ooid), oid_to_hex(noid));
fsck_handle_reflog_sha1(refname, osha1, 0); fsck_handle_reflog_oid(refname, ooid, 0);
fsck_handle_reflog_sha1(refname, nsha1, timestamp); fsck_handle_reflog_oid(refname, noid, timestamp);
return 0; return 0;
} }
@ -491,7 +491,7 @@ static void get_default_heads(void)
} }
} }
static struct object *parse_loose_object(const unsigned char *sha1, static struct object *parse_loose_object(const struct object_id *oid,
const char *path) const char *path)
{ {
struct object *obj; struct object *obj;
@ -500,27 +500,27 @@ static struct object *parse_loose_object(const unsigned char *sha1,
unsigned long size; unsigned long size;
int eaten; int eaten;
if (read_loose_object(path, sha1, &type, &size, &contents) < 0) if (read_loose_object(path, oid->hash, &type, &size, &contents) < 0)
return NULL; return NULL;
if (!contents && type != OBJ_BLOB) if (!contents && type != OBJ_BLOB)
die("BUG: read_loose_object streamed a non-blob"); die("BUG: read_loose_object streamed a non-blob");
obj = parse_object_buffer(sha1, type, size, contents, &eaten); obj = parse_object_buffer(oid->hash, type, size, contents, &eaten);
if (!eaten) if (!eaten)
free(contents); free(contents);
return obj; return obj;
} }
static int fsck_loose(const unsigned char *sha1, const char *path, void *data) static int fsck_loose(const struct object_id *oid, const char *path, void *data)
{ {
struct object *obj = parse_loose_object(sha1, path); struct object *obj = parse_loose_object(oid, path);
if (!obj) { if (!obj) {
errors_found |= ERROR_OBJECT; errors_found |= ERROR_OBJECT;
error("%s: object corrupt or missing: %s", error("%s: object corrupt or missing: %s",
sha1_to_hex(sha1), path); oid_to_hex(oid), path);
return 0; /* keep checking other objects */ return 0; /* keep checking other objects */
} }
@ -619,26 +619,26 @@ static int fsck_cache_tree(struct cache_tree *it)
return err; return err;
} }
static void mark_object_for_connectivity(const unsigned char *sha1) static void mark_object_for_connectivity(const struct object_id *oid)
{ {
struct object *obj = lookup_unknown_object(sha1); struct object *obj = lookup_unknown_object(oid->hash);
obj->flags |= HAS_OBJ; obj->flags |= HAS_OBJ;
} }
static int mark_loose_for_connectivity(const unsigned char *sha1, static int mark_loose_for_connectivity(const struct object_id *oid,
const char *path, const char *path,
void *data) void *data)
{ {
mark_object_for_connectivity(sha1); mark_object_for_connectivity(oid);
return 0; return 0;
} }
static int mark_packed_for_connectivity(const unsigned char *sha1, static int mark_packed_for_connectivity(const struct object_id *oid,
struct packed_git *pack, struct packed_git *pack,
uint32_t pos, uint32_t pos,
void *data) void *data)
{ {
mark_object_for_connectivity(sha1); mark_object_for_connectivity(oid);
return 0; return 0;
} }

View File

@ -294,17 +294,17 @@ static int grep_cmd_config(const char *var, const char *value, void *cb)
return st; return st;
} }
static void *lock_and_read_sha1_file(const unsigned char *sha1, enum object_type *type, unsigned long *size) static void *lock_and_read_oid_file(const struct object_id *oid, enum object_type *type, unsigned long *size)
{ {
void *data; void *data;
grep_read_lock(); grep_read_lock();
data = read_sha1_file(sha1, type, size); data = read_sha1_file(oid->hash, type, size);
grep_read_unlock(); grep_read_unlock();
return data; return data;
} }
static int grep_sha1(struct grep_opt *opt, const unsigned char *sha1, static int grep_oid(struct grep_opt *opt, const struct object_id *oid,
const char *filename, int tree_name_len, const char *filename, int tree_name_len,
const char *path) const char *path)
{ {
@ -323,7 +323,7 @@ static int grep_sha1(struct grep_opt *opt, const unsigned char *sha1,
#ifndef NO_PTHREADS #ifndef NO_PTHREADS
if (num_threads) { if (num_threads) {
add_work(opt, GREP_SOURCE_SHA1, pathbuf.buf, path, sha1); add_work(opt, GREP_SOURCE_SHA1, pathbuf.buf, path, oid);
strbuf_release(&pathbuf); strbuf_release(&pathbuf);
return 0; return 0;
} else } else
@ -332,7 +332,7 @@ static int grep_sha1(struct grep_opt *opt, const unsigned char *sha1,
struct grep_source gs; struct grep_source gs;
int hit; int hit;
grep_source_init(&gs, GREP_SOURCE_SHA1, pathbuf.buf, path, sha1); grep_source_init(&gs, GREP_SOURCE_SHA1, pathbuf.buf, path, oid);
strbuf_release(&pathbuf); strbuf_release(&pathbuf);
hit = grep_source(opt, &gs); hit = grep_source(opt, &gs);
@ -690,7 +690,7 @@ static int grep_cache(struct grep_opt *opt, const struct pathspec *pathspec,
ce_skip_worktree(ce)) { 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->oid.hash, ce->name, hit |= grep_oid(opt, &ce->oid, ce->name,
0, ce->name); 0, ce->name);
} else { } else {
hit |= grep_file(opt, ce->name); hit |= grep_file(opt, ce->name);
@ -750,7 +750,7 @@ static int grep_tree(struct grep_opt *opt, const struct pathspec *pathspec,
strbuf_add(base, entry.path, te_len); strbuf_add(base, entry.path, te_len);
if (S_ISREG(entry.mode)) { if (S_ISREG(entry.mode)) {
hit |= grep_sha1(opt, entry.oid->hash, base->buf, tn_len, hit |= grep_oid(opt, entry.oid, base->buf, tn_len,
check_attr ? base->buf + tn_len : NULL); check_attr ? base->buf + tn_len : NULL);
} else if (S_ISDIR(entry.mode)) { } else if (S_ISDIR(entry.mode)) {
enum object_type type; enum object_type type;
@ -758,7 +758,7 @@ static int grep_tree(struct grep_opt *opt, const struct pathspec *pathspec,
void *data; void *data;
unsigned long size; unsigned long size;
data = lock_and_read_sha1_file(entry.oid->hash, &type, &size); data = lock_and_read_oid_file(entry.oid, &type, &size);
if (!data) if (!data)
die(_("unable to read tree (%s)"), die(_("unable to read tree (%s)"),
oid_to_hex(entry.oid)); oid_to_hex(entry.oid));
@ -787,7 +787,7 @@ static int grep_object(struct grep_opt *opt, const struct pathspec *pathspec,
struct object *obj, const char *name, const char *path) struct object *obj, const char *name, const char *path)
{ {
if (obj->type == OBJ_BLOB) if (obj->type == OBJ_BLOB)
return grep_sha1(opt, obj->oid.hash, name, 0, path); return grep_oid(opt, &obj->oid, name, 0, path);
if (obj->type == OBJ_COMMIT || obj->type == OBJ_TREE) { if (obj->type == OBJ_COMMIT || obj->type == OBJ_TREE) {
struct tree_desc tree; struct tree_desc tree;
void *data; void *data;
@ -1169,7 +1169,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
allow_revs = use_index && !untracked; allow_revs = use_index && !untracked;
for (i = 0; i < argc; i++) { for (i = 0; i < argc; i++) {
const char *arg = argv[i]; const char *arg = argv[i];
unsigned char sha1[20]; struct object_id oid;
struct object_context oc; struct object_context oc;
struct object *object; struct object *object;
@ -1184,13 +1184,13 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
break; break;
} }
if (get_sha1_with_context(arg, 0, sha1, &oc)) { if (get_sha1_with_context(arg, 0, oid.hash, &oc)) {
if (seen_dashdash) if (seen_dashdash)
die(_("unable to resolve revision: %s"), arg); die(_("unable to resolve revision: %s"), arg);
break; break;
} }
object = parse_object_or_die(sha1, arg); object = parse_object_or_die(oid.hash, arg);
if (!seen_dashdash) if (!seen_dashdash)
verify_non_filename(prefix, arg); verify_non_filename(prefix, arg);
add_object_array_with_path(object, arg, &list, oc.mode, oc.path); add_object_array_with_path(object, arg, &list, oc.mode, oc.path);

View File

@ -36,12 +36,12 @@ static const char * const merge_base_usage[] = {
static struct commit *get_commit_reference(const char *arg) static struct commit *get_commit_reference(const char *arg)
{ {
unsigned char revkey[20]; struct object_id revkey;
struct commit *r; struct commit *r;
if (get_sha1(arg, revkey)) if (get_oid(arg, &revkey))
die("Not a valid object name %s", arg); die("Not a valid object name %s", arg);
r = lookup_commit_reference(revkey); r = lookup_commit_reference(revkey.hash);
if (!r) if (!r)
die("Not a valid commit name %s", arg); die("Not a valid commit name %s", arg);
@ -113,14 +113,14 @@ struct rev_collect {
unsigned int initial : 1; unsigned int initial : 1;
}; };
static void add_one_commit(unsigned char *sha1, struct rev_collect *revs) static void add_one_commit(struct object_id *oid, struct rev_collect *revs)
{ {
struct commit *commit; struct commit *commit;
if (is_null_sha1(sha1)) if (is_null_oid(oid))
return; return;
commit = lookup_commit(sha1); commit = lookup_commit(oid->hash);
if (!commit || if (!commit ||
(commit->object.flags & TMP_MARK) || (commit->object.flags & TMP_MARK) ||
parse_commit(commit)) parse_commit(commit))
@ -131,7 +131,7 @@ static void add_one_commit(unsigned char *sha1, struct rev_collect *revs)
commit->object.flags |= TMP_MARK; commit->object.flags |= TMP_MARK;
} }
static int collect_one_reflog_ent(unsigned char *osha1, unsigned char *nsha1, static int collect_one_reflog_ent(struct object_id *ooid, struct object_id *noid,
const char *ident, unsigned long timestamp, const char *ident, unsigned long timestamp,
int tz, const char *message, void *cbdata) int tz, const char *message, void *cbdata)
{ {
@ -139,15 +139,15 @@ static int collect_one_reflog_ent(unsigned char *osha1, unsigned char *nsha1,
if (revs->initial) { if (revs->initial) {
revs->initial = 0; revs->initial = 0;
add_one_commit(osha1, revs); add_one_commit(ooid, revs);
} }
add_one_commit(nsha1, revs); add_one_commit(noid, revs);
return 0; return 0;
} }
static int handle_fork_point(int argc, const char **argv) static int handle_fork_point(int argc, const char **argv)
{ {
unsigned char sha1[20]; struct object_id oid;
char *refname; char *refname;
const char *commitname; const char *commitname;
struct rev_collect revs; struct rev_collect revs;
@ -155,7 +155,7 @@ static int handle_fork_point(int argc, const char **argv)
struct commit_list *bases; struct commit_list *bases;
int i, ret = 0; int i, ret = 0;
switch (dwim_ref(argv[0], strlen(argv[0]), sha1, &refname)) { switch (dwim_ref(argv[0], strlen(argv[0]), oid.hash, &refname)) {
case 0: case 0:
die("No such ref: '%s'", argv[0]); die("No such ref: '%s'", argv[0]);
case 1: case 1:
@ -165,16 +165,16 @@ static int handle_fork_point(int argc, const char **argv)
} }
commitname = (argc == 2) ? argv[1] : "HEAD"; commitname = (argc == 2) ? argv[1] : "HEAD";
if (get_sha1(commitname, sha1)) if (get_oid(commitname, &oid))
die("Not a valid object name: '%s'", commitname); die("Not a valid object name: '%s'", commitname);
derived = lookup_commit_reference(sha1); derived = lookup_commit_reference(oid.hash);
memset(&revs, 0, sizeof(revs)); memset(&revs, 0, sizeof(revs));
revs.initial = 1; revs.initial = 1;
for_each_reflog_ent(refname, collect_one_reflog_ent, &revs); for_each_reflog_ent(refname, collect_one_reflog_ent, &revs);
if (!revs.nr && !get_sha1(refname, sha1)) if (!revs.nr && !get_oid(refname, &oid))
add_one_commit(sha1, &revs); add_one_commit(&oid, &revs);
for (i = 0; i < revs.nr; i++) for (i = 0; i < revs.nr; i++)
revs.commit[i]->object.flags &= ~TMP_MARK; revs.commit[i]->object.flags &= ~TMP_MARK;

View File

@ -244,7 +244,7 @@ static void drop_save(void)
unlink(git_path_merge_mode()); unlink(git_path_merge_mode());
} }
static int save_state(unsigned char *stash) static int save_state(struct object_id *stash)
{ {
int len; int len;
struct child_process cp = CHILD_PROCESS_INIT; struct child_process cp = CHILD_PROCESS_INIT;
@ -265,7 +265,7 @@ static int save_state(unsigned char *stash)
else if (!len) /* no changes */ else if (!len) /* no changes */
return -1; return -1;
strbuf_setlen(&buffer, buffer.len-1); strbuf_setlen(&buffer, buffer.len-1);
if (get_sha1(buffer.buf, stash)) if (get_oid(buffer.buf, stash))
die(_("not a valid object: %s"), buffer.buf); die(_("not a valid object: %s"), buffer.buf);
return 0; return 0;
} }
@ -305,18 +305,18 @@ static void reset_hard(unsigned const char *sha1, int verbose)
die(_("read-tree failed")); die(_("read-tree failed"));
} }
static void restore_state(const unsigned char *head, static void restore_state(const struct object_id *head,
const unsigned char *stash) const struct object_id *stash)
{ {
struct strbuf sb = STRBUF_INIT; struct strbuf sb = STRBUF_INIT;
const char *args[] = { "stash", "apply", NULL, NULL }; const char *args[] = { "stash", "apply", NULL, NULL };
if (is_null_sha1(stash)) if (is_null_oid(stash))
return; return;
reset_hard(head, 1); reset_hard(head->hash, 1);
args[2] = sha1_to_hex(stash); args[2] = oid_to_hex(stash);
/* /*
* It is OK to ignore error here, for example when there was * It is OK to ignore error here, for example when there was
@ -376,10 +376,10 @@ static void squash_message(struct commit *commit, struct commit_list *remotehead
static void finish(struct commit *head_commit, static void finish(struct commit *head_commit,
struct commit_list *remoteheads, struct commit_list *remoteheads,
const unsigned char *new_head, const char *msg) const struct object_id *new_head, const char *msg)
{ {
struct strbuf reflog_message = STRBUF_INIT; struct strbuf reflog_message = STRBUF_INIT;
const unsigned char *head = head_commit->object.oid.hash; const struct object_id *head = &head_commit->object.oid;
if (!msg) if (!msg)
strbuf_addstr(&reflog_message, getenv("GIT_REFLOG_ACTION")); strbuf_addstr(&reflog_message, getenv("GIT_REFLOG_ACTION"));
@ -397,7 +397,7 @@ static void finish(struct commit *head_commit,
else { else {
const char *argv_gc_auto[] = { "gc", "--auto", NULL }; const char *argv_gc_auto[] = { "gc", "--auto", NULL };
update_ref(reflog_message.buf, "HEAD", update_ref(reflog_message.buf, "HEAD",
new_head, head, 0, new_head->hash, head->hash, 0,
UPDATE_REFS_DIE_ON_ERR); UPDATE_REFS_DIE_ON_ERR);
/* /*
* We ignore errors in 'gc --auto', since the * We ignore errors in 'gc --auto', since the
@ -416,7 +416,7 @@ static void finish(struct commit *head_commit,
DIFF_FORMAT_SUMMARY | DIFF_FORMAT_DIFFSTAT; DIFF_FORMAT_SUMMARY | DIFF_FORMAT_DIFFSTAT;
opts.detect_rename = DIFF_DETECT_RENAME; opts.detect_rename = DIFF_DETECT_RENAME;
diff_setup_done(&opts); diff_setup_done(&opts);
diff_tree_sha1(head, new_head, "", &opts); diff_tree_sha1(head->hash, new_head->hash, "", &opts);
diffcore_std(&opts); diffcore_std(&opts);
diff_flush(&opts); diff_flush(&opts);
} }
@ -431,7 +431,7 @@ static void finish(struct commit *head_commit,
static void merge_name(const char *remote, struct strbuf *msg) static void merge_name(const char *remote, struct strbuf *msg)
{ {
struct commit *remote_head; struct commit *remote_head;
unsigned char branch_head[20]; struct object_id branch_head;
struct strbuf buf = STRBUF_INIT; struct strbuf buf = STRBUF_INIT;
struct strbuf bname = STRBUF_INIT; struct strbuf bname = STRBUF_INIT;
const char *ptr; const char *ptr;
@ -441,25 +441,25 @@ static void merge_name(const char *remote, struct strbuf *msg)
strbuf_branchname(&bname, remote, 0); strbuf_branchname(&bname, remote, 0);
remote = bname.buf; remote = bname.buf;
memset(branch_head, 0, sizeof(branch_head)); oidclr(&branch_head);
remote_head = get_merge_parent(remote); remote_head = get_merge_parent(remote);
if (!remote_head) if (!remote_head)
die(_("'%s' does not point to a commit"), remote); die(_("'%s' does not point to a commit"), remote);
if (dwim_ref(remote, strlen(remote), branch_head, &found_ref) > 0) { if (dwim_ref(remote, strlen(remote), branch_head.hash, &found_ref) > 0) {
if (starts_with(found_ref, "refs/heads/")) { if (starts_with(found_ref, "refs/heads/")) {
strbuf_addf(msg, "%s\t\tbranch '%s' of .\n", strbuf_addf(msg, "%s\t\tbranch '%s' of .\n",
sha1_to_hex(branch_head), remote); oid_to_hex(&branch_head), remote);
goto cleanup; goto cleanup;
} }
if (starts_with(found_ref, "refs/tags/")) { if (starts_with(found_ref, "refs/tags/")) {
strbuf_addf(msg, "%s\t\ttag '%s' of .\n", strbuf_addf(msg, "%s\t\ttag '%s' of .\n",
sha1_to_hex(branch_head), remote); oid_to_hex(&branch_head), remote);
goto cleanup; goto cleanup;
} }
if (starts_with(found_ref, "refs/remotes/")) { if (starts_with(found_ref, "refs/remotes/")) {
strbuf_addf(msg, "%s\t\tremote-tracking branch '%s' of .\n", strbuf_addf(msg, "%s\t\tremote-tracking branch '%s' of .\n",
sha1_to_hex(branch_head), remote); oid_to_hex(&branch_head), remote);
goto cleanup; goto cleanup;
} }
} }
@ -590,8 +590,8 @@ static int git_merge_config(const char *k, const char *v, void *cb)
return git_diff_ui_config(k, v, cb); return git_diff_ui_config(k, v, cb);
} }
static int read_tree_trivial(unsigned char *common, unsigned char *head, static int read_tree_trivial(struct object_id *common, struct object_id *head,
unsigned char *one) struct object_id *one)
{ {
int i, nr_trees = 0; int i, nr_trees = 0;
struct tree *trees[MAX_UNPACK_TREES]; struct tree *trees[MAX_UNPACK_TREES];
@ -606,13 +606,13 @@ static int read_tree_trivial(unsigned char *common, unsigned char *head,
opts.verbose_update = 1; opts.verbose_update = 1;
opts.trivial_merges_only = 1; opts.trivial_merges_only = 1;
opts.merge = 1; opts.merge = 1;
trees[nr_trees] = parse_tree_indirect(common); trees[nr_trees] = parse_tree_indirect(common->hash);
if (!trees[nr_trees++]) if (!trees[nr_trees++])
return -1; return -1;
trees[nr_trees] = parse_tree_indirect(head); trees[nr_trees] = parse_tree_indirect(head->hash);
if (!trees[nr_trees++]) if (!trees[nr_trees++])
return -1; return -1;
trees[nr_trees] = parse_tree_indirect(one); trees[nr_trees] = parse_tree_indirect(one->hash);
if (!trees[nr_trees++]) if (!trees[nr_trees++])
return -1; return -1;
opts.fn = threeway_merge; opts.fn = threeway_merge;
@ -626,9 +626,9 @@ static int read_tree_trivial(unsigned char *common, unsigned char *head,
return 0; return 0;
} }
static void write_tree_trivial(unsigned char *sha1) static void write_tree_trivial(struct object_id *oid)
{ {
if (write_cache_as_tree(sha1, 0, NULL)) if (write_cache_as_tree(oid->hash, 0, NULL))
die(_("git write-tree failed to write a tree")); die(_("git write-tree failed to write a tree"));
} }
@ -781,7 +781,7 @@ static void prepare_to_commit(struct commit_list *remoteheads)
static int merge_trivial(struct commit *head, struct commit_list *remoteheads) static int merge_trivial(struct commit *head, struct commit_list *remoteheads)
{ {
unsigned char result_tree[20], result_commit[20]; struct object_id result_tree, result_commit;
struct commit_list *parents, **pptr = &parents; struct commit_list *parents, **pptr = &parents;
static struct lock_file lock; static struct lock_file lock;
@ -792,15 +792,15 @@ static int merge_trivial(struct commit *head, struct commit_list *remoteheads)
return error(_("Unable to write index.")); return error(_("Unable to write index."));
rollback_lock_file(&lock); rollback_lock_file(&lock);
write_tree_trivial(result_tree); write_tree_trivial(&result_tree);
printf(_("Wonderful.\n")); printf(_("Wonderful.\n"));
pptr = commit_list_append(head, pptr); pptr = commit_list_append(head, pptr);
pptr = commit_list_append(remoteheads->item, pptr); pptr = commit_list_append(remoteheads->item, pptr);
prepare_to_commit(remoteheads); prepare_to_commit(remoteheads);
if (commit_tree(merge_msg.buf, merge_msg.len, result_tree, parents, if (commit_tree(merge_msg.buf, merge_msg.len, result_tree.hash, parents,
result_commit, NULL, sign_commit)) result_commit.hash, NULL, sign_commit))
die(_("failed to write commit object")); die(_("failed to write commit object"));
finish(head, remoteheads, result_commit, "In-index merge"); finish(head, remoteheads, &result_commit, "In-index merge");
drop_save(); drop_save();
return 0; return 0;
} }
@ -809,12 +809,12 @@ static int finish_automerge(struct commit *head,
int head_subsumed, int head_subsumed,
struct commit_list *common, struct commit_list *common,
struct commit_list *remoteheads, struct commit_list *remoteheads,
unsigned char *result_tree, struct object_id *result_tree,
const char *wt_strategy) const char *wt_strategy)
{ {
struct commit_list *parents = NULL; struct commit_list *parents = NULL;
struct strbuf buf = STRBUF_INIT; struct strbuf buf = STRBUF_INIT;
unsigned char result_commit[20]; struct object_id result_commit;
free_commit_list(common); free_commit_list(common);
parents = remoteheads; parents = remoteheads;
@ -822,11 +822,11 @@ static int finish_automerge(struct commit *head,
commit_list_insert(head, &parents); commit_list_insert(head, &parents);
strbuf_addch(&merge_msg, '\n'); strbuf_addch(&merge_msg, '\n');
prepare_to_commit(remoteheads); prepare_to_commit(remoteheads);
if (commit_tree(merge_msg.buf, merge_msg.len, result_tree, parents, if (commit_tree(merge_msg.buf, merge_msg.len, result_tree->hash, parents,
result_commit, NULL, sign_commit)) result_commit.hash, NULL, sign_commit))
die(_("failed to write commit object")); die(_("failed to write commit object"));
strbuf_addf(&buf, "Merge made by the '%s' strategy.", wt_strategy); strbuf_addf(&buf, "Merge made by the '%s' strategy.", wt_strategy);
finish(head, remoteheads, result_commit, buf.buf); finish(head, remoteheads, &result_commit, buf.buf);
strbuf_release(&buf); strbuf_release(&buf);
drop_save(); drop_save();
return 0; return 0;
@ -854,18 +854,18 @@ static int suggest_conflicts(void)
} }
static struct commit *is_old_style_invocation(int argc, const char **argv, static struct commit *is_old_style_invocation(int argc, const char **argv,
const unsigned char *head) const struct object_id *head)
{ {
struct commit *second_token = NULL; struct commit *second_token = NULL;
if (argc > 2) { if (argc > 2) {
unsigned char second_sha1[20]; struct object_id second_oid;
if (get_sha1(argv[1], second_sha1)) if (get_oid(argv[1], &second_oid))
return NULL; return NULL;
second_token = lookup_commit_reference_gently(second_sha1, 0); second_token = lookup_commit_reference_gently(second_oid.hash, 0);
if (!second_token) if (!second_token)
die(_("'%s' is not a commit"), argv[1]); die(_("'%s' is not a commit"), argv[1]);
if (hashcmp(second_token->object.oid.hash, head)) if (oidcmp(&second_token->object.oid, head))
return NULL; return NULL;
} }
return second_token; return second_token;
@ -1038,7 +1038,7 @@ static void handle_fetch_head(struct commit_list **remotes, struct strbuf *merge
die_errno(_("could not close '%s'"), filename); die_errno(_("could not close '%s'"), filename);
for (pos = 0; pos < merge_names->len; pos = npos) { for (pos = 0; pos < merge_names->len; pos = npos) {
unsigned char sha1[20]; struct object_id oid;
char *ptr; char *ptr;
struct commit *commit; struct commit *commit;
@ -1048,16 +1048,16 @@ static void handle_fetch_head(struct commit_list **remotes, struct strbuf *merge
else else
npos = merge_names->len; npos = merge_names->len;
if (npos - pos < 40 + 2 || if (npos - pos < GIT_SHA1_HEXSZ + 2 ||
get_sha1_hex(merge_names->buf + pos, sha1)) get_oid_hex(merge_names->buf + pos, &oid))
commit = NULL; /* bad */ commit = NULL; /* bad */
else if (memcmp(merge_names->buf + pos + 40, "\t\t", 2)) else if (memcmp(merge_names->buf + pos + GIT_SHA1_HEXSZ, "\t\t", 2))
continue; /* not-for-merge */ continue; /* not-for-merge */
else { else {
char saved = merge_names->buf[pos + 40]; char saved = merge_names->buf[pos + GIT_SHA1_HEXSZ];
merge_names->buf[pos + 40] = '\0'; merge_names->buf[pos + GIT_SHA1_HEXSZ] = '\0';
commit = get_merge_parent(merge_names->buf + pos); commit = get_merge_parent(merge_names->buf + pos);
merge_names->buf[pos + 40] = saved; merge_names->buf[pos + GIT_SHA1_HEXSZ] = saved;
} }
if (!commit) { if (!commit) {
if (ptr) if (ptr)
@ -1117,9 +1117,7 @@ static struct commit_list *collect_parents(struct commit *head_commit,
int cmd_merge(int argc, const char **argv, const char *prefix) int cmd_merge(int argc, const char **argv, const char *prefix)
{ {
unsigned char result_tree[20]; struct object_id result_tree, stash, head_oid;
unsigned char stash[20];
unsigned char head_sha1[20];
struct commit *head_commit; struct commit *head_commit;
struct strbuf buf = STRBUF_INIT; struct strbuf buf = STRBUF_INIT;
const char *head_arg; const char *head_arg;
@ -1138,13 +1136,13 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
* Check if we are _not_ on a detached HEAD, i.e. if there is a * Check if we are _not_ on a detached HEAD, i.e. if there is a
* current branch. * current branch.
*/ */
branch = branch_to_free = resolve_refdup("HEAD", 0, head_sha1, NULL); branch = branch_to_free = resolve_refdup("HEAD", 0, head_oid.hash, NULL);
if (branch && starts_with(branch, "refs/heads/")) if (branch && starts_with(branch, "refs/heads/"))
branch += 11; branch += 11;
if (!branch || is_null_sha1(head_sha1)) if (!branch || is_null_oid(&head_oid))
head_commit = NULL; head_commit = NULL;
else else
head_commit = lookup_commit_or_die(head_sha1, "HEAD"); head_commit = lookup_commit_or_die(head_oid.hash, "HEAD");
init_diff_ui_defaults(); init_diff_ui_defaults();
git_config(git_merge_config, NULL); git_config(git_merge_config, NULL);
@ -1242,7 +1240,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
* to forbid "git merge" into a branch yet to be born. * to forbid "git merge" into a branch yet to be born.
* We do the same for "git pull". * We do the same for "git pull".
*/ */
unsigned char *remote_head_sha1; struct object_id *remote_head_oid;
if (squash) if (squash)
die(_("Squash commit into empty head not supported yet")); die(_("Squash commit into empty head not supported yet"));
if (fast_forward == FF_NO) if (fast_forward == FF_NO)
@ -1254,9 +1252,9 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
die(_("%s - not something we can merge"), argv[0]); die(_("%s - not something we can merge"), argv[0]);
if (remoteheads->next) if (remoteheads->next)
die(_("Can merge only exactly one commit into empty head")); die(_("Can merge only exactly one commit into empty head"));
remote_head_sha1 = remoteheads->item->object.oid.hash; remote_head_oid = &remoteheads->item->object.oid;
read_empty(remote_head_sha1, 0); read_empty(remote_head_oid->hash, 0);
update_ref("initial pull", "HEAD", remote_head_sha1, update_ref("initial pull", "HEAD", remote_head_oid->hash,
NULL, 0, UPDATE_REFS_DIE_ON_ERR); NULL, 0, UPDATE_REFS_DIE_ON_ERR);
goto done; goto done;
} }
@ -1270,7 +1268,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
* additional safety measure to check for it. * additional safety measure to check for it.
*/ */
if (!have_message && if (!have_message &&
is_old_style_invocation(argc, argv, head_commit->object.oid.hash)) { is_old_style_invocation(argc, argv, &head_commit->object.oid)) {
warning("old-style 'git merge <msg> HEAD <commit>' is deprecated."); warning("old-style 'git merge <msg> HEAD <commit>' is deprecated.");
strbuf_addstr(&merge_msg, argv[0]); strbuf_addstr(&merge_msg, argv[0]);
head_arg = argv[1]; head_arg = argv[1];
@ -1422,7 +1420,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
goto done; goto done;
} }
finish(head_commit, remoteheads, commit->object.oid.hash, msg.buf); finish(head_commit, remoteheads, &commit->object.oid, msg.buf);
drop_save(); drop_save();
goto done; goto done;
} else if (!remoteheads->next && common->next) } else if (!remoteheads->next && common->next)
@ -1441,9 +1439,9 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
/* See if it is really trivial. */ /* See if it is really trivial. */
git_committer_info(IDENT_STRICT); git_committer_info(IDENT_STRICT);
printf(_("Trying really trivial in-index merge...\n")); printf(_("Trying really trivial in-index merge...\n"));
if (!read_tree_trivial(common->item->object.oid.hash, if (!read_tree_trivial(&common->item->object.oid,
head_commit->object.oid.hash, &head_commit->object.oid,
remoteheads->item->object.oid.hash)) { &remoteheads->item->object.oid)) {
ret = merge_trivial(head_commit, remoteheads); ret = merge_trivial(head_commit, remoteheads);
goto done; goto done;
} }
@ -1495,14 +1493,14 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
/* /*
* Stash away the local changes so that we can try more than one. * Stash away the local changes so that we can try more than one.
*/ */
save_state(stash)) save_state(&stash))
hashclr(stash); oidclr(&stash);
for (i = 0; i < use_strategies_nr; i++) { for (i = 0; i < use_strategies_nr; i++) {
int ret; int ret;
if (i) { if (i) {
printf(_("Rewinding the tree to pristine...\n")); printf(_("Rewinding the tree to pristine...\n"));
restore_state(head_commit->object.oid.hash, stash); restore_state(&head_commit->object.oid, &stash);
} }
if (use_strategies_nr != 1) if (use_strategies_nr != 1)
printf(_("Trying merge strategy %s...\n"), printf(_("Trying merge strategy %s...\n"),
@ -1547,7 +1545,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
} }
/* Automerge succeeded. */ /* Automerge succeeded. */
write_tree_trivial(result_tree); write_tree_trivial(&result_tree);
automerge_was_ok = 1; automerge_was_ok = 1;
break; break;
} }
@ -1559,7 +1557,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
if (automerge_was_ok) { if (automerge_was_ok) {
ret = finish_automerge(head_commit, head_subsumed, ret = finish_automerge(head_commit, head_subsumed,
common, remoteheads, common, remoteheads,
result_tree, wt_strategy); &result_tree, wt_strategy);
goto done; goto done;
} }
@ -1568,7 +1566,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
* it up. * it up.
*/ */
if (!best_strategy) { if (!best_strategy) {
restore_state(head_commit->object.oid.hash, stash); restore_state(&head_commit->object.oid, &stash);
if (use_strategies_nr > 1) if (use_strategies_nr > 1)
fprintf(stderr, fprintf(stderr,
_("No merge strategy handled the merge.\n")); _("No merge strategy handled the merge.\n"));
@ -1581,7 +1579,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
; /* We already have its result in the working tree. */ ; /* We already have its result in the working tree. */
else { else {
printf(_("Rewinding the tree to pristine...\n")); printf(_("Rewinding the tree to pristine...\n"));
restore_state(head_commit->object.oid.hash, stash); restore_state(&head_commit->object.oid, &stash);
printf(_("Using the %s to prepare resolving by hand.\n"), printf(_("Using the %s to prepare resolving by hand.\n"),
best_strategy); best_strategy);
try_merge_strategy(best_strategy, common, remoteheads, try_merge_strategy(best_strategy, common, remoteheads,

View File

@ -693,7 +693,7 @@ static int merge_abort(struct notes_merge_options *o)
static int merge_commit(struct notes_merge_options *o) static int merge_commit(struct notes_merge_options *o)
{ {
struct strbuf msg = STRBUF_INIT; struct strbuf msg = STRBUF_INIT;
unsigned char sha1[20], parent_sha1[20]; struct object_id oid, parent_oid;
struct notes_tree *t; struct notes_tree *t;
struct commit *partial; struct commit *partial;
struct pretty_print_context pretty_ctx; struct pretty_print_context pretty_ctx;
@ -705,27 +705,27 @@ static int merge_commit(struct notes_merge_options *o)
* and target notes ref from .git/NOTES_MERGE_REF. * and target notes ref from .git/NOTES_MERGE_REF.
*/ */
if (get_sha1("NOTES_MERGE_PARTIAL", sha1)) if (get_oid("NOTES_MERGE_PARTIAL", &oid))
die(_("failed to read ref NOTES_MERGE_PARTIAL")); die(_("failed to read ref NOTES_MERGE_PARTIAL"));
else if (!(partial = lookup_commit_reference(sha1))) else if (!(partial = lookup_commit_reference(oid.hash)))
die(_("could not find commit from NOTES_MERGE_PARTIAL.")); die(_("could not find commit from NOTES_MERGE_PARTIAL."));
else if (parse_commit(partial)) else if (parse_commit(partial))
die(_("could not parse commit from NOTES_MERGE_PARTIAL.")); die(_("could not parse commit from NOTES_MERGE_PARTIAL."));
if (partial->parents) if (partial->parents)
hashcpy(parent_sha1, partial->parents->item->object.oid.hash); oidcpy(&parent_oid, &partial->parents->item->object.oid);
else else
hashclr(parent_sha1); oidclr(&parent_oid);
t = xcalloc(1, sizeof(struct notes_tree)); t = xcalloc(1, sizeof(struct notes_tree));
init_notes(t, "NOTES_MERGE_PARTIAL", combine_notes_overwrite, 0); init_notes(t, "NOTES_MERGE_PARTIAL", combine_notes_overwrite, 0);
o->local_ref = local_ref_to_free = o->local_ref = local_ref_to_free =
resolve_refdup("NOTES_MERGE_REF", 0, sha1, NULL); resolve_refdup("NOTES_MERGE_REF", 0, oid.hash, NULL);
if (!o->local_ref) if (!o->local_ref)
die(_("failed to resolve NOTES_MERGE_REF")); die(_("failed to resolve NOTES_MERGE_REF"));
if (notes_merge_commit(o, t, partial, sha1)) if (notes_merge_commit(o, t, partial, oid.hash))
die(_("failed to finalize notes merge")); die(_("failed to finalize notes merge"));
/* Reuse existing commit message in reflog message */ /* Reuse existing commit message in reflog message */
@ -733,8 +733,8 @@ static int merge_commit(struct notes_merge_options *o)
format_commit_message(partial, "%s", &msg, &pretty_ctx); format_commit_message(partial, "%s", &msg, &pretty_ctx);
strbuf_trim(&msg); strbuf_trim(&msg);
strbuf_insert(&msg, 0, "notes: ", 7); strbuf_insert(&msg, 0, "notes: ", 7);
update_ref(msg.buf, o->local_ref, sha1, update_ref(msg.buf, o->local_ref, oid.hash,
is_null_sha1(parent_sha1) ? NULL : parent_sha1, is_null_oid(&parent_oid) ? NULL : parent_oid.hash,
0, UPDATE_REFS_DIE_ON_ERR); 0, UPDATE_REFS_DIE_ON_ERR);
free_notes(t); free_notes(t);

View File

@ -2612,17 +2612,17 @@ static void add_objects_in_unpacked_packs(struct rev_info *revs)
free(in_pack.array); free(in_pack.array);
} }
static int add_loose_object(const unsigned char *sha1, const char *path, static int add_loose_object(const struct object_id *oid, const char *path,
void *data) void *data)
{ {
enum object_type type = sha1_object_info(sha1, NULL); enum object_type type = sha1_object_info(oid->hash, NULL);
if (type < 0) { if (type < 0) {
warning("loose object at %s could not be examined", path); warning("loose object at %s could not be examined", path);
return 0; return 0;
} }
add_object_entry(sha1, type, "", 0); add_object_entry(oid->hash, type, "", 0);
return 0; return 0;
} }

View File

@ -19,12 +19,12 @@ static int prune_subdir(int nr, const char *path, void *data)
return 0; return 0;
} }
static int prune_object(const unsigned char *sha1, const char *path, static int prune_object(const struct object_id *oid, const char *path,
void *data) void *data)
{ {
int *opts = data; int *opts = data;
if (!has_sha1_pack(sha1)) if (!has_sha1_pack(oid->hash))
return 0; return 0;
if (*opts & PRUNE_PACKED_DRY_RUN) if (*opts & PRUNE_PACKED_DRY_RUN)

View File

@ -30,7 +30,7 @@ static int prune_tmp_file(const char *fullpath)
return 0; return 0;
} }
static int prune_object(const unsigned char *sha1, const char *fullpath, static int prune_object(const struct object_id *oid, const char *fullpath,
void *data) void *data)
{ {
struct stat st; struct stat st;
@ -39,7 +39,7 @@ static int prune_object(const unsigned char *sha1, const char *fullpath,
* Do we know about this object? * Do we know about this object?
* It must have been reachable * It must have been reachable
*/ */
if (lookup_object(sha1)) if (lookup_object(oid->hash))
return 0; return 0;
if (lstat(fullpath, &st)) { if (lstat(fullpath, &st)) {
@ -50,8 +50,8 @@ static int prune_object(const unsigned char *sha1, const char *fullpath,
if (st.st_mtime > expire) if (st.st_mtime > expire)
return 0; return 0;
if (show_only || verbose) { if (show_only || verbose) {
enum object_type type = sha1_object_info(sha1, NULL); enum object_type type = sha1_object_info(oid->hash, NULL);
printf("%s %s\n", sha1_to_hex(sha1), printf("%s %s\n", oid_to_hex(oid),
(type > 0) ? typename(type) : "unknown"); (type > 0) ? typename(type) : "unknown");
} }
if (!show_only) if (!show_only)

View File

@ -1417,7 +1417,7 @@ static void execute_commands(struct command *commands,
{ {
struct check_connected_options opt = CHECK_CONNECTED_INIT; struct check_connected_options opt = CHECK_CONNECTED_INIT;
struct command *cmd; struct command *cmd;
unsigned char sha1[20]; struct object_id oid;
struct iterate_data data; struct iterate_data data;
struct async muxer; struct async muxer;
int err_fd = 0; int err_fd = 0;
@ -1474,7 +1474,7 @@ static void execute_commands(struct command *commands,
check_aliased_updates(commands); check_aliased_updates(commands);
free(head_name_to_free); free(head_name_to_free);
head_name = head_name_to_free = resolve_refdup("HEAD", 0, sha1, NULL); head_name = head_name_to_free = resolve_refdup("HEAD", 0, oid.hash, NULL);
if (use_atomic) if (use_atomic)
execute_commands_atomic(commands, si); execute_commands_atomic(commands, si);

View File

@ -615,7 +615,7 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix)
return status; return status;
} }
static int count_reflog_ent(unsigned char *osha1, unsigned char *nsha1, static int count_reflog_ent(struct object_id *ooid, struct object_id *noid,
const char *email, unsigned long timestamp, int tz, const char *email, unsigned long timestamp, int tz,
const char *message, void *cb_data) const char *message, void *cb_data)
{ {

View File

@ -88,78 +88,78 @@ static int list_replace_refs(const char *pattern, const char *format)
} }
typedef int (*each_replace_name_fn)(const char *name, const char *ref, typedef int (*each_replace_name_fn)(const char *name, const char *ref,
const unsigned char *sha1); const struct object_id *oid);
static int for_each_replace_name(const char **argv, each_replace_name_fn fn) static int for_each_replace_name(const char **argv, each_replace_name_fn fn)
{ {
const char **p, *full_hex; const char **p, *full_hex;
char ref[PATH_MAX]; char ref[PATH_MAX];
int had_error = 0; int had_error = 0;
unsigned char sha1[20]; struct object_id oid;
for (p = argv; *p; p++) { for (p = argv; *p; p++) {
if (get_sha1(*p, sha1)) { if (get_oid(*p, &oid)) {
error("Failed to resolve '%s' as a valid ref.", *p); error("Failed to resolve '%s' as a valid ref.", *p);
had_error = 1; had_error = 1;
continue; continue;
} }
full_hex = sha1_to_hex(sha1); full_hex = oid_to_hex(&oid);
snprintf(ref, sizeof(ref), "%s%s", git_replace_ref_base, full_hex); snprintf(ref, sizeof(ref), "%s%s", git_replace_ref_base, full_hex);
/* read_ref() may reuse the buffer */ /* read_ref() may reuse the buffer */
full_hex = ref + strlen(git_replace_ref_base); full_hex = ref + strlen(git_replace_ref_base);
if (read_ref(ref, sha1)) { if (read_ref(ref, oid.hash)) {
error("replace ref '%s' not found.", full_hex); error("replace ref '%s' not found.", full_hex);
had_error = 1; had_error = 1;
continue; continue;
} }
if (fn(full_hex, ref, sha1)) if (fn(full_hex, ref, &oid))
had_error = 1; had_error = 1;
} }
return had_error; return had_error;
} }
static int delete_replace_ref(const char *name, const char *ref, static int delete_replace_ref(const char *name, const char *ref,
const unsigned char *sha1) const struct object_id *oid)
{ {
if (delete_ref(NULL, ref, sha1, 0)) if (delete_ref(NULL, ref, oid->hash, 0))
return 1; return 1;
printf("Deleted replace ref '%s'\n", name); printf("Deleted replace ref '%s'\n", name);
return 0; return 0;
} }
static void check_ref_valid(unsigned char object[20], static void check_ref_valid(struct object_id *object,
unsigned char prev[20], struct object_id *prev,
char *ref, char *ref,
int ref_size, int ref_size,
int force) int force)
{ {
if (snprintf(ref, ref_size, if (snprintf(ref, ref_size,
"%s%s", git_replace_ref_base, "%s%s", git_replace_ref_base,
sha1_to_hex(object)) > ref_size - 1) oid_to_hex(object)) > ref_size - 1)
die("replace ref name too long: %.*s...", 50, ref); die("replace ref name too long: %.*s...", 50, ref);
if (check_refname_format(ref, 0)) if (check_refname_format(ref, 0))
die("'%s' is not a valid ref name.", ref); die("'%s' is not a valid ref name.", ref);
if (read_ref(ref, prev)) if (read_ref(ref, prev->hash))
hashclr(prev); oidclr(prev);
else if (!force) else if (!force)
die("replace ref '%s' already exists", ref); die("replace ref '%s' already exists", ref);
} }
static int replace_object_sha1(const char *object_ref, static int replace_object_oid(const char *object_ref,
unsigned char object[20], struct object_id *object,
const char *replace_ref, const char *replace_ref,
unsigned char repl[20], struct object_id *repl,
int force) int force)
{ {
unsigned char prev[20]; struct object_id prev;
enum object_type obj_type, repl_type; enum object_type obj_type, repl_type;
char ref[PATH_MAX]; char ref[PATH_MAX];
struct ref_transaction *transaction; struct ref_transaction *transaction;
struct strbuf err = STRBUF_INIT; struct strbuf err = STRBUF_INIT;
obj_type = sha1_object_info(object, NULL); obj_type = sha1_object_info(object->hash, NULL);
repl_type = sha1_object_info(repl, NULL); repl_type = sha1_object_info(repl->hash, NULL);
if (!force && obj_type != repl_type) if (!force && obj_type != repl_type)
die("Objects must be of the same type.\n" die("Objects must be of the same type.\n"
"'%s' points to a replaced object of type '%s'\n" "'%s' points to a replaced object of type '%s'\n"
@ -167,11 +167,11 @@ static int replace_object_sha1(const char *object_ref,
object_ref, typename(obj_type), object_ref, typename(obj_type),
replace_ref, typename(repl_type)); replace_ref, typename(repl_type));
check_ref_valid(object, prev, ref, sizeof(ref), force); check_ref_valid(object, &prev, ref, sizeof(ref), force);
transaction = ref_transaction_begin(&err); transaction = ref_transaction_begin(&err);
if (!transaction || if (!transaction ||
ref_transaction_update(transaction, ref, repl, prev, ref_transaction_update(transaction, ref, repl->hash, prev.hash,
0, NULL, &err) || 0, NULL, &err) ||
ref_transaction_commit(transaction, &err)) ref_transaction_commit(transaction, &err))
die("%s", err.buf); die("%s", err.buf);
@ -182,14 +182,14 @@ static int replace_object_sha1(const char *object_ref,
static int replace_object(const char *object_ref, const char *replace_ref, int force) static int replace_object(const char *object_ref, const char *replace_ref, int force)
{ {
unsigned char object[20], repl[20]; struct object_id object, repl;
if (get_sha1(object_ref, object)) if (get_oid(object_ref, &object))
die("Failed to resolve '%s' as a valid ref.", object_ref); die("Failed to resolve '%s' as a valid ref.", object_ref);
if (get_sha1(replace_ref, repl)) if (get_oid(replace_ref, &repl))
die("Failed to resolve '%s' as a valid ref.", replace_ref); die("Failed to resolve '%s' as a valid ref.", replace_ref);
return replace_object_sha1(object_ref, object, replace_ref, repl, force); return replace_object_oid(object_ref, &object, replace_ref, &repl, force);
} }
/* /*
@ -197,7 +197,7 @@ static int replace_object(const char *object_ref, const char *replace_ref, int f
* If "raw" is true, then the object's raw contents are printed according to * If "raw" is true, then the object's raw contents are printed according to
* "type". Otherwise, we pretty-print the contents for human editing. * "type". Otherwise, we pretty-print the contents for human editing.
*/ */
static void export_object(const unsigned char *sha1, enum object_type type, static void export_object(const struct object_id *oid, enum object_type type,
int raw, const char *filename) int raw, const char *filename)
{ {
struct child_process cmd = CHILD_PROCESS_INIT; struct child_process cmd = CHILD_PROCESS_INIT;
@ -213,7 +213,7 @@ static void export_object(const unsigned char *sha1, enum object_type type,
argv_array_push(&cmd.args, typename(type)); argv_array_push(&cmd.args, typename(type));
else else
argv_array_push(&cmd.args, "-p"); argv_array_push(&cmd.args, "-p");
argv_array_push(&cmd.args, sha1_to_hex(sha1)); argv_array_push(&cmd.args, oid_to_hex(oid));
cmd.git_cmd = 1; cmd.git_cmd = 1;
cmd.out = fd; cmd.out = fd;
@ -226,7 +226,7 @@ static void export_object(const unsigned char *sha1, enum object_type type,
* interpreting it as "type", and writing the result to the object database. * interpreting it as "type", and writing the result to the object database.
* The sha1 of the written object is returned via sha1. * The sha1 of the written object is returned via sha1.
*/ */
static void import_object(unsigned char *sha1, enum object_type type, static void import_object(struct object_id *oid, enum object_type type,
int raw, const char *filename) int raw, const char *filename)
{ {
int fd; int fd;
@ -254,7 +254,7 @@ static void import_object(unsigned char *sha1, enum object_type type,
if (finish_command(&cmd)) if (finish_command(&cmd))
die("mktree reported failure"); die("mktree reported failure");
if (get_sha1_hex(result.buf, sha1) < 0) if (get_oid_hex(result.buf, oid) < 0)
die("mktree did not return an object name"); die("mktree did not return an object name");
strbuf_release(&result); strbuf_release(&result);
@ -264,7 +264,7 @@ static void import_object(unsigned char *sha1, enum object_type type,
if (fstat(fd, &st) < 0) if (fstat(fd, &st) < 0)
die_errno("unable to fstat %s", filename); die_errno("unable to fstat %s", filename);
if (index_fd(sha1, fd, &st, type, NULL, flags) < 0) if (index_fd(oid->hash, fd, &st, type, NULL, flags) < 0)
die("unable to write object to database"); die("unable to write object to database");
/* index_fd close()s fd for us */ /* index_fd close()s fd for us */
} }
@ -279,29 +279,29 @@ static int edit_and_replace(const char *object_ref, int force, int raw)
{ {
char *tmpfile = git_pathdup("REPLACE_EDITOBJ"); char *tmpfile = git_pathdup("REPLACE_EDITOBJ");
enum object_type type; enum object_type type;
unsigned char old[20], new[20], prev[20]; struct object_id old, new, prev;
char ref[PATH_MAX]; char ref[PATH_MAX];
if (get_sha1(object_ref, old) < 0) if (get_oid(object_ref, &old) < 0)
die("Not a valid object name: '%s'", object_ref); die("Not a valid object name: '%s'", object_ref);
type = sha1_object_info(old, NULL); type = sha1_object_info(old.hash, NULL);
if (type < 0) if (type < 0)
die("unable to get object type for %s", sha1_to_hex(old)); die("unable to get object type for %s", oid_to_hex(&old));
check_ref_valid(old, prev, ref, sizeof(ref), force); check_ref_valid(&old, &prev, ref, sizeof(ref), force);
export_object(old, type, raw, tmpfile); export_object(&old, type, raw, tmpfile);
if (launch_editor(tmpfile, NULL, NULL) < 0) if (launch_editor(tmpfile, NULL, NULL) < 0)
die("editing object file failed"); die("editing object file failed");
import_object(new, type, raw, tmpfile); import_object(&new, type, raw, tmpfile);
free(tmpfile); free(tmpfile);
if (!hashcmp(old, new)) if (!oidcmp(&old, &new))
return error("new object is the same as the old one: '%s'", sha1_to_hex(old)); return error("new object is the same as the old one: '%s'", oid_to_hex(&old));
return replace_object_sha1(object_ref, old, "replacement", new, force); return replace_object_oid(object_ref, &old, "replacement", &new, force);
} }
static void replace_parents(struct strbuf *buf, int argc, const char **argv) static void replace_parents(struct strbuf *buf, int argc, const char **argv)
@ -312,7 +312,7 @@ static void replace_parents(struct strbuf *buf, int argc, const char **argv)
/* find existing parents */ /* find existing parents */
parent_start = buf->buf; parent_start = buf->buf;
parent_start += 46; /* "tree " + "hex sha1" + "\n" */ parent_start += GIT_SHA1_HEXSZ + 6; /* "tree " + "hex sha1" + "\n" */
parent_end = parent_start; parent_end = parent_start;
while (starts_with(parent_end, "parent ")) while (starts_with(parent_end, "parent "))
@ -320,11 +320,11 @@ static void replace_parents(struct strbuf *buf, int argc, const char **argv)
/* prepare new parents */ /* prepare new parents */
for (i = 0; i < argc; i++) { for (i = 0; i < argc; i++) {
unsigned char sha1[20]; struct object_id oid;
if (get_sha1(argv[i], sha1) < 0) if (get_oid(argv[i], &oid) < 0)
die(_("Not a valid object name: '%s'"), argv[i]); die(_("Not a valid object name: '%s'"), argv[i]);
lookup_commit_or_die(sha1, argv[i]); lookup_commit_or_die(oid.hash, argv[i]);
strbuf_addf(&new_parents, "parent %s\n", sha1_to_hex(sha1)); strbuf_addf(&new_parents, "parent %s\n", oid_to_hex(&oid));
} }
/* replace existing parents with new ones */ /* replace existing parents with new ones */
@ -345,12 +345,12 @@ static void check_one_mergetag(struct commit *commit,
{ {
struct check_mergetag_data *mergetag_data = (struct check_mergetag_data *)data; struct check_mergetag_data *mergetag_data = (struct check_mergetag_data *)data;
const char *ref = mergetag_data->argv[0]; const char *ref = mergetag_data->argv[0];
unsigned char tag_sha1[20]; struct object_id tag_oid;
struct tag *tag; struct tag *tag;
int i; int i;
hash_sha1_file(extra->value, extra->len, typename(OBJ_TAG), tag_sha1); hash_sha1_file(extra->value, extra->len, typename(OBJ_TAG), tag_oid.hash);
tag = lookup_tag(tag_sha1); tag = lookup_tag(tag_oid.hash);
if (!tag) if (!tag)
die(_("bad mergetag in commit '%s'"), ref); die(_("bad mergetag in commit '%s'"), ref);
if (parse_tag_buffer(tag, extra->value, extra->len)) if (parse_tag_buffer(tag, extra->value, extra->len))
@ -366,7 +366,7 @@ static void check_one_mergetag(struct commit *commit,
} }
die(_("original commit '%s' contains mergetag '%s' that is discarded; " die(_("original commit '%s' contains mergetag '%s' that is discarded; "
"use --edit instead of --graft"), ref, sha1_to_hex(tag_sha1)); "use --edit instead of --graft"), ref, oid_to_hex(&tag_oid));
} }
static void check_mergetags(struct commit *commit, int argc, const char **argv) static void check_mergetags(struct commit *commit, int argc, const char **argv)
@ -380,16 +380,16 @@ static void check_mergetags(struct commit *commit, int argc, const char **argv)
static int create_graft(int argc, const char **argv, int force) static int create_graft(int argc, const char **argv, int force)
{ {
unsigned char old[20], new[20]; struct object_id old, new;
const char *old_ref = argv[0]; const char *old_ref = argv[0];
struct commit *commit; struct commit *commit;
struct strbuf buf = STRBUF_INIT; struct strbuf buf = STRBUF_INIT;
const char *buffer; const char *buffer;
unsigned long size; unsigned long size;
if (get_sha1(old_ref, old) < 0) if (get_oid(old_ref, &old) < 0)
die(_("Not a valid object name: '%s'"), old_ref); die(_("Not a valid object name: '%s'"), old_ref);
commit = lookup_commit_or_die(old, old_ref); commit = lookup_commit_or_die(old.hash, old_ref);
buffer = get_commit_buffer(commit, &size); buffer = get_commit_buffer(commit, &size);
strbuf_add(&buf, buffer, size); strbuf_add(&buf, buffer, size);
@ -404,15 +404,15 @@ static int create_graft(int argc, const char **argv, int force)
check_mergetags(commit, argc, argv); check_mergetags(commit, argc, argv);
if (write_sha1_file(buf.buf, buf.len, commit_type, new)) if (write_sha1_file(buf.buf, buf.len, commit_type, new.hash))
die(_("could not write replacement commit for: '%s'"), old_ref); die(_("could not write replacement commit for: '%s'"), old_ref);
strbuf_release(&buf); strbuf_release(&buf);
if (!hashcmp(old, new)) if (!oidcmp(&old, &new))
return error("new commit is the same as the old one: '%s'", sha1_to_hex(old)); return error("new commit is the same as the old one: '%s'", oid_to_hex(&old));
return replace_object_sha1(old_ref, old, "replacement", new, force); return replace_object_oid(old_ref, &old, "replacement", &new, force);
} }
int cmd_replace(int argc, const char **argv, const char *prefix) int cmd_replace(int argc, const char **argv, const char *prefix)

19
cache.h
View File

@ -1363,6 +1363,15 @@ extern char *oid_to_hex_r(char *out, const struct object_id *oid);
extern char *sha1_to_hex(const unsigned char *sha1); /* static buffer result! */ extern char *sha1_to_hex(const unsigned char *sha1); /* static buffer result! */
extern char *oid_to_hex(const struct object_id *oid); /* same static buffer as sha1_to_hex */ extern char *oid_to_hex(const struct object_id *oid); /* same static buffer as sha1_to_hex */
/*
* Parse a 40-character hexadecimal object ID starting from hex, updating the
* pointer specified by end when parsing stops. The resulting object ID is
* stored in oid. Returns 0 on success. Parsing will stop on the first NUL or
* other invalid character. end is only updated on success; otherwise, it is
* unmodified.
*/
extern int parse_oid_hex(const char *hex, struct object_id *oid, const char **end);
/* /*
* This reads short-hand syntax that not only evaluates to a commit * This reads short-hand syntax that not only evaluates to a commit
* object name, but also can act as if the end user spelled the name * object name, but also can act as if the end user spelled the name
@ -1673,6 +1682,12 @@ extern void check_pack_index_ptr(const struct packed_git *p, const void *ptr);
* error. * error.
*/ */
extern const unsigned char *nth_packed_object_sha1(struct packed_git *, uint32_t n); extern const unsigned char *nth_packed_object_sha1(struct packed_git *, uint32_t n);
/*
* Like nth_packed_object_sha1, but write the data into the object specified by
* the the first argument. Returns the first argument on success, and NULL on
* error.
*/
extern const struct object_id *nth_packed_object_oid(struct object_id *, struct packed_git *, uint32_t n);
/* /*
* Return the offset of the nth object within the specified packfile. * Return the offset of the nth object within the specified packfile.
@ -1714,7 +1729,7 @@ extern int unpack_object_header(struct packed_git *, struct pack_window **, off_
* scratch buffer, but restored to its original contents before * scratch buffer, but restored to its original contents before
* the function returns. * the function returns.
*/ */
typedef int each_loose_object_fn(const unsigned char *sha1, typedef int each_loose_object_fn(const struct object_id *oid,
const char *path, const char *path,
void *data); void *data);
typedef int each_loose_cruft_fn(const char *basename, typedef int each_loose_cruft_fn(const char *basename,
@ -1740,7 +1755,7 @@ int for_each_loose_file_in_objdir_buf(struct strbuf *path,
* LOCAL_ONLY flag is set). * LOCAL_ONLY flag is set).
*/ */
#define FOR_EACH_OBJECT_LOCAL_ONLY 0x1 #define FOR_EACH_OBJECT_LOCAL_ONLY 0x1
typedef int each_packed_object_fn(const unsigned char *sha1, typedef int each_packed_object_fn(const struct object_id *oid,
struct packed_git *pack, struct packed_git *pack,
uint32_t pos, uint32_t pos,
void *data); void *data);

8
hex.c
View File

@ -53,6 +53,14 @@ int get_oid_hex(const char *hex, struct object_id *oid)
return get_sha1_hex(hex, oid->hash); return get_sha1_hex(hex, oid->hash);
} }
int parse_oid_hex(const char *hex, struct object_id *oid, const char **end)
{
int ret = get_oid_hex(hex, oid);
if (!ret)
*end = hex + GIT_SHA1_HEXSZ;
return ret;
}
char *sha1_to_hex_r(char *buffer, const unsigned char *sha1) char *sha1_to_hex_r(char *buffer, const unsigned char *sha1)
{ {
static const char hex[] = "0123456789abcdef"; static const char hex[] = "0123456789abcdef";

View File

@ -58,7 +58,7 @@ struct recent_data {
unsigned long timestamp; unsigned long timestamp;
}; };
static void add_recent_object(const unsigned char *sha1, static void add_recent_object(const struct object_id *oid,
unsigned long mtime, unsigned long mtime,
struct recent_data *data) struct recent_data *data)
{ {
@ -75,37 +75,37 @@ static void add_recent_object(const unsigned char *sha1,
* later processing, and the revision machinery expects * later processing, and the revision machinery expects
* commits and tags to have been parsed. * commits and tags to have been parsed.
*/ */
type = sha1_object_info(sha1, NULL); type = sha1_object_info(oid->hash, NULL);
if (type < 0) if (type < 0)
die("unable to get object info for %s", sha1_to_hex(sha1)); die("unable to get object info for %s", oid_to_hex(oid));
switch (type) { switch (type) {
case OBJ_TAG: case OBJ_TAG:
case OBJ_COMMIT: case OBJ_COMMIT:
obj = parse_object_or_die(sha1, NULL); obj = parse_object_or_die(oid->hash, NULL);
break; break;
case OBJ_TREE: case OBJ_TREE:
obj = (struct object *)lookup_tree(sha1); obj = (struct object *)lookup_tree(oid->hash);
break; break;
case OBJ_BLOB: case OBJ_BLOB:
obj = (struct object *)lookup_blob(sha1); obj = (struct object *)lookup_blob(oid->hash);
break; break;
default: default:
die("unknown object type for %s: %s", die("unknown object type for %s: %s",
sha1_to_hex(sha1), typename(type)); oid_to_hex(oid), typename(type));
} }
if (!obj) if (!obj)
die("unable to lookup %s", sha1_to_hex(sha1)); die("unable to lookup %s", oid_to_hex(oid));
add_pending_object(data->revs, obj, ""); add_pending_object(data->revs, obj, "");
} }
static int add_recent_loose(const unsigned char *sha1, static int add_recent_loose(const struct object_id *oid,
const char *path, void *data) const char *path, void *data)
{ {
struct stat st; struct stat st;
struct object *obj = lookup_object(sha1); struct object *obj = lookup_object(oid->hash);
if (obj && obj->flags & SEEN) if (obj && obj->flags & SEEN)
return 0; return 0;
@ -119,22 +119,22 @@ static int add_recent_loose(const unsigned char *sha1,
*/ */
if (errno == ENOENT) if (errno == ENOENT)
return 0; return 0;
return error_errno("unable to stat %s", sha1_to_hex(sha1)); return error_errno("unable to stat %s", oid_to_hex(oid));
} }
add_recent_object(sha1, st.st_mtime, data); add_recent_object(oid, st.st_mtime, data);
return 0; return 0;
} }
static int add_recent_packed(const unsigned char *sha1, static int add_recent_packed(const struct object_id *oid,
struct packed_git *p, uint32_t pos, struct packed_git *p, uint32_t pos,
void *data) void *data)
{ {
struct object *obj = lookup_object(sha1); struct object *obj = lookup_object(oid->hash);
if (obj && obj->flags & SEEN) if (obj && obj->flags & SEEN)
return 0; return 0;
add_recent_object(sha1, p->mtime, data); add_recent_object(oid, p->mtime, data);
return 0; return 0;
} }

View File

@ -1297,9 +1297,9 @@ static void populate_value(struct ref_array_item *ref)
ref->value = xcalloc(used_atom_cnt, sizeof(struct atom_value)); ref->value = xcalloc(used_atom_cnt, sizeof(struct atom_value));
if (need_symref && (ref->flag & REF_ISSYMREF) && !ref->symref) { if (need_symref && (ref->flag & REF_ISSYMREF) && !ref->symref) {
unsigned char unused1[20]; struct object_id unused1;
ref->symref = resolve_refdup(ref->refname, RESOLVE_REF_READING, ref->symref = resolve_refdup(ref->refname, RESOLVE_REF_READING,
unused1, NULL); unused1.hash, NULL);
if (!ref->symref) if (!ref->symref)
ref->symref = ""; ref->symref = "";
} }

View File

@ -10,7 +10,7 @@ struct complete_reflogs {
char *ref; char *ref;
const char *short_ref; const char *short_ref;
struct reflog_info { struct reflog_info {
unsigned char osha1[20], nsha1[20]; struct object_id ooid, noid;
char *email; char *email;
unsigned long timestamp; unsigned long timestamp;
int tz; int tz;
@ -19,7 +19,7 @@ struct complete_reflogs {
int nr, alloc; int nr, alloc;
}; };
static int read_one_reflog(unsigned char *osha1, unsigned char *nsha1, static int read_one_reflog(struct object_id *ooid, struct object_id *noid,
const char *email, unsigned long timestamp, int tz, const char *email, unsigned long timestamp, int tz,
const char *message, void *cb_data) const char *message, void *cb_data)
{ {
@ -28,8 +28,8 @@ static int read_one_reflog(unsigned char *osha1, unsigned char *nsha1,
ALLOC_GROW(array->items, array->nr + 1, array->alloc); ALLOC_GROW(array->items, array->nr + 1, array->alloc);
item = array->items + array->nr; item = array->items + array->nr;
hashcpy(item->osha1, osha1); oidcpy(&item->ooid, ooid);
hashcpy(item->nsha1, nsha1); oidcpy(&item->noid, noid);
item->email = xstrdup(email); item->email = xstrdup(email);
item->timestamp = timestamp; item->timestamp = timestamp;
item->tz = tz; item->tz = tz;
@ -45,11 +45,11 @@ static struct complete_reflogs *read_complete_reflog(const char *ref)
reflogs->ref = xstrdup(ref); reflogs->ref = xstrdup(ref);
for_each_reflog_ent(ref, read_one_reflog, reflogs); for_each_reflog_ent(ref, read_one_reflog, reflogs);
if (reflogs->nr == 0) { if (reflogs->nr == 0) {
unsigned char sha1[20]; struct object_id oid;
const char *name; const char *name;
void *name_to_free; void *name_to_free;
name = name_to_free = resolve_refdup(ref, RESOLVE_REF_READING, name = name_to_free = resolve_refdup(ref, RESOLVE_REF_READING,
sha1, NULL); oid.hash, NULL);
if (name) { if (name) {
for_each_reflog_ent(name, read_one_reflog, reflogs); for_each_reflog_ent(name, read_one_reflog, reflogs);
free(name_to_free); free(name_to_free);
@ -172,18 +172,18 @@ int add_reflog_for_walk(struct reflog_walk_info *info,
reflogs = item->util; reflogs = item->util;
else { else {
if (*branch == '\0') { if (*branch == '\0') {
unsigned char sha1[20]; struct object_id oid;
free(branch); free(branch);
branch = resolve_refdup("HEAD", 0, sha1, NULL); branch = resolve_refdup("HEAD", 0, oid.hash, NULL);
if (!branch) if (!branch)
die ("No current branch"); die ("No current branch");
} }
reflogs = read_complete_reflog(branch); reflogs = read_complete_reflog(branch);
if (!reflogs || reflogs->nr == 0) { if (!reflogs || reflogs->nr == 0) {
unsigned char sha1[20]; struct object_id oid;
char *b; char *b;
if (dwim_log(branch, strlen(branch), sha1, &b) == 1) { if (dwim_log(branch, strlen(branch), oid.hash, &b) == 1) {
if (reflogs) { if (reflogs) {
free(reflogs->ref); free(reflogs->ref);
free(reflogs); free(reflogs);
@ -238,13 +238,13 @@ void fake_reflog_parent(struct reflog_walk_info *info, struct commit *commit)
do { do {
reflog = &commit_reflog->reflogs->items[commit_reflog->recno]; reflog = &commit_reflog->reflogs->items[commit_reflog->recno];
commit_reflog->recno--; commit_reflog->recno--;
logobj = parse_object(reflog->osha1); logobj = parse_object(reflog->ooid.hash);
} while (commit_reflog->recno && (logobj && logobj->type != OBJ_COMMIT)); } while (commit_reflog->recno && (logobj && logobj->type != OBJ_COMMIT));
if (!logobj && commit_reflog->recno >= 0 && is_null_sha1(reflog->osha1)) { if (!logobj && commit_reflog->recno >= 0 && is_null_sha1(reflog->ooid.hash)) {
/* a root commit, but there are still more entries to show */ /* a root commit, but there are still more entries to show */
reflog = &commit_reflog->reflogs->items[commit_reflog->recno]; reflog = &commit_reflog->reflogs->items[commit_reflog->recno];
logobj = parse_object(reflog->nsha1); logobj = parse_object(reflog->noid.hash);
} }
if (!logobj || logobj->type != OBJ_COMMIT) { if (!logobj || logobj->type != OBJ_COMMIT) {

24
refs.c
View File

@ -675,7 +675,7 @@ struct read_ref_at_cb {
int *cutoff_cnt; int *cutoff_cnt;
}; };
static int read_ref_at_ent(unsigned char *osha1, unsigned char *nsha1, static int read_ref_at_ent(struct object_id *ooid, struct object_id *noid,
const char *email, unsigned long timestamp, int tz, const char *email, unsigned long timestamp, int tz,
const char *message, void *cb_data) const char *message, void *cb_data)
{ {
@ -699,30 +699,30 @@ static int read_ref_at_ent(unsigned char *osha1, unsigned char *nsha1,
* hold the values for the previous record. * hold the values for the previous record.
*/ */
if (!is_null_sha1(cb->osha1)) { if (!is_null_sha1(cb->osha1)) {
hashcpy(cb->sha1, nsha1); hashcpy(cb->sha1, noid->hash);
if (hashcmp(cb->osha1, nsha1)) if (hashcmp(cb->osha1, noid->hash))
warning("Log for ref %s has gap after %s.", warning("Log for ref %s has gap after %s.",
cb->refname, show_date(cb->date, cb->tz, DATE_MODE(RFC2822))); cb->refname, show_date(cb->date, cb->tz, DATE_MODE(RFC2822)));
} }
else if (cb->date == cb->at_time) else if (cb->date == cb->at_time)
hashcpy(cb->sha1, nsha1); hashcpy(cb->sha1, noid->hash);
else if (hashcmp(nsha1, cb->sha1)) else if (hashcmp(noid->hash, cb->sha1))
warning("Log for ref %s unexpectedly ended on %s.", warning("Log for ref %s unexpectedly ended on %s.",
cb->refname, show_date(cb->date, cb->tz, cb->refname, show_date(cb->date, cb->tz,
DATE_MODE(RFC2822))); DATE_MODE(RFC2822)));
hashcpy(cb->osha1, osha1); hashcpy(cb->osha1, ooid->hash);
hashcpy(cb->nsha1, nsha1); hashcpy(cb->nsha1, noid->hash);
cb->found_it = 1; cb->found_it = 1;
return 1; return 1;
} }
hashcpy(cb->osha1, osha1); hashcpy(cb->osha1, ooid->hash);
hashcpy(cb->nsha1, nsha1); hashcpy(cb->nsha1, noid->hash);
if (cb->cnt > 0) if (cb->cnt > 0)
cb->cnt--; cb->cnt--;
return 0; return 0;
} }
static int read_ref_at_ent_oldest(unsigned char *osha1, unsigned char *nsha1, static int read_ref_at_ent_oldest(struct object_id *ooid, struct object_id *noid,
const char *email, unsigned long timestamp, const char *email, unsigned long timestamp,
int tz, const char *message, void *cb_data) int tz, const char *message, void *cb_data)
{ {
@ -736,9 +736,9 @@ static int read_ref_at_ent_oldest(unsigned char *osha1, unsigned char *nsha1,
*cb->cutoff_tz = tz; *cb->cutoff_tz = tz;
if (cb->cutoff_cnt) if (cb->cutoff_cnt)
*cb->cutoff_cnt = cb->reccnt; *cb->cutoff_cnt = cb->reccnt;
hashcpy(cb->sha1, osha1); hashcpy(cb->sha1, ooid->hash);
if (is_null_sha1(cb->sha1)) if (is_null_sha1(cb->sha1))
hashcpy(cb->sha1, nsha1); hashcpy(cb->sha1, noid->hash);
/* We just want the first entry */ /* We just want the first entry */
return 1; return 1;
} }

2
refs.h
View File

@ -292,7 +292,7 @@ int delete_reflog(const char *refname);
/* iterate over reflog entries */ /* iterate over reflog entries */
typedef int each_reflog_ent_fn( typedef int each_reflog_ent_fn(
unsigned char *old_sha1, unsigned char *new_sha1, struct object_id *old_oid, struct object_id *new_oid,
const char *committer, unsigned long timestamp, const char *committer, unsigned long timestamp,
int tz, const char *msg, void *cb_data); int tz, const char *msg, void *cb_data);

View File

@ -3102,16 +3102,17 @@ static int files_delete_reflog(struct ref_store *ref_store,
static int show_one_reflog_ent(struct strbuf *sb, each_reflog_ent_fn fn, void *cb_data) static int show_one_reflog_ent(struct strbuf *sb, each_reflog_ent_fn fn, void *cb_data)
{ {
unsigned char osha1[20], nsha1[20]; struct object_id ooid, noid;
char *email_end, *message; char *email_end, *message;
unsigned long timestamp; unsigned long timestamp;
int tz; int tz;
const char *p = sb->buf;
/* old SP new SP name <email> SP time TAB msg LF */ /* old SP new SP name <email> SP time TAB msg LF */
if (sb->len < 83 || sb->buf[sb->len - 1] != '\n' || if (!sb->len || sb->buf[sb->len - 1] != '\n' ||
get_sha1_hex(sb->buf, osha1) || sb->buf[40] != ' ' || parse_oid_hex(p, &ooid, &p) || *p++ != ' ' ||
get_sha1_hex(sb->buf + 41, nsha1) || sb->buf[81] != ' ' || parse_oid_hex(p, &noid, &p) || *p++ != ' ' ||
!(email_end = strchr(sb->buf + 82, '>')) || !(email_end = strchr(p, '>')) ||
email_end[1] != ' ' || email_end[1] != ' ' ||
!(timestamp = strtoul(email_end + 2, &message, 10)) || !(timestamp = strtoul(email_end + 2, &message, 10)) ||
!message || message[0] != ' ' || !message || message[0] != ' ' ||
@ -3125,7 +3126,7 @@ static int show_one_reflog_ent(struct strbuf *sb, each_reflog_ent_fn fn, void *c
message += 6; message += 6;
else else
message += 7; message += 7;
return fn(osha1, nsha1, sb->buf + 82, timestamp, tz, message, cb_data); return fn(&ooid, &noid, p, timestamp, tz, message, cb_data);
} }
static char *find_beginning_of_line(char *bob, char *scan) static char *find_beginning_of_line(char *bob, char *scan)
@ -3954,10 +3955,10 @@ struct expire_reflog_cb {
reflog_expiry_should_prune_fn *should_prune_fn; reflog_expiry_should_prune_fn *should_prune_fn;
void *policy_cb; void *policy_cb;
FILE *newlog; FILE *newlog;
unsigned char last_kept_sha1[20]; struct object_id last_kept_oid;
}; };
static int expire_reflog_ent(unsigned char *osha1, unsigned char *nsha1, static int expire_reflog_ent(struct object_id *ooid, struct object_id *noid,
const char *email, unsigned long timestamp, int tz, const char *email, unsigned long timestamp, int tz,
const char *message, void *cb_data) const char *message, void *cb_data)
{ {
@ -3965,9 +3966,9 @@ static int expire_reflog_ent(unsigned char *osha1, unsigned char *nsha1,
struct expire_reflog_policy_cb *policy_cb = cb->policy_cb; struct expire_reflog_policy_cb *policy_cb = cb->policy_cb;
if (cb->flags & EXPIRE_REFLOGS_REWRITE) if (cb->flags & EXPIRE_REFLOGS_REWRITE)
osha1 = cb->last_kept_sha1; ooid = &cb->last_kept_oid;
if ((*cb->should_prune_fn)(osha1, nsha1, email, timestamp, tz, if ((*cb->should_prune_fn)(ooid->hash, noid->hash, email, timestamp, tz,
message, policy_cb)) { message, policy_cb)) {
if (!cb->newlog) if (!cb->newlog)
printf("would prune %s", message); printf("would prune %s", message);
@ -3976,9 +3977,9 @@ static int expire_reflog_ent(unsigned char *osha1, unsigned char *nsha1,
} else { } else {
if (cb->newlog) { if (cb->newlog) {
fprintf(cb->newlog, "%s %s %s %lu %+05d\t%s", fprintf(cb->newlog, "%s %s %s %lu %+05d\t%s",
sha1_to_hex(osha1), sha1_to_hex(nsha1), oid_to_hex(ooid), oid_to_hex(noid),
email, timestamp, tz, message); email, timestamp, tz, message);
hashcpy(cb->last_kept_sha1, nsha1); oidcpy(&cb->last_kept_oid, noid);
} }
if (cb->flags & EXPIRE_REFLOGS_VERBOSE) if (cb->flags & EXPIRE_REFLOGS_VERBOSE)
printf("keep %s", message); printf("keep %s", message);
@ -4065,14 +4066,14 @@ static int files_reflog_expire(struct ref_store *ref_store,
*/ */
int update = (flags & EXPIRE_REFLOGS_UPDATE_REF) && int update = (flags & EXPIRE_REFLOGS_UPDATE_REF) &&
!(type & REF_ISSYMREF) && !(type & REF_ISSYMREF) &&
!is_null_sha1(cb.last_kept_sha1); !is_null_oid(&cb.last_kept_oid);
if (close_lock_file(&reflog_lock)) { if (close_lock_file(&reflog_lock)) {
status |= error("couldn't write %s: %s", log_file, status |= error("couldn't write %s: %s", log_file,
strerror(errno)); strerror(errno));
} else if (update && } else if (update &&
(write_in_full(get_lock_file_fd(lock->lk), (write_in_full(get_lock_file_fd(lock->lk),
sha1_to_hex(cb.last_kept_sha1), 40) != 40 || oid_to_hex(&cb.last_kept_oid), GIT_SHA1_HEXSZ) != GIT_SHA1_HEXSZ ||
write_str_in_full(get_lock_file_fd(lock->lk), "\n") != 1 || write_str_in_full(get_lock_file_fd(lock->lk), "\n") != 1 ||
close_ref(lock) < 0)) { close_ref(lock) < 0)) {
status |= error("couldn't write %s", status |= error("couldn't write %s",

View File

@ -1196,11 +1196,11 @@ static void handle_refs(const char *submodule, struct rev_info *revs, unsigned f
for_each(submodule, handle_one_ref, &cb); for_each(submodule, handle_one_ref, &cb);
} }
static void handle_one_reflog_commit(unsigned char *sha1, void *cb_data) static void handle_one_reflog_commit(struct object_id *oid, void *cb_data)
{ {
struct all_refs_cb *cb = cb_data; struct all_refs_cb *cb = cb_data;
if (!is_null_sha1(sha1)) { if (!is_null_oid(oid)) {
struct object *o = parse_object(sha1); struct object *o = parse_object(oid->hash);
if (o) { if (o) {
o->flags |= cb->all_flags; o->flags |= cb->all_flags;
/* ??? CMDLINEFLAGS ??? */ /* ??? CMDLINEFLAGS ??? */
@ -1214,12 +1214,12 @@ static void handle_one_reflog_commit(unsigned char *sha1, void *cb_data)
} }
} }
static int handle_one_reflog_ent(unsigned char *osha1, unsigned char *nsha1, static int handle_one_reflog_ent(struct object_id *ooid, struct object_id *noid,
const char *email, unsigned long timestamp, int tz, const char *email, unsigned long timestamp, int tz,
const char *message, void *cb_data) const char *message, void *cb_data)
{ {
handle_one_reflog_commit(osha1, cb_data); handle_one_reflog_commit(ooid, cb_data);
handle_one_reflog_commit(nsha1, cb_data); handle_one_reflog_commit(noid, cb_data);
return 0; return 0;
} }

View File

@ -2706,6 +2706,17 @@ const unsigned char *nth_packed_object_sha1(struct packed_git *p,
} }
} }
const struct object_id *nth_packed_object_oid(struct object_id *oid,
struct packed_git *p,
uint32_t n)
{
const unsigned char *hash = nth_packed_object_sha1(p, n);
if (!hash)
return NULL;
hashcpy(oid->hash, hash);
return oid;
}
void check_pack_index_ptr(const struct packed_git *p, const void *vptr) void check_pack_index_ptr(const struct packed_git *p, const void *vptr)
{ {
const unsigned char *ptr = vptr; const unsigned char *ptr = vptr;
@ -3752,15 +3763,15 @@ static int for_each_file_in_obj_subdir(int subdir_nr,
strbuf_setlen(path, baselen); strbuf_setlen(path, baselen);
strbuf_addf(path, "/%s", de->d_name); strbuf_addf(path, "/%s", de->d_name);
if (strlen(de->d_name) == 38) { if (strlen(de->d_name) == GIT_SHA1_HEXSZ - 2) {
char hex[41]; char hex[GIT_SHA1_HEXSZ+1];
unsigned char sha1[20]; struct object_id oid;
snprintf(hex, sizeof(hex), "%02x%s", snprintf(hex, sizeof(hex), "%02x%s",
subdir_nr, de->d_name); subdir_nr, de->d_name);
if (!get_sha1_hex(hex, sha1)) { if (!get_oid_hex(hex, &oid)) {
if (obj_cb) { if (obj_cb) {
r = obj_cb(sha1, path->buf, data); r = obj_cb(&oid, path->buf, data);
if (r) if (r)
break; break;
} }
@ -3866,13 +3877,13 @@ static int for_each_object_in_pack(struct packed_git *p, each_packed_object_fn c
int r = 0; int r = 0;
for (i = 0; i < p->num_objects; i++) { for (i = 0; i < p->num_objects; i++) {
const unsigned char *sha1 = nth_packed_object_sha1(p, i); struct object_id oid;
if (!sha1) if (!nth_packed_object_oid(&oid, p, i))
return error("unable to get sha1 of object %u in %s", return error("unable to get sha1 of object %u in %s",
i, p->pack_name); i, p->pack_name);
r = cb(sha1, p, i, data); r = cb(&oid, p, i, data);
if (r) if (r)
break; break;
} }

View File

@ -1051,7 +1051,7 @@ struct grab_nth_branch_switch_cbdata {
struct strbuf buf; struct strbuf buf;
}; };
static int grab_nth_branch_switch(unsigned char *osha1, unsigned char *nsha1, static int grab_nth_branch_switch(struct object_id *ooid, struct object_id *noid,
const char *email, unsigned long timestamp, int tz, const char *email, unsigned long timestamp, int tz,
const char *message, void *cb_data) const char *message, void *cb_data)
{ {

View File

@ -471,11 +471,11 @@ void transport_print_push_status(const char *dest, struct ref *refs,
{ {
struct ref *ref; struct ref *ref;
int n = 0; int n = 0;
unsigned char head_sha1[20]; struct object_id head_oid;
char *head; char *head;
int summary_width = transport_summary_width(refs); int summary_width = transport_summary_width(refs);
head = resolve_refdup("HEAD", RESOLVE_REF_READING, head_sha1, NULL); head = resolve_refdup("HEAD", RESOLVE_REF_READING, head_oid.hash, NULL);
if (verbose) { if (verbose) {
for (ref = refs; ref; ref = ref->next) for (ref = refs; ref; ref = ref->next)

View File

@ -121,7 +121,7 @@ static void status_printf_more(struct wt_status *s, const char *color,
void wt_status_prepare(struct wt_status *s) void wt_status_prepare(struct wt_status *s)
{ {
unsigned char sha1[20]; struct object_id oid;
memset(s, 0, sizeof(*s)); memset(s, 0, sizeof(*s));
memcpy(s->color_palette, default_wt_status_colors, memcpy(s->color_palette, default_wt_status_colors,
@ -129,7 +129,7 @@ void wt_status_prepare(struct wt_status *s)
s->show_untracked_files = SHOW_NORMAL_UNTRACKED_FILES; s->show_untracked_files = SHOW_NORMAL_UNTRACKED_FILES;
s->use_color = -1; s->use_color = -1;
s->relative_paths = 1; s->relative_paths = 1;
s->branch = resolve_refdup("HEAD", 0, sha1, NULL); s->branch = resolve_refdup("HEAD", 0, oid.hash, NULL);
s->reference = "HEAD"; s->reference = "HEAD";
s->fp = stdout; s->fp = stdout;
s->index_file = get_index_file(); s->index_file = get_index_file();
@ -1115,16 +1115,16 @@ static void abbrev_sha1_in_line(struct strbuf *line)
split = strbuf_split_max(line, ' ', 3); split = strbuf_split_max(line, ' ', 3);
if (split[0] && split[1]) { if (split[0] && split[1]) {
unsigned char sha1[20]; struct object_id oid;
/* /*
* strbuf_split_max left a space. Trim it and re-add * strbuf_split_max left a space. Trim it and re-add
* it after abbreviation. * it after abbreviation.
*/ */
strbuf_trim(split[1]); strbuf_trim(split[1]);
if (!get_sha1(split[1]->buf, sha1)) { if (!get_oid(split[1]->buf, &oid)) {
strbuf_reset(split[1]); strbuf_reset(split[1]);
strbuf_add_unique_abbrev(split[1], sha1, strbuf_add_unique_abbrev(split[1], oid.hash,
DEFAULT_ABBREV); DEFAULT_ABBREV);
strbuf_addch(split[1], ' '); strbuf_addch(split[1], ' ');
strbuf_reset(line); strbuf_reset(line);
@ -1340,7 +1340,7 @@ static void show_bisect_in_progress(struct wt_status *s,
static char *get_branch(const struct worktree *wt, const char *path) static char *get_branch(const struct worktree *wt, const char *path)
{ {
struct strbuf sb = STRBUF_INIT; struct strbuf sb = STRBUF_INIT;
unsigned char sha1[20]; struct object_id oid;
const char *branch_name; const char *branch_name;
if (strbuf_read_file(&sb, worktree_git_path(wt, "%s", path), 0) <= 0) if (strbuf_read_file(&sb, worktree_git_path(wt, "%s", path), 0) <= 0)
@ -1354,9 +1354,9 @@ static char *get_branch(const struct worktree *wt, const char *path)
strbuf_remove(&sb, 0, branch_name - sb.buf); strbuf_remove(&sb, 0, branch_name - sb.buf);
else if (starts_with(sb.buf, "refs/")) else if (starts_with(sb.buf, "refs/"))
; ;
else if (!get_sha1_hex(sb.buf, sha1)) { else if (!get_oid_hex(sb.buf, &oid)) {
strbuf_reset(&sb); strbuf_reset(&sb);
strbuf_add_unique_abbrev(&sb, sha1, DEFAULT_ABBREV); strbuf_add_unique_abbrev(&sb, oid.hash, DEFAULT_ABBREV);
} else if (!strcmp(sb.buf, "detached HEAD")) /* rebase */ } else if (!strcmp(sb.buf, "detached HEAD")) /* rebase */
goto got_nothing; goto got_nothing;
else /* bisect */ else /* bisect */
@ -1370,10 +1370,10 @@ got_nothing:
struct grab_1st_switch_cbdata { struct grab_1st_switch_cbdata {
struct strbuf buf; struct strbuf buf;
unsigned char nsha1[20]; struct object_id noid;
}; };
static int grab_1st_switch(unsigned char *osha1, unsigned char *nsha1, static int grab_1st_switch(struct object_id *ooid, struct object_id *noid,
const char *email, unsigned long timestamp, int tz, const char *email, unsigned long timestamp, int tz,
const char *message, void *cb_data) const char *message, void *cb_data)
{ {
@ -1387,13 +1387,13 @@ static int grab_1st_switch(unsigned char *osha1, unsigned char *nsha1,
return 0; return 0;
target += strlen(" to "); target += strlen(" to ");
strbuf_reset(&cb->buf); strbuf_reset(&cb->buf);
hashcpy(cb->nsha1, nsha1); oidcpy(&cb->noid, noid);
end = strchrnul(target, '\n'); end = strchrnul(target, '\n');
strbuf_add(&cb->buf, target, end - target); strbuf_add(&cb->buf, target, end - target);
if (!strcmp(cb->buf.buf, "HEAD")) { if (!strcmp(cb->buf.buf, "HEAD")) {
/* HEAD is relative. Resolve it to the right reflog entry. */ /* HEAD is relative. Resolve it to the right reflog entry. */
strbuf_reset(&cb->buf); strbuf_reset(&cb->buf);
strbuf_add_unique_abbrev(&cb->buf, nsha1, DEFAULT_ABBREV); strbuf_add_unique_abbrev(&cb->buf, noid->hash, DEFAULT_ABBREV);
} }
return 1; return 1;
} }
@ -1402,7 +1402,7 @@ static void wt_status_get_detached_from(struct wt_status_state *state)
{ {
struct grab_1st_switch_cbdata cb; struct grab_1st_switch_cbdata cb;
struct commit *commit; struct commit *commit;
unsigned char sha1[20]; struct object_id oid;
char *ref = NULL; char *ref = NULL;
strbuf_init(&cb.buf, 0); strbuf_init(&cb.buf, 0);
@ -1411,22 +1411,22 @@ static void wt_status_get_detached_from(struct wt_status_state *state)
return; return;
} }
if (dwim_ref(cb.buf.buf, cb.buf.len, sha1, &ref) == 1 && if (dwim_ref(cb.buf.buf, cb.buf.len, oid.hash, &ref) == 1 &&
/* sha1 is a commit? match without further lookup */ /* sha1 is a commit? match without further lookup */
(!hashcmp(cb.nsha1, sha1) || (!oidcmp(&cb.noid, &oid) ||
/* perhaps sha1 is a tag, try to dereference to a commit */ /* perhaps sha1 is a tag, try to dereference to a commit */
((commit = lookup_commit_reference_gently(sha1, 1)) != NULL && ((commit = lookup_commit_reference_gently(oid.hash, 1)) != NULL &&
!hashcmp(cb.nsha1, commit->object.oid.hash)))) { !oidcmp(&cb.noid, &commit->object.oid)))) {
const char *from = ref; const char *from = ref;
if (!skip_prefix(from, "refs/tags/", &from)) if (!skip_prefix(from, "refs/tags/", &from))
skip_prefix(from, "refs/remotes/", &from); skip_prefix(from, "refs/remotes/", &from);
state->detached_from = xstrdup(from); state->detached_from = xstrdup(from);
} else } else
state->detached_from = state->detached_from =
xstrdup(find_unique_abbrev(cb.nsha1, DEFAULT_ABBREV)); xstrdup(find_unique_abbrev(cb.noid.hash, DEFAULT_ABBREV));
hashcpy(state->detached_sha1, cb.nsha1); hashcpy(state->detached_sha1, cb.noid.hash);
state->detached_at = !get_sha1("HEAD", sha1) && state->detached_at = !get_oid("HEAD", &oid) &&
!hashcmp(sha1, state->detached_sha1); !hashcmp(oid.hash, state->detached_sha1);
free(ref); free(ref);
strbuf_release(&cb.buf); strbuf_release(&cb.buf);
@ -1476,22 +1476,22 @@ void wt_status_get_state(struct wt_status_state *state,
int get_detached_from) int get_detached_from)
{ {
struct stat st; struct stat st;
unsigned char sha1[20]; struct object_id oid;
if (!stat(git_path_merge_head(), &st)) { if (!stat(git_path_merge_head(), &st)) {
state->merge_in_progress = 1; state->merge_in_progress = 1;
} else if (wt_status_check_rebase(NULL, state)) { } else if (wt_status_check_rebase(NULL, state)) {
; /* all set */ ; /* all set */
} else if (!stat(git_path_cherry_pick_head(), &st) && } else if (!stat(git_path_cherry_pick_head(), &st) &&
!get_sha1("CHERRY_PICK_HEAD", sha1)) { !get_oid("CHERRY_PICK_HEAD", &oid)) {
state->cherry_pick_in_progress = 1; state->cherry_pick_in_progress = 1;
hashcpy(state->cherry_pick_head_sha1, sha1); hashcpy(state->cherry_pick_head_sha1, oid.hash);
} }
wt_status_check_bisect(NULL, state); wt_status_check_bisect(NULL, state);
if (!stat(git_path_revert_head(), &st) && if (!stat(git_path_revert_head(), &st) &&
!get_sha1("REVERT_HEAD", sha1)) { !get_oid("REVERT_HEAD", &oid)) {
state->revert_in_progress = 1; state->revert_in_progress = 1;
hashcpy(state->revert_head_sha1, sha1); hashcpy(state->revert_head_sha1, oid.hash);
} }
if (get_detached_from) if (get_detached_from)