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>
brian m. carlson committed
Sep 5, 2016 at 20:08 UTC
60af7691db8abc0550add4dcd9e02bd474fca318
1 file changed
+33
-33
builtin/checkout.c
+33
-33
@@ -175,9 +175,9 @@ static int checkout_merged(int pos, struct checkout *state)
175
const char *path = ce->name;
176
mmfile_t ancestor, ours, theirs;
177
int status;
178
- unsigned char sha1[20];
178
+ struct object_id oid;
179
mmbuffer_t result_buf;
180
- unsigned char threeway[3][20];
180
+ struct object_id threeway[3];
181
unsigned mode = 0;
182
183
memset(threeway, 0, sizeof(threeway));
@@ -186,18 +186,18 @@ static int checkout_merged(int pos, struct checkout *state)
186
stage = ce_stage(ce);
187
if (!stage || strcmp(path, ce->name))
188
break;
189
- hashcpy(threeway[stage - 1], ce->oid.hash);
189
+ oidcpy(&threeway[stage - 1], &ce->oid);
190
if (stage == 2)
191
mode = create_ce_mode(ce->ce_mode);
192
pos++;
193
ce = active_cache[pos];
194
}
195
- if (is_null_sha1(threeway[1]) || is_null_sha1(threeway[2]))
195
+ if (is_null_oid(&threeway[1]) || is_null_oid(&threeway[2]))
196
return error(_("path '%s' does not have necessary versions"), path);
197
198
- read_mmblob(&ancestor, threeway[0]);
199
- read_mmblob(&ours, threeway[1]);
200
- read_mmblob(&theirs, threeway[2]);
198
+ read_mmblob(&ancestor, threeway[0].hash);
199
+ read_mmblob(&ours, threeway[1].hash);
200
+ read_mmblob(&theirs, threeway[2].hash);
201
202
/*
203
* NEEDSWORK: re-create conflicts from merges with
@@ -226,9 +226,9 @@ static int checkout_merged(int pos, struct checkout *state)
226
* object database even when it may contain conflicts).
227
*/
228
if (write_sha1_file(result_buf.ptr, result_buf.size,
229
- blob_type, sha1))
229
+ blob_type, oid.hash))
230
die(_("Unable to add merge result for '%s'"), path);
231
- ce = make_cache_entry(mode, sha1, path, 2, 0);
231
+ ce = make_cache_entry(mode, oid.hash, path, 2, 0);
232
if (!ce)
233
die(_("make_cache_entry failed for path '%s'"), path);
234
status = checkout_entry(ce, state, NULL);
@@ -241,7 +241,7 @@ static int checkout_paths(const struct checkout_opts *opts,
241
int pos;
242
struct checkout state;
243
static char *ps_matched;
244
- unsigned char rev[20];
244
+ struct object_id rev;
245
struct commit *head;
246
int errs = 0;
247
struct lock_file *lock_file;
@@ -374,8 +374,8 @@ static int checkout_paths(const struct checkout_opts *opts,
374
if (write_locked_index(&the_index, lock_file, COMMIT_LOCK))
375
die(_("unable to write new index file"));
376
377
- read_ref_full("HEAD", 0, rev, NULL);
378
- head = lookup_commit_reference_gently(rev, 1);
377
+ read_ref_full("HEAD", 0, rev.hash, NULL);
378
+ head = lookup_commit_reference_gently(rev.hash, 1);
379
380
errs |= post_checkout_hook(head, head, 0);
381
return errs;
@@ -808,11 +808,11 @@ static int switch_branches(const struct checkout_opts *opts,
808
int ret = 0;
809
struct branch_info old;
810
void *path_to_free;
811
- unsigned char rev[20];
811
+ struct object_id rev;
812
int flag, writeout_error = 0;
813
memset(&old, 0, sizeof(old));
814
- old.path = path_to_free = resolve_refdup("HEAD", 0, rev, &flag);
815
- old.commit = lookup_commit_reference_gently(rev, 1);
814
+ old.path = path_to_free = resolve_refdup("HEAD", 0, rev.hash, &flag);
815
+ old.commit = lookup_commit_reference_gently(rev.hash, 1);
816
if (!(flag & REF_ISSYMREF))
817
old.path = NULL;
818
@@ -860,7 +860,7 @@ static int git_checkout_config(const char *var, const char *value, void *cb)
860
struct tracking_name_data {
861
/* const */ char *src_ref;
862
char *dst_ref;
863
- unsigned char *dst_sha1;
863
+ struct object_id *dst_oid;
864
int unique;
865
};
866
@@ -871,7 +871,7 @@ static int check_tracking_name(struct remote *remote, void *cb_data)
871
memset(&query, 0, sizeof(struct refspec));
872
query.src = cb->src_ref;
873
if (remote_find_tracking(remote, &query) ||
874
- get_sha1(query.dst, cb->dst_sha1)) {
874
+ get_oid(query.dst, cb->dst_oid)) {
875
free(query.dst);
876
return 0;
877
}
@@ -884,13 +884,13 @@ static int check_tracking_name(struct remote *remote, void *cb_data)
884
return 0;
885
}
886
887
-static const char *unique_tracking_name(const char *name, unsigned char *sha1)
887
+static const char *unique_tracking_name(const char *name, struct object_id *oid)
888
{
889
struct tracking_name_data cb_data = { NULL, NULL, NULL, 1 };
890
char src_ref[PATH_MAX];
891
snprintf(src_ref, PATH_MAX, "refs/heads/%s", name);
892
cb_data.src_ref = src_ref;
893
- cb_data.dst_sha1 = sha1;
893
+ cb_data.dst_oid = oid;
894
for_each_remote(check_tracking_name, &cb_data);
895
if (cb_data.unique)
896
return cb_data.dst_ref;
@@ -902,12 +902,12 @@ static int parse_branchname_arg(int argc, const char **argv,
902
int dwim_new_local_branch_ok,
903
struct branch_info *new,
904
struct checkout_opts *opts,
905
- unsigned char rev[20])
905
+ struct object_id *rev)
906
{
907
struct tree **source_tree = &opts->source_tree;
908
const char **new_branch = &opts->new_branch;
909
int argcount = 0;
910
- unsigned char branch_rev[20];
910
+ struct object_id branch_rev;
911
const char *arg;
912
int dash_dash_pos;
913
int has_dash_dash = 0;
@@ -973,7 +973,7 @@ static int parse_branchname_arg(int argc, const char **argv,
973
if (!strcmp(arg, "-"))
974
arg = "@{-1}";
975
976
- if (get_sha1_mb(arg, rev)) {
976
+ if (get_sha1_mb(arg, rev->hash)) {
977
/*
978
* Either case (3) or (4), with <something> not being
979
* 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,
1022
setup_branch_path(new);
1023
1024
if (!check_refname_format(new->path, 0) &&
1025
- !read_ref(new->path, branch_rev))
1026
- hashcpy(rev, branch_rev);
1025
+ !read_ref(new->path, branch_rev.hash))
1026
+ oidcpy(rev, &branch_rev);
1027
else
1028
new->path = NULL; /* not an existing branch */
1029
1030
- new->commit = lookup_commit_reference_gently(rev, 1);
1030
+ new->commit = lookup_commit_reference_gently(rev->hash, 1);
1031
if (!new->commit) {
1032
/* not a commit */
1033
- *source_tree = parse_tree_indirect(rev);
1033
+ *source_tree = parse_tree_indirect(rev->hash);
1034
} else {
1035
parse_commit_or_die(new->commit);
1036
*source_tree = new->commit->tree;
@@ -1108,9 +1108,9 @@ static int checkout_branch(struct checkout_opts *opts,
1108
1109
if (new->path && !opts->force_detach && !opts->new_branch &&
1110
!opts->ignore_other_worktrees) {
1111
- unsigned char sha1[20];
1111
+ struct object_id oid;
1112
int flag;
1113
- char *head_ref = resolve_refdup("HEAD", 0, sha1, &flag);
1113
+ char *head_ref = resolve_refdup("HEAD", 0, oid.hash, &flag);
1114
if (head_ref &&
1115
(!(flag & REF_ISSYMREF) || strcmp(head_ref, new->path)))
1116
die_if_checked_out(new->path, 1);
@@ -1118,11 +1118,11 @@ static int checkout_branch(struct checkout_opts *opts,
1118
}
1119
1120
if (!new->commit && opts->new_branch) {
1121
- unsigned char rev[20];
1121
+ struct object_id rev;
1122
int flag;
1123
1124
- if (!read_ref_full("HEAD", 0, rev, &flag) &&
1125
- (flag & REF_ISSYMREF) && is_null_sha1(rev))
1124
+ if (!read_ref_full("HEAD", 0, rev.hash, &flag) &&
1125
+ (flag & REF_ISSYMREF) && is_null_oid(&rev))
1126
return switch_unborn_to_new_branch(opts);
1127
}
1128
return switch_branches(opts, new);
@@ -1232,14 +1232,14 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
1232
* remote branches, erroring out for invalid or ambiguous cases.
1233
*/
1234
if (argc) {
1235
- unsigned char rev[20];
1235
+ struct object_id rev;
1236
int dwim_ok =
1237
!opts.patch_mode &&
1238
dwim_new_local_branch &&
1239
opts.track == BRANCH_TRACK_UNSPECIFIED &&
1240
!opts.new_branch;
1241
int n = parse_branchname_arg(argc, argv, dwim_ok,
1242
- &new, &opts, rev);
1242
+ &new, &opts, &rev);
1243
argv += n;
1244
argc -= n;
1245
}