Skip to content

Commit 744c040

Browse files
rscharfegitster
authored andcommitted
refs: pass NULL to resolve_ref_unsafe() if hash is not needed
This allows us to get rid of some write-only variables, among them seven SHA1 buffers. Signed-off-by: Rene Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e691b02 commit 744c040

File tree

14 files changed

+19
-38
lines changed

14 files changed

+19
-38
lines changed

branch.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,8 @@ int validate_new_branchname(const char *name, struct strbuf *ref,
191191

192192
if (!attr_only) {
193193
const char *head;
194-
struct object_id oid;
195194

196-
head = resolve_ref_unsafe("HEAD", 0, oid.hash, NULL);
195+
head = resolve_ref_unsafe("HEAD", 0, NULL, NULL);
197196
if (!is_bare_repository() && head && !strcmp(head, ref->buf))
198197
die(_("Cannot force update the current branch."));
199198
}

builtin/commit.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1431,7 +1431,6 @@ static void print_summary(const char *prefix, const struct object_id *oid,
14311431
struct rev_info rev;
14321432
struct commit *commit;
14331433
struct strbuf format = STRBUF_INIT;
1434-
struct object_id junk_oid;
14351434
const char *head;
14361435
struct pretty_print_context pctx = {0};
14371436
struct strbuf author_ident = STRBUF_INIT;
@@ -1484,7 +1483,7 @@ static void print_summary(const char *prefix, const struct object_id *oid,
14841483
rev.diffopt.break_opt = 0;
14851484
diff_setup_done(&rev.diffopt);
14861485

1487-
head = resolve_ref_unsafe("HEAD", 0, junk_oid.hash, NULL);
1486+
head = resolve_ref_unsafe("HEAD", 0, NULL, NULL);
14881487
if (!strcmp(head, "HEAD"))
14891488
head = _("detached HEAD");
14901489
else

builtin/log.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1660,10 +1660,9 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
16601660
check_head = 1;
16611661

16621662
if (check_head) {
1663-
struct object_id oid;
16641663
const char *ref, *v;
16651664
ref = resolve_ref_unsafe("HEAD", RESOLVE_REF_READING,
1666-
oid.hash, NULL);
1665+
NULL, NULL);
16671666
if (ref && skip_prefix(ref, "refs/heads/", &v))
16681667
branch_name = xstrdup(v);
16691668
else

builtin/receive-pack.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,11 +1207,10 @@ static void check_aliased_update(struct command *cmd, struct string_list *list)
12071207
const char *dst_name;
12081208
struct string_list_item *item;
12091209
struct command *dst_cmd;
1210-
unsigned char sha1[GIT_MAX_RAWSZ];
12111210
int flag;
12121211

12131212
strbuf_addf(&buf, "%s%s", get_git_namespace(), cmd->ref_name);
1214-
dst_name = resolve_ref_unsafe(buf.buf, 0, sha1, &flag);
1213+
dst_name = resolve_ref_unsafe(buf.buf, 0, NULL, &flag);
12151214
strbuf_release(&buf);
12161215

12171216
if (!(flag & REF_ISSYMREF))

builtin/remote.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -558,14 +558,13 @@ static int read_remote_branches(const char *refname,
558558
struct strbuf buf = STRBUF_INIT;
559559
struct string_list_item *item;
560560
int flag;
561-
struct object_id orig_oid;
562561
const char *symref;
563562

564563
strbuf_addf(&buf, "refs/remotes/%s/", rename->old);
565564
if (starts_with(refname, buf.buf)) {
566565
item = string_list_append(rename->remote_branches, xstrdup(refname));
567566
symref = resolve_ref_unsafe(refname, RESOLVE_REF_READING,
568-
orig_oid.hash, &flag);
567+
NULL, &flag);
569568
if (flag & REF_ISSYMREF)
570569
item->util = xstrdup(symref);
571570
else

builtin/submodule--helper.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@
1717
static char *get_default_remote(void)
1818
{
1919
char *dest = NULL, *ret;
20-
unsigned char sha1[20];
2120
struct strbuf sb = STRBUF_INIT;
22-
const char *refname = resolve_ref_unsafe("HEAD", 0, sha1, NULL);
21+
const char *refname = resolve_ref_unsafe("HEAD", 0, NULL, NULL);
2322

2423
if (!refname)
2524
die(_("No such ref: %s"), "HEAD");
@@ -1089,8 +1088,7 @@ static const char *remote_submodule_branch(const char *path)
10891088
return "master";
10901089

10911090
if (!strcmp(branch, ".")) {
1092-
unsigned char sha1[20];
1093-
const char *refname = resolve_ref_unsafe("HEAD", 0, sha1, NULL);
1091+
const char *refname = resolve_ref_unsafe("HEAD", 0, NULL, NULL);
10941092

10951093
if (!refname)
10961094
die(_("No such ref: %s"), "HEAD");

builtin/symbolic-ref.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@ static const char * const git_symbolic_ref_usage[] = {
1212

1313
static int check_symref(const char *HEAD, int quiet, int shorten, int print)
1414
{
15-
unsigned char sha1[20];
1615
int flag;
17-
const char *refname = resolve_ref_unsafe(HEAD, 0, sha1, &flag);
16+
const char *refname = resolve_ref_unsafe(HEAD, 0, NULL, &flag);
1817

1918
if (!refname)
2019
die("No such ref: %s", HEAD);

http-backend.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -486,10 +486,9 @@ static int show_head_ref(const char *refname, const struct object_id *oid,
486486
struct strbuf *buf = cb_data;
487487

488488
if (flag & REF_ISSYMREF) {
489-
struct object_id unused;
490489
const char *target = resolve_ref_unsafe(refname,
491490
RESOLVE_REF_READING,
492-
unused.hash, NULL);
491+
NULL, NULL);
493492

494493
if (target)
495494
strbuf_addf(buf, "ref: %s\n", strip_namespace(target));

log-tree.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,6 @@ static const struct name_decoration *current_pointed_by_HEAD(const struct name_d
185185
{
186186
const struct name_decoration *list, *head = NULL;
187187
const char *branch_name = NULL;
188-
struct object_id unused;
189188
int rru_flags;
190189

191190
/* First find HEAD */
@@ -198,7 +197,7 @@ static const struct name_decoration *current_pointed_by_HEAD(const struct name_d
198197
return NULL;
199198

200199
/* Now resolve and find the matching current branch */
201-
branch_name = resolve_ref_unsafe("HEAD", 0, unused.hash, &rru_flags);
200+
branch_name = resolve_ref_unsafe("HEAD", 0, NULL, &rru_flags);
202201
if (!(rru_flags & REF_ISSYMREF))
203202
return NULL;
204203

refs.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,7 @@ int read_ref(const char *refname, unsigned char *sha1)
239239

240240
int ref_exists(const char *refname)
241241
{
242-
unsigned char sha1[20];
243-
return !!resolve_ref_unsafe(refname, RESOLVE_REF_READING, sha1, NULL);
242+
return !!resolve_ref_unsafe(refname, RESOLVE_REF_READING, NULL, NULL);
244243
}
245244

246245
static int filter_refs(const char *refname, const struct object_id *oid,
@@ -286,12 +285,11 @@ static int warn_if_dangling_symref(const char *refname, const struct object_id *
286285
{
287286
struct warn_if_dangling_data *d = cb_data;
288287
const char *resolves_to;
289-
struct object_id junk;
290288

291289
if (!(flags & REF_ISSYMREF))
292290
return 0;
293291

294-
resolves_to = resolve_ref_unsafe(refname, 0, junk.hash, NULL);
292+
resolves_to = resolve_ref_unsafe(refname, 0, NULL, NULL);
295293
if (!resolves_to
296294
|| (d->refname
297295
? strcmp(resolves_to, d->refname)

0 commit comments

Comments
 (0)