git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH 1/3] refs: make sha1 output parameter of refs_resolve_ref_unsafe() optional
@ 2017-09-23  9:41 René Scharfe
  2017-09-23  9:44 ` [PATCH 2/3] refs: pass NULL to refs_resolve_ref_unsafe() if hash is not needed René Scharfe
                   ` (4 more replies)
  0 siblings, 5 replies; 8+ messages in thread
From: René Scharfe @ 2017-09-23  9:41 UTC (permalink / raw)
  To: Git List; +Cc: Junio C Hamano, Michael Haggerty

Allow callers of refs_resolve_ref_unsafe() to pass NULL if they don't
need the resolved hash value.  We already allow the same for the flags
parameter.  This new leniency is inherited by the various wrappers like
resolve_ref_unsafe().

Signed-off-by: Rene Scharfe <l.s.r@web.de>
---
 refs.c | 3 +++
 refs.h | 9 +++++----
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/refs.c b/refs.c
index c30f4c36be..36439fdb54 100644
--- a/refs.c
+++ b/refs.c
@@ -1396,9 +1396,12 @@ const char *refs_resolve_ref_unsafe(struct ref_store *refs,
 				    unsigned char *sha1, int *flags)
 {
 	static struct strbuf sb_refname = STRBUF_INIT;
+	struct object_id unused_oid;
 	int unused_flags;
 	int symref_count;
 
+	if (!sha1)
+		sha1 = unused_oid.hash;
 	if (!flags)
 		flags = &unused_flags;
 
diff --git a/refs.h b/refs.h
index 78a26400b6..996d4ea54d 100644
--- a/refs.h
+++ b/refs.h
@@ -10,10 +10,11 @@ struct worktree;
 /*
  * Resolve a reference, recursively following symbolic refererences.
  *
- * Store the referred-to object's name in sha1 and return the name of
- * the non-symbolic reference that ultimately pointed at it.  The
- * return value, if not NULL, is a pointer into either a static buffer
- * or the input ref.
+ * Return the name of the non-symbolic reference that ultimately pointed
+ * at the resolved object name.  The return value, if not NULL, is a
+ * pointer into either a static buffer or the input ref.
+ *
+ * If sha1 is non-NULL, store the referred-to object's name in it.
  *
  * If the reference cannot be resolved to an object, the behavior
  * depends on the RESOLVE_REF_READING flag:
-- 
2.14.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 2/3] refs: pass NULL to refs_resolve_ref_unsafe() if hash is not needed
  2017-09-23  9:41 [PATCH 1/3] refs: make sha1 output parameter of refs_resolve_ref_unsafe() optional René Scharfe
@ 2017-09-23  9:44 ` René Scharfe
  2017-09-23  9:45 ` [PATCH 3/3] refs: pass NULL to resolve_ref_unsafe() " René Scharfe
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: René Scharfe @ 2017-09-23  9:44 UTC (permalink / raw)
  To: Git List; +Cc: Junio C Hamano, Michael Haggerty

This allows us to get rid of two write-only variables, one of them
being a SHA1 buffer.

Signed-off-by: Rene Scharfe <l.s.r@web.de>
---
 refs/files-backend.c | 3 +--
 worktree.c           | 3 +--
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/refs/files-backend.c b/refs/files-backend.c
index 32663a999e..a3134d23ab 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -1676,13 +1676,12 @@ static int commit_ref_update(struct files_ref_store *refs,
 		 * check with HEAD only which should cover 99% of all usage
 		 * scenarios (even 100% of the default ones).
 		 */
-		struct object_id head_oid;
 		int head_flag;
 		const char *head_ref;
 
 		head_ref = refs_resolve_ref_unsafe(&refs->base, "HEAD",
 						   RESOLVE_REF_READING,
-						   head_oid.hash, &head_flag);
+						   NULL, &head_flag);
 		if (head_ref && (head_flag & REF_ISSYMREF) &&
 		    !strcmp(head_ref, lock->ref_name)) {
 			struct strbuf log_err = STRBUF_INIT;
diff --git a/worktree.c b/worktree.c
index 8aaeea0377..70015629dc 100644
--- a/worktree.c
+++ b/worktree.c
@@ -307,7 +307,6 @@ const struct worktree *find_shared_symref(const char *symref,
 	for (i = 0; worktrees[i]; i++) {
 		struct worktree *wt = worktrees[i];
 		const char *symref_target;
-		unsigned char sha1[20];
 		struct ref_store *refs;
 		int flags;
 
@@ -327,7 +326,7 @@ const struct worktree *find_shared_symref(const char *symref,
 
 		refs = get_worktree_ref_store(wt);
 		symref_target = refs_resolve_ref_unsafe(refs, symref, 0,
-							sha1, &flags);
+							NULL, &flags);
 		if ((flags & REF_ISSYMREF) && !strcmp(symref_target, target)) {
 			existing = wt;
 			break;
-- 
2.14.1

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 3/3] refs: pass NULL to resolve_ref_unsafe() if hash is not needed
  2017-09-23  9:41 [PATCH 1/3] refs: make sha1 output parameter of refs_resolve_ref_unsafe() optional René Scharfe
  2017-09-23  9:44 ` [PATCH 2/3] refs: pass NULL to refs_resolve_ref_unsafe() if hash is not needed René Scharfe
@ 2017-09-23  9:45 ` René Scharfe
  2017-09-24  1:26 ` [PATCH 1/3] refs: make sha1 output parameter of refs_resolve_ref_unsafe() optional Junio C Hamano
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: René Scharfe @ 2017-09-23  9:45 UTC (permalink / raw)
  To: Git List; +Cc: Junio C Hamano, Michael Haggerty

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>
---
 branch.c                    |  3 +--
 builtin/commit.c            |  3 +--
 builtin/log.c               |  3 +--
 builtin/receive-pack.c      |  3 +--
 builtin/remote.c            |  3 +--
 builtin/submodule--helper.c |  6 ++----
 builtin/symbolic-ref.c      |  3 +--
 http-backend.c              |  3 +--
 log-tree.c                  |  3 +--
 refs.c                      |  6 ++----
 remote.c                    | 12 ++++--------
 revision.c                  |  3 +--
 transport.c                 |  3 +--
 upload-pack.c               |  3 +--
 14 files changed, 19 insertions(+), 38 deletions(-)

diff --git a/branch.c b/branch.c
index 703ded69ca..4377ce2fb1 100644
--- a/branch.c
+++ b/branch.c
@@ -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."));
 	}
diff --git a/builtin/commit.c b/builtin/commit.c
index 58f9747c2f..39d5b7f6c7 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -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,
 	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
diff --git a/builtin/log.c b/builtin/log.c
index f8cccbc964..d81a09051e 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -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
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index 52c63ebfdc..65d89078ab 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -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))
diff --git a/builtin/remote.c b/builtin/remote.c
index 33ba739332..4f5cac96b0 100644
--- a/builtin/remote.c
+++ b/builtin/remote.c
@@ -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
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 818fe74f0a..ea49710893 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -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)
 		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");
diff --git a/builtin/symbolic-ref.c b/builtin/symbolic-ref.c
index df75cb9d4a..17aabaa679 100644
--- a/builtin/symbolic-ref.c
+++ b/builtin/symbolic-ref.c
@@ -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);
diff --git a/http-backend.c b/http-backend.c
index 8076b1d5e5..b8ce960a35 100644
--- a/http-backend.c
+++ b/http-backend.c
@@ -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));
diff --git a/log-tree.c b/log-tree.c
index 410ab4f02d..cea056234d 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -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
 		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;
 
diff --git a/refs.c b/refs.c
index 36439fdb54..97e33fdc7b 100644
--- a/refs.c
+++ b/refs.c
@@ -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 *
 {
 	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)
diff --git a/remote.c b/remote.c
index 4113090069..b220f0dfc6 100644
--- a/remote.c
+++ b/remote.c
@@ -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)
 
 	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)
 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,
 		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)
 
 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);
 }
diff --git a/revision.c b/revision.c
index f9a90d71d2..9582a727ca 100644
--- a/revision.c
+++ b/revision.c
@@ -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"));
 
diff --git a/transport.c b/transport.c
index d75ff0514d..fb8c01e57a 100644
--- a/transport.c
+++ b/transport.c
@@ -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,
 		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;
diff --git a/upload-pack.c b/upload-pack.c
index 7efff2fbfd..06d822aad2 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -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);
-- 
2.14.1

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/3] refs: make sha1 output parameter of refs_resolve_ref_unsafe() optional
  2017-09-23  9:41 [PATCH 1/3] refs: make sha1 output parameter of refs_resolve_ref_unsafe() optional René Scharfe
  2017-09-23  9:44 ` [PATCH 2/3] refs: pass NULL to refs_resolve_ref_unsafe() if hash is not needed René Scharfe
  2017-09-23  9:45 ` [PATCH 3/3] refs: pass NULL to resolve_ref_unsafe() " René Scharfe
@ 2017-09-24  1:26 ` Junio C Hamano
  2017-09-24 12:39   ` René Scharfe
  2017-10-01  7:28 ` [PATCH 4/3] refs: pass NULL to refs_resolve_refdup() if hash is not needed René Scharfe
  2017-10-01  7:29 ` [PATCH 5/3] refs: pass NULL to resolve_refdup() " René Scharfe
  4 siblings, 1 reply; 8+ messages in thread
From: Junio C Hamano @ 2017-09-24  1:26 UTC (permalink / raw)
  To: René Scharfe; +Cc: Git List, Michael Haggerty

René Scharfe <l.s.r@web.de> writes:

> Allow callers of refs_resolve_ref_unsafe() to pass NULL if they don't
> need the resolved hash value.  We already allow the same for the flags
> parameter.  This new leniency is inherited by the various wrappers like
> resolve_ref_unsafe().
>
> Signed-off-by: Rene Scharfe <l.s.r@web.de>
> ---

The patches all make sense, and I'd expect them to be something a
competent contributor would write after coming to this realization:
it seems that many many callers, when they have a ref that could be
a symbolic ref, want to learn (1) if it is a symref and (2) where it
points at, and nothing else, most notably they do not care what the
object pointed by the (symbolic) ref is.

I wonder if we want a dedicated helper for them (perhaps about a
dozen callers we have that fall into this pattern?) to call for the
exact purpose, implemented as a thin-wrapper around the
resolve_ref_unsafe() function, though.

Thanks.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/3] refs: make sha1 output parameter of refs_resolve_ref_unsafe() optional
  2017-09-24  1:26 ` [PATCH 1/3] refs: make sha1 output parameter of refs_resolve_ref_unsafe() optional Junio C Hamano
@ 2017-09-24 12:39   ` René Scharfe
  0 siblings, 0 replies; 8+ messages in thread
From: René Scharfe @ 2017-09-24 12:39 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Git List, Michael Haggerty

Am 24.09.2017 um 03:26 schrieb Junio C Hamano:
> I wonder if we want a dedicated helper for them (perhaps about a
> dozen callers we have that fall into this pattern?) to call for the
> exact purpose, implemented as a thin-wrapper around the
> resolve_ref_unsafe() function, though.

refs_resolve_ref_unsafe() effectively has seven wrappers already:

	resolve_ref_unsafe()
	refs_resolve_refdup()
	resolve_refdup()
	refs_read_ref_full()
	read_ref_full()
	read_ref()

	ref_exists()

The last one already supplies a dummy SHA1 buffer; for a handful of
the others we could add and use variants that do the same.  I feel
that this API would become a bit crowded, though.

René

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 4/3] refs: pass NULL to refs_resolve_refdup() if hash is not needed
  2017-09-23  9:41 [PATCH 1/3] refs: make sha1 output parameter of refs_resolve_ref_unsafe() optional René Scharfe
                   ` (2 preceding siblings ...)
  2017-09-24  1:26 ` [PATCH 1/3] refs: make sha1 output parameter of refs_resolve_ref_unsafe() optional Junio C Hamano
@ 2017-10-01  7:28 ` René Scharfe
  2017-10-01  7:29 ` [PATCH 5/3] refs: pass NULL to resolve_refdup() " René Scharfe
  4 siblings, 0 replies; 8+ messages in thread
From: René Scharfe @ 2017-10-01  7:28 UTC (permalink / raw)
  To: Git List; +Cc: Junio C Hamano, Michael Haggerty

This gets us rid of a write-only variable.

Signed-off-by: Rene Scharfe <l.s.r@web.de>
---
 refs/files-backend.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/refs/files-backend.c b/refs/files-backend.c
index fec77744b4..ed00ddab1a 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -2499,7 +2499,6 @@ static int files_transaction_prepare(struct ref_store *ref_store,
 	struct string_list affected_refnames = STRING_LIST_INIT_NODUP;
 	char *head_ref = NULL;
 	int head_type;
-	struct object_id head_oid;
 	struct files_transaction_backend_data *backend_data;
 	struct ref_transaction *packed_transaction = NULL;
 
@@ -2556,7 +2555,7 @@ static int files_transaction_prepare(struct ref_store *ref_store,
 	 */
 	head_ref = refs_resolve_refdup(ref_store, "HEAD",
 				       RESOLVE_REF_NO_RECURSE,
-				       head_oid.hash, &head_type);
+				       NULL, &head_type);
 
 	if (head_ref && !(head_type & REF_ISSYMREF)) {
 		FREE_AND_NULL(head_ref);
-- 
2.14.2


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 5/3] refs: pass NULL to resolve_refdup() if hash is not needed
  2017-09-23  9:41 [PATCH 1/3] refs: make sha1 output parameter of refs_resolve_ref_unsafe() optional René Scharfe
                   ` (3 preceding siblings ...)
  2017-10-01  7:28 ` [PATCH 4/3] refs: pass NULL to refs_resolve_refdup() if hash is not needed René Scharfe
@ 2017-10-01  7:29 ` René Scharfe
  2017-10-01  8:29   ` Junio C Hamano
  4 siblings, 1 reply; 8+ messages in thread
From: René Scharfe @ 2017-10-01  7:29 UTC (permalink / raw)
  To: Git List; +Cc: Junio C Hamano, Michael Haggerty

This allows us to get rid of several write-only variables.

Signed-off-by: Rene Scharfe <l.s.r@web.de>
---
 builtin/checkout.c     | 3 +--
 builtin/receive-pack.c | 3 +--
 ref-filter.c           | 7 ++-----
 reflog-walk.c          | 6 ++----
 transport.c            | 3 +--
 wt-status.c            | 4 +---
 6 files changed, 8 insertions(+), 18 deletions(-)

diff --git a/builtin/checkout.c b/builtin/checkout.c
index 3345a0d16f..10751585ea 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -1124,9 +1124,8 @@ static int checkout_branch(struct checkout_opts *opts,
 
 	if (new->path && !opts->force_detach && !opts->new_branch &&
 	    !opts->ignore_other_worktrees) {
-		struct object_id oid;
 		int flag;
-		char *head_ref = resolve_refdup("HEAD", 0, oid.hash, &flag);
+		char *head_ref = resolve_refdup("HEAD", 0, NULL, &flag);
 		if (head_ref &&
 		    (!(flag & REF_ISSYMREF) || strcmp(head_ref, new->path)))
 			die_if_checked_out(new->path, 1);
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index 29a0f3b75f..cc48767405 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -1458,7 +1458,6 @@ static void execute_commands(struct command *commands,
 {
 	struct check_connected_options opt = CHECK_CONNECTED_INIT;
 	struct command *cmd;
-	struct object_id oid;
 	struct iterate_data data;
 	struct async muxer;
 	int err_fd = 0;
@@ -1515,7 +1514,7 @@ static void execute_commands(struct command *commands,
 	check_aliased_updates(commands);
 
 	free(head_name_to_free);
-	head_name = head_name_to_free = resolve_refdup("HEAD", 0, oid.hash, NULL);
+	head_name = head_name_to_free = resolve_refdup("HEAD", 0, NULL, NULL);
 
 	if (use_atomic)
 		execute_commands_atomic(commands, si);
diff --git a/ref-filter.c b/ref-filter.c
index bc591f4f3d..55323620ab 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -295,9 +295,7 @@ static void if_atom_parser(const struct ref_format *format, struct used_atom *at
 
 static void head_atom_parser(const struct ref_format *format, struct used_atom *atom, const char *arg)
 {
-	struct object_id unused;
-
-	atom->u.head = resolve_refdup("HEAD", RESOLVE_REF_READING, unused.hash, NULL);
+	atom->u.head = resolve_refdup("HEAD", RESOLVE_REF_READING, NULL, NULL);
 }
 
 static struct {
@@ -1317,9 +1315,8 @@ static void populate_value(struct ref_array_item *ref)
 	ref->value = xcalloc(used_atom_cnt, sizeof(struct atom_value));
 
 	if (need_symref && (ref->flag & REF_ISSYMREF) && !ref->symref) {
-		struct object_id unused1;
 		ref->symref = resolve_refdup(ref->refname, RESOLVE_REF_READING,
-					     unused1.hash, NULL);
+					     NULL, NULL);
 		if (!ref->symref)
 			ref->symref = "";
 	}
diff --git a/reflog-walk.c b/reflog-walk.c
index 74ebe5148f..842b2f77dc 100644
--- a/reflog-walk.c
+++ b/reflog-walk.c
@@ -61,11 +61,10 @@ static struct complete_reflogs *read_complete_reflog(const char *ref)
 	reflogs->ref = xstrdup(ref);
 	for_each_reflog_ent(ref, read_one_reflog, reflogs);
 	if (reflogs->nr == 0) {
-		struct object_id oid;
 		const char *name;
 		void *name_to_free;
 		name = name_to_free = resolve_refdup(ref, RESOLVE_REF_READING,
-						     oid.hash, NULL);
+						     NULL, NULL);
 		if (name) {
 			for_each_reflog_ent(name, read_one_reflog, reflogs);
 			free(name_to_free);
@@ -151,9 +150,8 @@ int add_reflog_for_walk(struct reflog_walk_info *info,
 		reflogs = item->util;
 	else {
 		if (*branch == '\0') {
-			struct object_id oid;
 			free(branch);
-			branch = resolve_refdup("HEAD", 0, oid.hash, NULL);
+			branch = resolve_refdup("HEAD", 0, NULL, NULL);
 			if (!branch)
 				die ("No current branch");
 
diff --git a/transport.c b/transport.c
index fb8c01e57a..f1e2f61991 100644
--- a/transport.c
+++ b/transport.c
@@ -471,11 +471,10 @@ void transport_print_push_status(const char *dest, struct ref *refs,
 {
 	struct ref *ref;
 	int n = 0;
-	struct object_id head_oid;
 	char *head;
 	int summary_width = transport_summary_width(refs);
 
-	head = resolve_refdup("HEAD", RESOLVE_REF_READING, head_oid.hash, NULL);
+	head = resolve_refdup("HEAD", RESOLVE_REF_READING, NULL, NULL);
 
 	if (verbose) {
 		for (ref = refs; ref; ref = ref->next)
diff --git a/wt-status.c b/wt-status.c
index 6f730ee8f2..29bc64cc02 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -121,15 +121,13 @@ static void status_printf_more(struct wt_status *s, const char *color,
 
 void wt_status_prepare(struct wt_status *s)
 {
-	struct object_id oid;
-
 	memset(s, 0, sizeof(*s));
 	memcpy(s->color_palette, default_wt_status_colors,
 	       sizeof(default_wt_status_colors));
 	s->show_untracked_files = SHOW_NORMAL_UNTRACKED_FILES;
 	s->use_color = -1;
 	s->relative_paths = 1;
-	s->branch = resolve_refdup("HEAD", 0, oid.hash, NULL);
+	s->branch = resolve_refdup("HEAD", 0, NULL, NULL);
 	s->reference = "HEAD";
 	s->fp = stdout;
 	s->index_file = get_index_file();
-- 
2.14.2

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH 5/3] refs: pass NULL to resolve_refdup() if hash is not needed
  2017-10-01  7:29 ` [PATCH 5/3] refs: pass NULL to resolve_refdup() " René Scharfe
@ 2017-10-01  8:29   ` Junio C Hamano
  0 siblings, 0 replies; 8+ messages in thread
From: Junio C Hamano @ 2017-10-01  8:29 UTC (permalink / raw)
  To: René Scharfe; +Cc: Git List, Michael Haggerty

René Scharfe <l.s.r@web.de> writes:

> This allows us to get rid of several write-only variables.
>
> Signed-off-by: Rene Scharfe <l.s.r@web.de>
> ---
>  builtin/checkout.c     | 3 +--
>  builtin/receive-pack.c | 3 +--
>  ref-filter.c           | 7 ++-----
>  reflog-walk.c          | 6 ++----
>  transport.c            | 3 +--
>  wt-status.c            | 4 +---
>  6 files changed, 8 insertions(+), 18 deletions(-)

Both patches looked good to me.

It's a bit surprising that we care so much about where a symbolic
ref points at, but it is understandable from the list of files
affected.


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2017-10-01  8:29 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-23  9:41 [PATCH 1/3] refs: make sha1 output parameter of refs_resolve_ref_unsafe() optional René Scharfe
2017-09-23  9:44 ` [PATCH 2/3] refs: pass NULL to refs_resolve_ref_unsafe() if hash is not needed René Scharfe
2017-09-23  9:45 ` [PATCH 3/3] refs: pass NULL to resolve_ref_unsafe() " René Scharfe
2017-09-24  1:26 ` [PATCH 1/3] refs: make sha1 output parameter of refs_resolve_ref_unsafe() optional Junio C Hamano
2017-09-24 12:39   ` René Scharfe
2017-10-01  7:28 ` [PATCH 4/3] refs: pass NULL to refs_resolve_refdup() if hash is not needed René Scharfe
2017-10-01  7:29 ` [PATCH 5/3] refs: pass NULL to resolve_refdup() " René Scharfe
2017-10-01  8:29   ` Junio C Hamano

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).