Skip to content

Commit 3a5d7c5

Browse files
bk2204gitster
authored andcommitted
builtin/reset: convert to use struct object_id
Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 031cee5 commit 3a5d7c5

1 file changed

Lines changed: 26 additions & 26 deletions

File tree

builtin/reset.c

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ static inline int is_merge(void)
3939
return !access(git_path_merge_head(), F_OK);
4040
}
4141

42-
static int reset_index(const unsigned char *sha1, int reset_type, int quiet)
42+
static int reset_index(const struct object_id *oid, int reset_type, int quiet)
4343
{
4444
int nr = 1;
4545
struct tree_desc desc[2];
@@ -69,22 +69,22 @@ static int reset_index(const unsigned char *sha1, int reset_type, int quiet)
6969
read_cache_unmerged();
7070

7171
if (reset_type == KEEP) {
72-
unsigned char head_sha1[20];
73-
if (get_sha1("HEAD", head_sha1))
72+
struct object_id head_oid;
73+
if (get_oid("HEAD", &head_oid))
7474
return error(_("You do not have a valid HEAD."));
75-
if (!fill_tree_descriptor(desc, head_sha1))
75+
if (!fill_tree_descriptor(desc, head_oid.hash))
7676
return error(_("Failed to find tree of HEAD."));
7777
nr++;
7878
opts.fn = twoway_merge;
7979
}
8080

81-
if (!fill_tree_descriptor(desc + nr - 1, sha1))
82-
return error(_("Failed to find tree of %s."), sha1_to_hex(sha1));
81+
if (!fill_tree_descriptor(desc + nr - 1, oid->hash))
82+
return error(_("Failed to find tree of %s."), oid_to_hex(oid));
8383
if (unpack_trees(nr, desc, &opts))
8484
return -1;
8585

8686
if (reset_type == MIXED || reset_type == HARD) {
87-
tree = parse_tree_indirect(sha1);
87+
tree = parse_tree_indirect(oid->hash);
8888
prime_cache_tree(&the_index, tree);
8989
}
9090

@@ -143,7 +143,7 @@ static void update_index_from_diff(struct diff_queue_struct *q,
143143
}
144144

145145
static int read_from_tree(const struct pathspec *pathspec,
146-
unsigned char *tree_sha1,
146+
struct object_id *tree_oid,
147147
int intent_to_add)
148148
{
149149
struct diff_options opt;
@@ -154,7 +154,7 @@ static int read_from_tree(const struct pathspec *pathspec,
154154
opt.format_callback = update_index_from_diff;
155155
opt.format_callback_data = &intent_to_add;
156156

157-
if (do_diff_cache(tree_sha1, &opt))
157+
if (do_diff_cache(tree_oid->hash, &opt))
158158
return 1;
159159
diffcore_std(&opt);
160160
diff_flush(&opt);
@@ -191,7 +191,7 @@ static void parse_args(struct pathspec *pathspec,
191191
const char **rev_ret)
192192
{
193193
const char *rev = "HEAD";
194-
unsigned char unused[20];
194+
struct object_id unused;
195195
/*
196196
* Possible arguments are:
197197
*
@@ -216,8 +216,8 @@ static void parse_args(struct pathspec *pathspec,
216216
* has to be unambiguous. If there is a single argument, it
217217
* can not be a tree
218218
*/
219-
else if ((!argv[1] && !get_sha1_committish(argv[0], unused)) ||
220-
(argv[1] && !get_sha1_treeish(argv[0], unused))) {
219+
else if ((!argv[1] && !get_sha1_committish(argv[0], unused.hash)) ||
220+
(argv[1] && !get_sha1_treeish(argv[0], unused.hash))) {
221221
/*
222222
* Ok, argv[0] looks like a commit/tree; it should not
223223
* be a filename.
@@ -241,24 +241,24 @@ static void parse_args(struct pathspec *pathspec,
241241
prefix, argv);
242242
}
243243

244-
static int reset_refs(const char *rev, const unsigned char *sha1)
244+
static int reset_refs(const char *rev, const struct object_id *oid)
245245
{
246246
int update_ref_status;
247247
struct strbuf msg = STRBUF_INIT;
248-
unsigned char *orig = NULL, sha1_orig[20],
249-
*old_orig = NULL, sha1_old_orig[20];
248+
struct object_id *orig = NULL, oid_orig,
249+
*old_orig = NULL, oid_old_orig;
250250

251-
if (!get_sha1("ORIG_HEAD", sha1_old_orig))
252-
old_orig = sha1_old_orig;
253-
if (!get_sha1("HEAD", sha1_orig)) {
254-
orig = sha1_orig;
251+
if (!get_oid("ORIG_HEAD", &oid_old_orig))
252+
old_orig = &oid_old_orig;
253+
if (!get_oid("HEAD", &oid_orig)) {
254+
orig = &oid_orig;
255255
set_reflog_message(&msg, "updating ORIG_HEAD", NULL);
256-
update_ref(msg.buf, "ORIG_HEAD", orig, old_orig, 0,
256+
update_ref_oid(msg.buf, "ORIG_HEAD", orig, old_orig, 0,
257257
UPDATE_REFS_MSG_ON_ERR);
258258
} else if (old_orig)
259-
delete_ref("ORIG_HEAD", old_orig, 0);
259+
delete_ref("ORIG_HEAD", old_orig->hash, 0);
260260
set_reflog_message(&msg, "updating HEAD", rev);
261-
update_ref_status = update_ref(msg.buf, "HEAD", sha1, orig, 0,
261+
update_ref_status = update_ref_oid(msg.buf, "HEAD", oid, orig, 0,
262262
UPDATE_REFS_MSG_ON_ERR);
263263
strbuf_release(&msg);
264264
return update_ref_status;
@@ -357,15 +357,15 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
357357
hold_locked_index(lock, 1);
358358
if (reset_type == MIXED) {
359359
int flags = quiet ? REFRESH_QUIET : REFRESH_IN_PORCELAIN;
360-
if (read_from_tree(&pathspec, oid.hash, intent_to_add))
360+
if (read_from_tree(&pathspec, &oid, intent_to_add))
361361
return 1;
362362
if (get_git_work_tree())
363363
refresh_index(&the_index, flags, NULL, NULL,
364364
_("Unstaged changes after reset:"));
365365
} else {
366-
int err = reset_index(oid.hash, reset_type, quiet);
366+
int err = reset_index(&oid, reset_type, quiet);
367367
if (reset_type == KEEP && !err)
368-
err = reset_index(oid.hash, MIXED, quiet);
368+
err = reset_index(&oid, MIXED, quiet);
369369
if (err)
370370
die(_("Could not reset index file to revision '%s'."), rev);
371371
}
@@ -377,7 +377,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
377377
if (!pathspec.nr && !unborn) {
378378
/* Any resets without paths update HEAD to the head being
379379
* switched to, saving the previous head in ORIG_HEAD before. */
380-
update_ref_status = reset_refs(rev, oid.hash);
380+
update_ref_status = reset_refs(rev, &oid);
381381

382382
if (reset_type == HARD && !update_ref_status && !quiet)
383383
print_new_head_line(lookup_commit_reference(oid.hash));

0 commit comments

Comments
 (0)