Browse Source

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 <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
maint
René Scharfe 7 years ago committed by Junio C Hamano
parent
commit
744c040b19
  1. 3
      branch.c
  2. 3
      builtin/commit.c
  3. 3
      builtin/log.c
  4. 3
      builtin/receive-pack.c
  5. 3
      builtin/remote.c
  6. 6
      builtin/submodule--helper.c
  7. 3
      builtin/symbolic-ref.c
  8. 3
      http-backend.c
  9. 3
      log-tree.c
  10. 6
      refs.c
  11. 12
      remote.c
  12. 3
      revision.c
  13. 3
      transport.c
  14. 3
      upload-pack.c

3
branch.c

@ -191,9 +191,8 @@ int validate_new_branchname(const char *name, struct strbuf *ref, @@ -191,9 +191,8 @@ int validate_new_branchname(const char *name, struct strbuf *ref,

if (!attr_only) {
const char *head;
struct object_id oid;

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

3
builtin/commit.c

@ -1431,7 +1431,6 @@ static void print_summary(const char *prefix, const struct object_id *oid, @@ -1431,7 +1431,6 @@ static void print_summary(const char *prefix, const struct object_id *oid,
struct rev_info rev;
struct commit *commit;
struct strbuf format = STRBUF_INIT;
struct object_id junk_oid;
const char *head;
struct pretty_print_context pctx = {0};
struct strbuf author_ident = STRBUF_INIT;
@ -1484,7 +1483,7 @@ static void print_summary(const char *prefix, const struct object_id *oid, @@ -1484,7 +1483,7 @@ static void print_summary(const char *prefix, const struct object_id *oid,
rev.diffopt.break_opt = 0;
diff_setup_done(&rev.diffopt);

head = resolve_ref_unsafe("HEAD", 0, junk_oid.hash, NULL);
head = resolve_ref_unsafe("HEAD", 0, NULL, NULL);
if (!strcmp(head, "HEAD"))
head = _("detached HEAD");
else

3
builtin/log.c

@ -1660,10 +1660,9 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix) @@ -1660,10 +1660,9 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
check_head = 1;

if (check_head) {
struct object_id oid;
const char *ref, *v;
ref = resolve_ref_unsafe("HEAD", RESOLVE_REF_READING,
oid.hash, NULL);
NULL, NULL);
if (ref && skip_prefix(ref, "refs/heads/", &v))
branch_name = xstrdup(v);
else

3
builtin/receive-pack.c

@ -1207,11 +1207,10 @@ static void check_aliased_update(struct command *cmd, struct string_list *list) @@ -1207,11 +1207,10 @@ static void check_aliased_update(struct command *cmd, struct string_list *list)
const char *dst_name;
struct string_list_item *item;
struct command *dst_cmd;
unsigned char sha1[GIT_MAX_RAWSZ];
int flag;

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

if (!(flag & REF_ISSYMREF))

3
builtin/remote.c

@ -558,14 +558,13 @@ static int read_remote_branches(const char *refname, @@ -558,14 +558,13 @@ static int read_remote_branches(const char *refname,
struct strbuf buf = STRBUF_INIT;
struct string_list_item *item;
int flag;
struct object_id orig_oid;
const char *symref;

strbuf_addf(&buf, "refs/remotes/%s/", rename->old);
if (starts_with(refname, buf.buf)) {
item = string_list_append(rename->remote_branches, xstrdup(refname));
symref = resolve_ref_unsafe(refname, RESOLVE_REF_READING,
orig_oid.hash, &flag);
NULL, &flag);
if (flag & REF_ISSYMREF)
item->util = xstrdup(symref);
else

6
builtin/submodule--helper.c

@ -17,9 +17,8 @@ @@ -17,9 +17,8 @@
static char *get_default_remote(void)
{
char *dest = NULL, *ret;
unsigned char sha1[20];
struct strbuf sb = STRBUF_INIT;
const char *refname = resolve_ref_unsafe("HEAD", 0, sha1, NULL);
const char *refname = resolve_ref_unsafe("HEAD", 0, NULL, NULL);

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

if (!strcmp(branch, ".")) {
unsigned char sha1[20];
const char *refname = resolve_ref_unsafe("HEAD", 0, sha1, NULL);
const char *refname = resolve_ref_unsafe("HEAD", 0, NULL, NULL);

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

3
builtin/symbolic-ref.c

@ -12,9 +12,8 @@ static const char * const git_symbolic_ref_usage[] = { @@ -12,9 +12,8 @@ static const char * const git_symbolic_ref_usage[] = {

static int check_symref(const char *HEAD, int quiet, int shorten, int print)
{
unsigned char sha1[20];
int flag;
const char *refname = resolve_ref_unsafe(HEAD, 0, sha1, &flag);
const char *refname = resolve_ref_unsafe(HEAD, 0, NULL, &flag);

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

3
http-backend.c

@ -486,10 +486,9 @@ static int show_head_ref(const char *refname, const struct object_id *oid, @@ -486,10 +486,9 @@ static int show_head_ref(const char *refname, const struct object_id *oid,
struct strbuf *buf = cb_data;

if (flag & REF_ISSYMREF) {
struct object_id unused;
const char *target = resolve_ref_unsafe(refname,
RESOLVE_REF_READING,
unused.hash, NULL);
NULL, NULL);

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

3
log-tree.c

@ -185,7 +185,6 @@ static const struct name_decoration *current_pointed_by_HEAD(const struct name_d @@ -185,7 +185,6 @@ static const struct name_decoration *current_pointed_by_HEAD(const struct name_d
{
const struct name_decoration *list, *head = NULL;
const char *branch_name = NULL;
struct object_id unused;
int rru_flags;

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

/* Now resolve and find the matching current branch */
branch_name = resolve_ref_unsafe("HEAD", 0, unused.hash, &rru_flags);
branch_name = resolve_ref_unsafe("HEAD", 0, NULL, &rru_flags);
if (!(rru_flags & REF_ISSYMREF))
return NULL;


6
refs.c

@ -239,8 +239,7 @@ int read_ref(const char *refname, unsigned char *sha1) @@ -239,8 +239,7 @@ int read_ref(const char *refname, unsigned char *sha1)

int ref_exists(const char *refname)
{
unsigned char sha1[20];
return !!resolve_ref_unsafe(refname, RESOLVE_REF_READING, sha1, NULL);
return !!resolve_ref_unsafe(refname, RESOLVE_REF_READING, NULL, NULL);
}

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 * @@ -286,12 +285,11 @@ static int warn_if_dangling_symref(const char *refname, const struct object_id *
{
struct warn_if_dangling_data *d = cb_data;
const char *resolves_to;
struct object_id junk;

if (!(flags & REF_ISSYMREF))
return 0;

resolves_to = resolve_ref_unsafe(refname, 0, junk.hash, NULL);
resolves_to = resolve_ref_unsafe(refname, 0, NULL, NULL);
if (!resolves_to
|| (d->refname
? strcmp(resolves_to, d->refname)

12
remote.c

@ -466,7 +466,6 @@ static void alias_all_urls(void) @@ -466,7 +466,6 @@ static void alias_all_urls(void)
static void read_config(void)
{
static int loaded;
struct object_id oid;
int flag;

if (loaded)
@ -475,7 +474,7 @@ static void read_config(void) @@ -475,7 +474,7 @@ static void read_config(void)

current_branch = NULL;
if (startup_info->have_repository) {
const char *head_ref = resolve_ref_unsafe("HEAD", 0, oid.hash, &flag);
const char *head_ref = resolve_ref_unsafe("HEAD", 0, NULL, &flag);
if (head_ref && (flag & REF_ISSYMREF) &&
skip_prefix(head_ref, "refs/heads/", &head_ref)) {
current_branch = make_branch(head_ref, 0);
@ -1105,10 +1104,9 @@ static struct ref *make_linked_ref(const char *name, struct ref ***tail) @@ -1105,10 +1104,9 @@ static struct ref *make_linked_ref(const char *name, struct ref ***tail)
static char *guess_ref(const char *name, struct ref *peer)
{
struct strbuf buf = STRBUF_INIT;
struct object_id oid;

const char *r = resolve_ref_unsafe(peer->name, RESOLVE_REF_READING,
oid.hash, NULL);
NULL, NULL);
if (!r)
return NULL;

@ -1166,12 +1164,11 @@ static int match_explicit(struct ref *src, struct ref *dst, @@ -1166,12 +1164,11 @@ static int match_explicit(struct ref *src, struct ref *dst,
return -1;

if (!dst_value) {
struct object_id oid;
int flag;

dst_value = resolve_ref_unsafe(matched_src->name,
RESOLVE_REF_READING,
oid.hash, &flag);
NULL, &flag);
if (!dst_value ||
((flag & REF_ISSYMREF) &&
!starts_with(dst_value, "refs/heads/")))
@ -1792,10 +1789,9 @@ const char *branch_get_push(struct branch *branch, struct strbuf *err) @@ -1792,10 +1789,9 @@ const char *branch_get_push(struct branch *branch, struct strbuf *err)

static int ignore_symref_update(const char *refname)
{
struct object_id oid;
int flag;

if (!resolve_ref_unsafe(refname, 0, oid.hash, &flag))
if (!resolve_ref_unsafe(refname, 0, NULL, &flag))
return 0; /* non-existing refs are OK */
return (flag & REF_ISSYMREF);
}

3
revision.c

@ -2263,11 +2263,10 @@ static int handle_revision_pseudo_opt(const char *submodule, @@ -2263,11 +2263,10 @@ static int handle_revision_pseudo_opt(const char *submodule,

static void NORETURN diagnose_missing_default(const char *def)
{
unsigned char sha1[20];
int flags;
const char *refname;

refname = resolve_ref_unsafe(def, 0, sha1, &flags);
refname = resolve_ref_unsafe(def, 0, NULL, &flags);
if (!refname || !(flags & REF_ISSYMREF) || (flags & REF_ISBROKEN))
die(_("your current branch appears to be broken"));


3
transport.c

@ -26,7 +26,6 @@ static void set_upstreams(struct transport *transport, struct ref *refs, @@ -26,7 +26,6 @@ static void set_upstreams(struct transport *transport, struct ref *refs,
const char *localname;
const char *tmp;
const char *remotename;
unsigned char sha[20];
int flag = 0;
/*
* Check suitability for tracking. Must be successful /
@ -44,7 +43,7 @@ static void set_upstreams(struct transport *transport, struct ref *refs, @@ -44,7 +43,7 @@ static void set_upstreams(struct transport *transport, struct ref *refs,
localname = ref->peer_ref->name;
remotename = ref->name;
tmp = resolve_ref_unsafe(localname, RESOLVE_REF_READING,
sha, &flag);
NULL, &flag);
if (tmp && flag & REF_ISSYMREF &&
starts_with(tmp, "refs/heads/"))
localname = tmp;

3
upload-pack.c

@ -965,11 +965,10 @@ static int find_symref(const char *refname, const struct object_id *oid, @@ -965,11 +965,10 @@ static int find_symref(const char *refname, const struct object_id *oid,
{
const char *symref_target;
struct string_list_item *item;
struct object_id unused;

if ((flag & REF_ISSYMREF) == 0)
return 0;
symref_target = resolve_ref_unsafe(refname, 0, unused.hash, &flag);
symref_target = resolve_ref_unsafe(refname, 0, NULL, &flag);
if (!symref_target || (flag & REF_ISSYMREF) == 0)
die("'%s' is a symref but it is not?", refname);
item = string_list_append(cb_data, refname);

Loading…
Cancel
Save