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>
brian m. carlson committed
Sep 5, 2016 at 20:08 UTC
3a5d7c55f76681ad9dcef8564275217881c9ace0
1 file changed
+26
-26
builtin/reset.c
+26
-26
@@ -39,7 +39,7 @@ static inline int is_merge(void)
39
return !access(git_path_merge_head(), F_OK);
40
}
41
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)
43
{
44
int nr = 1;
45
struct tree_desc desc[2];
@@ -69,22 +69,22 @@ static int reset_index(const unsigned char *sha1, int reset_type, int quiet)
69
read_cache_unmerged();
70
71
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))
74
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))
76
return error(_("Failed to find tree of HEAD."));
77
nr++;
78
opts.fn = twoway_merge;
79
}
80
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));
83
if (unpack_trees(nr, desc, &opts))
84
return -1;
85
86
if (reset_type == MIXED || reset_type == HARD) {
87
- tree = parse_tree_indirect(sha1);
87
+ tree = parse_tree_indirect(oid->hash);
88
prime_cache_tree(&the_index, tree);
89
}
90
@@ -143,7 +143,7 @@ static void update_index_from_diff(struct diff_queue_struct *q,
143
}
144
145
static int read_from_tree(const struct pathspec *pathspec,
146
- unsigned char *tree_sha1,
146
+ struct object_id *tree_oid,
147
int intent_to_add)
148
{
149
struct diff_options opt;
@@ -154,7 +154,7 @@ static int read_from_tree(const struct pathspec *pathspec,
154
opt.format_callback = update_index_from_diff;
155
opt.format_callback_data = &intent_to_add;
156
157
- if (do_diff_cache(tree_sha1, &opt))
157
+ if (do_diff_cache(tree_oid->hash, &opt))
158
return 1;
159
diffcore_std(&opt);
160
diff_flush(&opt);
@@ -191,7 +191,7 @@ static void parse_args(struct pathspec *pathspec,
191
const char **rev_ret)
192
{
193
const char *rev = "HEAD";
194
- unsigned char unused[20];
194
+ struct object_id unused;
195
/*
196
* Possible arguments are:
197
*
@@ -216,8 +216,8 @@ static void parse_args(struct pathspec *pathspec,
216
* has to be unambiguous. If there is a single argument, it
217
* can not be a tree
218
*/
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))) {
221
/*
222
* Ok, argv[0] looks like a commit/tree; it should not
223
* be a filename.
@@ -241,24 +241,24 @@ static void parse_args(struct pathspec *pathspec,
241
prefix, argv);
242
}
243
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)
245
{
246
int update_ref_status;
247
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;
250
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;
255
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,
257
UPDATE_REFS_MSG_ON_ERR);
258
} else if (old_orig)
259
- delete_ref("ORIG_HEAD", old_orig, 0);
259
+ delete_ref("ORIG_HEAD", old_orig->hash, 0);
260
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,
262
UPDATE_REFS_MSG_ON_ERR);
263
strbuf_release(&msg);
264
return update_ref_status;
@@ -357,15 +357,15 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
357
hold_locked_index(lock, 1);
358
if (reset_type == MIXED) {
359
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))
361
return 1;
362
if (get_git_work_tree())
363
refresh_index(&the_index, flags, NULL, NULL,
364
_("Unstaged changes after reset:"));
365
} else {
366
- int err = reset_index(oid.hash, reset_type, quiet);
366
+ int err = reset_index(&oid, reset_type, quiet);
367
if (reset_type == KEEP && !err)
368
- err = reset_index(oid.hash, MIXED, quiet);
368
+ err = reset_index(&oid, MIXED, quiet);
369
if (err)
370
die(_("Could not reset index file to revision '%s'."), rev);
371
}
@@ -377,7 +377,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
377
if (!pathspec.nr && !unborn) {
378
/* Any resets without paths update HEAD to the head being
379
* 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);
381
382
if (reset_type == HARD && !update_ref_status && !quiet)
383
print_new_head_line(lookup_commit_reference(oid.hash));