builtin/checkout: convert some static functions to struct object_id
Convert all the static functions that are not callbacks to struct object_id. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
7eda0e4fbb
commit
60af7691db
@ -175,9 +175,9 @@ static int checkout_merged(int pos, struct checkout *state)
|
|||||||
const char *path = ce->name;
|
const char *path = ce->name;
|
||||||
mmfile_t ancestor, ours, theirs;
|
mmfile_t ancestor, ours, theirs;
|
||||||
int status;
|
int status;
|
||||||
unsigned char sha1[20];
|
struct object_id oid;
|
||||||
mmbuffer_t result_buf;
|
mmbuffer_t result_buf;
|
||||||
unsigned char threeway[3][20];
|
struct object_id threeway[3];
|
||||||
unsigned mode = 0;
|
unsigned mode = 0;
|
||||||
|
|
||||||
memset(threeway, 0, sizeof(threeway));
|
memset(threeway, 0, sizeof(threeway));
|
||||||
@ -186,18 +186,18 @@ static int checkout_merged(int pos, struct checkout *state)
|
|||||||
stage = ce_stage(ce);
|
stage = ce_stage(ce);
|
||||||
if (!stage || strcmp(path, ce->name))
|
if (!stage || strcmp(path, ce->name))
|
||||||
break;
|
break;
|
||||||
hashcpy(threeway[stage - 1], ce->oid.hash);
|
oidcpy(&threeway[stage - 1], &ce->oid);
|
||||||
if (stage == 2)
|
if (stage == 2)
|
||||||
mode = create_ce_mode(ce->ce_mode);
|
mode = create_ce_mode(ce->ce_mode);
|
||||||
pos++;
|
pos++;
|
||||||
ce = active_cache[pos];
|
ce = active_cache[pos];
|
||||||
}
|
}
|
||||||
if (is_null_sha1(threeway[1]) || is_null_sha1(threeway[2]))
|
if (is_null_oid(&threeway[1]) || is_null_oid(&threeway[2]))
|
||||||
return error(_("path '%s' does not have necessary versions"), path);
|
return error(_("path '%s' does not have necessary versions"), path);
|
||||||
|
|
||||||
read_mmblob(&ancestor, threeway[0]);
|
read_mmblob(&ancestor, threeway[0].hash);
|
||||||
read_mmblob(&ours, threeway[1]);
|
read_mmblob(&ours, threeway[1].hash);
|
||||||
read_mmblob(&theirs, threeway[2]);
|
read_mmblob(&theirs, threeway[2].hash);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* NEEDSWORK: re-create conflicts from merges with
|
* NEEDSWORK: re-create conflicts from merges with
|
||||||
@ -226,9 +226,9 @@ static int checkout_merged(int pos, struct checkout *state)
|
|||||||
* object database even when it may contain conflicts).
|
* object database even when it may contain conflicts).
|
||||||
*/
|
*/
|
||||||
if (write_sha1_file(result_buf.ptr, result_buf.size,
|
if (write_sha1_file(result_buf.ptr, result_buf.size,
|
||||||
blob_type, sha1))
|
blob_type, oid.hash))
|
||||||
die(_("Unable to add merge result for '%s'"), path);
|
die(_("Unable to add merge result for '%s'"), path);
|
||||||
ce = make_cache_entry(mode, sha1, path, 2, 0);
|
ce = make_cache_entry(mode, oid.hash, path, 2, 0);
|
||||||
if (!ce)
|
if (!ce)
|
||||||
die(_("make_cache_entry failed for path '%s'"), path);
|
die(_("make_cache_entry failed for path '%s'"), path);
|
||||||
status = checkout_entry(ce, state, NULL);
|
status = checkout_entry(ce, state, NULL);
|
||||||
@ -241,7 +241,7 @@ static int checkout_paths(const struct checkout_opts *opts,
|
|||||||
int pos;
|
int pos;
|
||||||
struct checkout state;
|
struct checkout state;
|
||||||
static char *ps_matched;
|
static char *ps_matched;
|
||||||
unsigned char rev[20];
|
struct object_id rev;
|
||||||
struct commit *head;
|
struct commit *head;
|
||||||
int errs = 0;
|
int errs = 0;
|
||||||
struct lock_file *lock_file;
|
struct lock_file *lock_file;
|
||||||
@ -374,8 +374,8 @@ static int checkout_paths(const struct checkout_opts *opts,
|
|||||||
if (write_locked_index(&the_index, lock_file, COMMIT_LOCK))
|
if (write_locked_index(&the_index, lock_file, COMMIT_LOCK))
|
||||||
die(_("unable to write new index file"));
|
die(_("unable to write new index file"));
|
||||||
|
|
||||||
read_ref_full("HEAD", 0, rev, NULL);
|
read_ref_full("HEAD", 0, rev.hash, NULL);
|
||||||
head = lookup_commit_reference_gently(rev, 1);
|
head = lookup_commit_reference_gently(rev.hash, 1);
|
||||||
|
|
||||||
errs |= post_checkout_hook(head, head, 0);
|
errs |= post_checkout_hook(head, head, 0);
|
||||||
return errs;
|
return errs;
|
||||||
@ -808,11 +808,11 @@ static int switch_branches(const struct checkout_opts *opts,
|
|||||||
int ret = 0;
|
int ret = 0;
|
||||||
struct branch_info old;
|
struct branch_info old;
|
||||||
void *path_to_free;
|
void *path_to_free;
|
||||||
unsigned char rev[20];
|
struct object_id rev;
|
||||||
int flag, writeout_error = 0;
|
int flag, writeout_error = 0;
|
||||||
memset(&old, 0, sizeof(old));
|
memset(&old, 0, sizeof(old));
|
||||||
old.path = path_to_free = resolve_refdup("HEAD", 0, rev, &flag);
|
old.path = path_to_free = resolve_refdup("HEAD", 0, rev.hash, &flag);
|
||||||
old.commit = lookup_commit_reference_gently(rev, 1);
|
old.commit = lookup_commit_reference_gently(rev.hash, 1);
|
||||||
if (!(flag & REF_ISSYMREF))
|
if (!(flag & REF_ISSYMREF))
|
||||||
old.path = NULL;
|
old.path = NULL;
|
||||||
|
|
||||||
@ -860,7 +860,7 @@ static int git_checkout_config(const char *var, const char *value, void *cb)
|
|||||||
struct tracking_name_data {
|
struct tracking_name_data {
|
||||||
/* const */ char *src_ref;
|
/* const */ char *src_ref;
|
||||||
char *dst_ref;
|
char *dst_ref;
|
||||||
unsigned char *dst_sha1;
|
struct object_id *dst_oid;
|
||||||
int unique;
|
int unique;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -871,7 +871,7 @@ static int check_tracking_name(struct remote *remote, void *cb_data)
|
|||||||
memset(&query, 0, sizeof(struct refspec));
|
memset(&query, 0, sizeof(struct refspec));
|
||||||
query.src = cb->src_ref;
|
query.src = cb->src_ref;
|
||||||
if (remote_find_tracking(remote, &query) ||
|
if (remote_find_tracking(remote, &query) ||
|
||||||
get_sha1(query.dst, cb->dst_sha1)) {
|
get_oid(query.dst, cb->dst_oid)) {
|
||||||
free(query.dst);
|
free(query.dst);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -884,13 +884,13 @@ static int check_tracking_name(struct remote *remote, void *cb_data)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char *unique_tracking_name(const char *name, unsigned char *sha1)
|
static const char *unique_tracking_name(const char *name, struct object_id *oid)
|
||||||
{
|
{
|
||||||
struct tracking_name_data cb_data = { NULL, NULL, NULL, 1 };
|
struct tracking_name_data cb_data = { NULL, NULL, NULL, 1 };
|
||||||
char src_ref[PATH_MAX];
|
char src_ref[PATH_MAX];
|
||||||
snprintf(src_ref, PATH_MAX, "refs/heads/%s", name);
|
snprintf(src_ref, PATH_MAX, "refs/heads/%s", name);
|
||||||
cb_data.src_ref = src_ref;
|
cb_data.src_ref = src_ref;
|
||||||
cb_data.dst_sha1 = sha1;
|
cb_data.dst_oid = oid;
|
||||||
for_each_remote(check_tracking_name, &cb_data);
|
for_each_remote(check_tracking_name, &cb_data);
|
||||||
if (cb_data.unique)
|
if (cb_data.unique)
|
||||||
return cb_data.dst_ref;
|
return cb_data.dst_ref;
|
||||||
@ -902,12 +902,12 @@ static int parse_branchname_arg(int argc, const char **argv,
|
|||||||
int dwim_new_local_branch_ok,
|
int dwim_new_local_branch_ok,
|
||||||
struct branch_info *new,
|
struct branch_info *new,
|
||||||
struct checkout_opts *opts,
|
struct checkout_opts *opts,
|
||||||
unsigned char rev[20])
|
struct object_id *rev)
|
||||||
{
|
{
|
||||||
struct tree **source_tree = &opts->source_tree;
|
struct tree **source_tree = &opts->source_tree;
|
||||||
const char **new_branch = &opts->new_branch;
|
const char **new_branch = &opts->new_branch;
|
||||||
int argcount = 0;
|
int argcount = 0;
|
||||||
unsigned char branch_rev[20];
|
struct object_id branch_rev;
|
||||||
const char *arg;
|
const char *arg;
|
||||||
int dash_dash_pos;
|
int dash_dash_pos;
|
||||||
int has_dash_dash = 0;
|
int has_dash_dash = 0;
|
||||||
@ -973,7 +973,7 @@ static int parse_branchname_arg(int argc, const char **argv,
|
|||||||
if (!strcmp(arg, "-"))
|
if (!strcmp(arg, "-"))
|
||||||
arg = "@{-1}";
|
arg = "@{-1}";
|
||||||
|
|
||||||
if (get_sha1_mb(arg, rev)) {
|
if (get_sha1_mb(arg, rev->hash)) {
|
||||||
/*
|
/*
|
||||||
* Either case (3) or (4), with <something> not being
|
* Either case (3) or (4), with <something> not being
|
||||||
* a commit, or an attempt to use case (1) with an
|
* a commit, or an attempt to use case (1) with an
|
||||||
@ -1022,15 +1022,15 @@ static int parse_branchname_arg(int argc, const char **argv,
|
|||||||
setup_branch_path(new);
|
setup_branch_path(new);
|
||||||
|
|
||||||
if (!check_refname_format(new->path, 0) &&
|
if (!check_refname_format(new->path, 0) &&
|
||||||
!read_ref(new->path, branch_rev))
|
!read_ref(new->path, branch_rev.hash))
|
||||||
hashcpy(rev, branch_rev);
|
oidcpy(rev, &branch_rev);
|
||||||
else
|
else
|
||||||
new->path = NULL; /* not an existing branch */
|
new->path = NULL; /* not an existing branch */
|
||||||
|
|
||||||
new->commit = lookup_commit_reference_gently(rev, 1);
|
new->commit = lookup_commit_reference_gently(rev->hash, 1);
|
||||||
if (!new->commit) {
|
if (!new->commit) {
|
||||||
/* not a commit */
|
/* not a commit */
|
||||||
*source_tree = parse_tree_indirect(rev);
|
*source_tree = parse_tree_indirect(rev->hash);
|
||||||
} else {
|
} else {
|
||||||
parse_commit_or_die(new->commit);
|
parse_commit_or_die(new->commit);
|
||||||
*source_tree = new->commit->tree;
|
*source_tree = new->commit->tree;
|
||||||
@ -1108,9 +1108,9 @@ static int checkout_branch(struct checkout_opts *opts,
|
|||||||
|
|
||||||
if (new->path && !opts->force_detach && !opts->new_branch &&
|
if (new->path && !opts->force_detach && !opts->new_branch &&
|
||||||
!opts->ignore_other_worktrees) {
|
!opts->ignore_other_worktrees) {
|
||||||
unsigned char sha1[20];
|
struct object_id oid;
|
||||||
int flag;
|
int flag;
|
||||||
char *head_ref = resolve_refdup("HEAD", 0, sha1, &flag);
|
char *head_ref = resolve_refdup("HEAD", 0, oid.hash, &flag);
|
||||||
if (head_ref &&
|
if (head_ref &&
|
||||||
(!(flag & REF_ISSYMREF) || strcmp(head_ref, new->path)))
|
(!(flag & REF_ISSYMREF) || strcmp(head_ref, new->path)))
|
||||||
die_if_checked_out(new->path, 1);
|
die_if_checked_out(new->path, 1);
|
||||||
@ -1118,11 +1118,11 @@ static int checkout_branch(struct checkout_opts *opts,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!new->commit && opts->new_branch) {
|
if (!new->commit && opts->new_branch) {
|
||||||
unsigned char rev[20];
|
struct object_id rev;
|
||||||
int flag;
|
int flag;
|
||||||
|
|
||||||
if (!read_ref_full("HEAD", 0, rev, &flag) &&
|
if (!read_ref_full("HEAD", 0, rev.hash, &flag) &&
|
||||||
(flag & REF_ISSYMREF) && is_null_sha1(rev))
|
(flag & REF_ISSYMREF) && is_null_oid(&rev))
|
||||||
return switch_unborn_to_new_branch(opts);
|
return switch_unborn_to_new_branch(opts);
|
||||||
}
|
}
|
||||||
return switch_branches(opts, new);
|
return switch_branches(opts, new);
|
||||||
@ -1232,14 +1232,14 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
|
|||||||
* remote branches, erroring out for invalid or ambiguous cases.
|
* remote branches, erroring out for invalid or ambiguous cases.
|
||||||
*/
|
*/
|
||||||
if (argc) {
|
if (argc) {
|
||||||
unsigned char rev[20];
|
struct object_id rev;
|
||||||
int dwim_ok =
|
int dwim_ok =
|
||||||
!opts.patch_mode &&
|
!opts.patch_mode &&
|
||||||
dwim_new_local_branch &&
|
dwim_new_local_branch &&
|
||||||
opts.track == BRANCH_TRACK_UNSPECIFIED &&
|
opts.track == BRANCH_TRACK_UNSPECIFIED &&
|
||||||
!opts.new_branch;
|
!opts.new_branch;
|
||||||
int n = parse_branchname_arg(argc, argv, dwim_ok,
|
int n = parse_branchname_arg(argc, argv, dwim_ok,
|
||||||
&new, &opts, rev);
|
&new, &opts, &rev);
|
||||||
argv += n;
|
argv += n;
|
||||||
argc -= n;
|
argc -= n;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user