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>
This commit is contained in:
parent
e691b027b6
commit
744c040b19
3
branch.c
3
branch.c
@ -191,9 +191,8 @@ int validate_new_branchname(const char *name, struct strbuf *ref,
|
|||||||
|
|
||||||
if (!attr_only) {
|
if (!attr_only) {
|
||||||
const char *head;
|
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))
|
if (!is_bare_repository() && head && !strcmp(head, ref->buf))
|
||||||
die(_("Cannot force update the current branch."));
|
die(_("Cannot force update the current branch."));
|
||||||
}
|
}
|
||||||
|
@ -1431,7 +1431,6 @@ static void print_summary(const char *prefix, const struct object_id *oid,
|
|||||||
struct rev_info rev;
|
struct rev_info rev;
|
||||||
struct commit *commit;
|
struct commit *commit;
|
||||||
struct strbuf format = STRBUF_INIT;
|
struct strbuf format = STRBUF_INIT;
|
||||||
struct object_id junk_oid;
|
|
||||||
const char *head;
|
const char *head;
|
||||||
struct pretty_print_context pctx = {0};
|
struct pretty_print_context pctx = {0};
|
||||||
struct strbuf author_ident = STRBUF_INIT;
|
struct strbuf author_ident = STRBUF_INIT;
|
||||||
@ -1484,7 +1483,7 @@ static void print_summary(const char *prefix, const struct object_id *oid,
|
|||||||
rev.diffopt.break_opt = 0;
|
rev.diffopt.break_opt = 0;
|
||||||
diff_setup_done(&rev.diffopt);
|
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"))
|
if (!strcmp(head, "HEAD"))
|
||||||
head = _("detached HEAD");
|
head = _("detached HEAD");
|
||||||
else
|
else
|
||||||
|
@ -1660,10 +1660,9 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
|
|||||||
check_head = 1;
|
check_head = 1;
|
||||||
|
|
||||||
if (check_head) {
|
if (check_head) {
|
||||||
struct object_id oid;
|
|
||||||
const char *ref, *v;
|
const char *ref, *v;
|
||||||
ref = resolve_ref_unsafe("HEAD", RESOLVE_REF_READING,
|
ref = resolve_ref_unsafe("HEAD", RESOLVE_REF_READING,
|
||||||
oid.hash, NULL);
|
NULL, NULL);
|
||||||
if (ref && skip_prefix(ref, "refs/heads/", &v))
|
if (ref && skip_prefix(ref, "refs/heads/", &v))
|
||||||
branch_name = xstrdup(v);
|
branch_name = xstrdup(v);
|
||||||
else
|
else
|
||||||
|
@ -1207,11 +1207,10 @@ static void check_aliased_update(struct command *cmd, struct string_list *list)
|
|||||||
const char *dst_name;
|
const char *dst_name;
|
||||||
struct string_list_item *item;
|
struct string_list_item *item;
|
||||||
struct command *dst_cmd;
|
struct command *dst_cmd;
|
||||||
unsigned char sha1[GIT_MAX_RAWSZ];
|
|
||||||
int flag;
|
int flag;
|
||||||
|
|
||||||
strbuf_addf(&buf, "%s%s", get_git_namespace(), cmd->ref_name);
|
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);
|
strbuf_release(&buf);
|
||||||
|
|
||||||
if (!(flag & REF_ISSYMREF))
|
if (!(flag & REF_ISSYMREF))
|
||||||
|
@ -558,14 +558,13 @@ static int read_remote_branches(const char *refname,
|
|||||||
struct strbuf buf = STRBUF_INIT;
|
struct strbuf buf = STRBUF_INIT;
|
||||||
struct string_list_item *item;
|
struct string_list_item *item;
|
||||||
int flag;
|
int flag;
|
||||||
struct object_id orig_oid;
|
|
||||||
const char *symref;
|
const char *symref;
|
||||||
|
|
||||||
strbuf_addf(&buf, "refs/remotes/%s/", rename->old);
|
strbuf_addf(&buf, "refs/remotes/%s/", rename->old);
|
||||||
if (starts_with(refname, buf.buf)) {
|
if (starts_with(refname, buf.buf)) {
|
||||||
item = string_list_append(rename->remote_branches, xstrdup(refname));
|
item = string_list_append(rename->remote_branches, xstrdup(refname));
|
||||||
symref = resolve_ref_unsafe(refname, RESOLVE_REF_READING,
|
symref = resolve_ref_unsafe(refname, RESOLVE_REF_READING,
|
||||||
orig_oid.hash, &flag);
|
NULL, &flag);
|
||||||
if (flag & REF_ISSYMREF)
|
if (flag & REF_ISSYMREF)
|
||||||
item->util = xstrdup(symref);
|
item->util = xstrdup(symref);
|
||||||
else
|
else
|
||||||
|
@ -17,9 +17,8 @@
|
|||||||
static char *get_default_remote(void)
|
static char *get_default_remote(void)
|
||||||
{
|
{
|
||||||
char *dest = NULL, *ret;
|
char *dest = NULL, *ret;
|
||||||
unsigned char sha1[20];
|
|
||||||
struct strbuf sb = STRBUF_INIT;
|
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)
|
if (!refname)
|
||||||
die(_("No such ref: %s"), "HEAD");
|
die(_("No such ref: %s"), "HEAD");
|
||||||
@ -1089,8 +1088,7 @@ static const char *remote_submodule_branch(const char *path)
|
|||||||
return "master";
|
return "master";
|
||||||
|
|
||||||
if (!strcmp(branch, ".")) {
|
if (!strcmp(branch, ".")) {
|
||||||
unsigned char sha1[20];
|
const char *refname = resolve_ref_unsafe("HEAD", 0, NULL, NULL);
|
||||||
const char *refname = resolve_ref_unsafe("HEAD", 0, sha1, NULL);
|
|
||||||
|
|
||||||
if (!refname)
|
if (!refname)
|
||||||
die(_("No such ref: %s"), "HEAD");
|
die(_("No such ref: %s"), "HEAD");
|
||||||
|
@ -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)
|
static int check_symref(const char *HEAD, int quiet, int shorten, int print)
|
||||||
{
|
{
|
||||||
unsigned char sha1[20];
|
|
||||||
int flag;
|
int flag;
|
||||||
const char *refname = resolve_ref_unsafe(HEAD, 0, sha1, &flag);
|
const char *refname = resolve_ref_unsafe(HEAD, 0, NULL, &flag);
|
||||||
|
|
||||||
if (!refname)
|
if (!refname)
|
||||||
die("No such ref: %s", HEAD);
|
die("No such ref: %s", HEAD);
|
||||||
|
@ -486,10 +486,9 @@ static int show_head_ref(const char *refname, const struct object_id *oid,
|
|||||||
struct strbuf *buf = cb_data;
|
struct strbuf *buf = cb_data;
|
||||||
|
|
||||||
if (flag & REF_ISSYMREF) {
|
if (flag & REF_ISSYMREF) {
|
||||||
struct object_id unused;
|
|
||||||
const char *target = resolve_ref_unsafe(refname,
|
const char *target = resolve_ref_unsafe(refname,
|
||||||
RESOLVE_REF_READING,
|
RESOLVE_REF_READING,
|
||||||
unused.hash, NULL);
|
NULL, NULL);
|
||||||
|
|
||||||
if (target)
|
if (target)
|
||||||
strbuf_addf(buf, "ref: %s\n", strip_namespace(target));
|
strbuf_addf(buf, "ref: %s\n", strip_namespace(target));
|
||||||
|
@ -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 struct name_decoration *list, *head = NULL;
|
||||||
const char *branch_name = NULL;
|
const char *branch_name = NULL;
|
||||||
struct object_id unused;
|
|
||||||
int rru_flags;
|
int rru_flags;
|
||||||
|
|
||||||
/* First find HEAD */
|
/* First find HEAD */
|
||||||
@ -198,7 +197,7 @@ static const struct name_decoration *current_pointed_by_HEAD(const struct name_d
|
|||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
/* Now resolve and find the matching current branch */
|
/* 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))
|
if (!(rru_flags & REF_ISSYMREF))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
6
refs.c
6
refs.c
@ -239,8 +239,7 @@ int read_ref(const char *refname, unsigned char *sha1)
|
|||||||
|
|
||||||
int ref_exists(const char *refname)
|
int ref_exists(const char *refname)
|
||||||
{
|
{
|
||||||
unsigned char sha1[20];
|
return !!resolve_ref_unsafe(refname, RESOLVE_REF_READING, NULL, NULL);
|
||||||
return !!resolve_ref_unsafe(refname, RESOLVE_REF_READING, sha1, NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int filter_refs(const char *refname, const struct object_id *oid,
|
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 *
|
|||||||
{
|
{
|
||||||
struct warn_if_dangling_data *d = cb_data;
|
struct warn_if_dangling_data *d = cb_data;
|
||||||
const char *resolves_to;
|
const char *resolves_to;
|
||||||
struct object_id junk;
|
|
||||||
|
|
||||||
if (!(flags & REF_ISSYMREF))
|
if (!(flags & REF_ISSYMREF))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
resolves_to = resolve_ref_unsafe(refname, 0, junk.hash, NULL);
|
resolves_to = resolve_ref_unsafe(refname, 0, NULL, NULL);
|
||||||
if (!resolves_to
|
if (!resolves_to
|
||||||
|| (d->refname
|
|| (d->refname
|
||||||
? strcmp(resolves_to, d->refname)
|
? strcmp(resolves_to, d->refname)
|
||||||
|
12
remote.c
12
remote.c
@ -466,7 +466,6 @@ static void alias_all_urls(void)
|
|||||||
static void read_config(void)
|
static void read_config(void)
|
||||||
{
|
{
|
||||||
static int loaded;
|
static int loaded;
|
||||||
struct object_id oid;
|
|
||||||
int flag;
|
int flag;
|
||||||
|
|
||||||
if (loaded)
|
if (loaded)
|
||||||
@ -475,7 +474,7 @@ static void read_config(void)
|
|||||||
|
|
||||||
current_branch = NULL;
|
current_branch = NULL;
|
||||||
if (startup_info->have_repository) {
|
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) &&
|
if (head_ref && (flag & REF_ISSYMREF) &&
|
||||||
skip_prefix(head_ref, "refs/heads/", &head_ref)) {
|
skip_prefix(head_ref, "refs/heads/", &head_ref)) {
|
||||||
current_branch = make_branch(head_ref, 0);
|
current_branch = make_branch(head_ref, 0);
|
||||||
@ -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)
|
static char *guess_ref(const char *name, struct ref *peer)
|
||||||
{
|
{
|
||||||
struct strbuf buf = STRBUF_INIT;
|
struct strbuf buf = STRBUF_INIT;
|
||||||
struct object_id oid;
|
|
||||||
|
|
||||||
const char *r = resolve_ref_unsafe(peer->name, RESOLVE_REF_READING,
|
const char *r = resolve_ref_unsafe(peer->name, RESOLVE_REF_READING,
|
||||||
oid.hash, NULL);
|
NULL, NULL);
|
||||||
if (!r)
|
if (!r)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
@ -1166,12 +1164,11 @@ static int match_explicit(struct ref *src, struct ref *dst,
|
|||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (!dst_value) {
|
if (!dst_value) {
|
||||||
struct object_id oid;
|
|
||||||
int flag;
|
int flag;
|
||||||
|
|
||||||
dst_value = resolve_ref_unsafe(matched_src->name,
|
dst_value = resolve_ref_unsafe(matched_src->name,
|
||||||
RESOLVE_REF_READING,
|
RESOLVE_REF_READING,
|
||||||
oid.hash, &flag);
|
NULL, &flag);
|
||||||
if (!dst_value ||
|
if (!dst_value ||
|
||||||
((flag & REF_ISSYMREF) &&
|
((flag & REF_ISSYMREF) &&
|
||||||
!starts_with(dst_value, "refs/heads/")))
|
!starts_with(dst_value, "refs/heads/")))
|
||||||
@ -1792,10 +1789,9 @@ const char *branch_get_push(struct branch *branch, struct strbuf *err)
|
|||||||
|
|
||||||
static int ignore_symref_update(const char *refname)
|
static int ignore_symref_update(const char *refname)
|
||||||
{
|
{
|
||||||
struct object_id oid;
|
|
||||||
int flag;
|
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 0; /* non-existing refs are OK */
|
||||||
return (flag & REF_ISSYMREF);
|
return (flag & REF_ISSYMREF);
|
||||||
}
|
}
|
||||||
|
@ -2263,11 +2263,10 @@ static int handle_revision_pseudo_opt(const char *submodule,
|
|||||||
|
|
||||||
static void NORETURN diagnose_missing_default(const char *def)
|
static void NORETURN diagnose_missing_default(const char *def)
|
||||||
{
|
{
|
||||||
unsigned char sha1[20];
|
|
||||||
int flags;
|
int flags;
|
||||||
const char *refname;
|
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))
|
if (!refname || !(flags & REF_ISSYMREF) || (flags & REF_ISBROKEN))
|
||||||
die(_("your current branch appears to be broken"));
|
die(_("your current branch appears to be broken"));
|
||||||
|
|
||||||
|
@ -26,7 +26,6 @@ static void set_upstreams(struct transport *transport, struct ref *refs,
|
|||||||
const char *localname;
|
const char *localname;
|
||||||
const char *tmp;
|
const char *tmp;
|
||||||
const char *remotename;
|
const char *remotename;
|
||||||
unsigned char sha[20];
|
|
||||||
int flag = 0;
|
int flag = 0;
|
||||||
/*
|
/*
|
||||||
* Check suitability for tracking. Must be successful /
|
* Check suitability for tracking. Must be successful /
|
||||||
@ -44,7 +43,7 @@ static void set_upstreams(struct transport *transport, struct ref *refs,
|
|||||||
localname = ref->peer_ref->name;
|
localname = ref->peer_ref->name;
|
||||||
remotename = ref->name;
|
remotename = ref->name;
|
||||||
tmp = resolve_ref_unsafe(localname, RESOLVE_REF_READING,
|
tmp = resolve_ref_unsafe(localname, RESOLVE_REF_READING,
|
||||||
sha, &flag);
|
NULL, &flag);
|
||||||
if (tmp && flag & REF_ISSYMREF &&
|
if (tmp && flag & REF_ISSYMREF &&
|
||||||
starts_with(tmp, "refs/heads/"))
|
starts_with(tmp, "refs/heads/"))
|
||||||
localname = tmp;
|
localname = tmp;
|
||||||
|
@ -965,11 +965,10 @@ static int find_symref(const char *refname, const struct object_id *oid,
|
|||||||
{
|
{
|
||||||
const char *symref_target;
|
const char *symref_target;
|
||||||
struct string_list_item *item;
|
struct string_list_item *item;
|
||||||
struct object_id unused;
|
|
||||||
|
|
||||||
if ((flag & REF_ISSYMREF) == 0)
|
if ((flag & REF_ISSYMREF) == 0)
|
||||||
return 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)
|
if (!symref_target || (flag & REF_ISSYMREF) == 0)
|
||||||
die("'%s' is a symref but it is not?", refname);
|
die("'%s' is a symref but it is not?", refname);
|
||||||
item = string_list_append(cb_data, refname);
|
item = string_list_append(cb_data, refname);
|
||||||
|
Loading…
Reference in New Issue
Block a user