All of lore.kernel.org
 help / color / mirror / Atom feed
From: "ZheNing Hu via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>, Jeff King <peff@peff.net>,
	ZheNing Hu <adlternative@gmail.com>,
	ZheNing Hu <adlternative@gmail.com>
Subject: [PATCH 1/4] refs: let repo_dwim_ref() learn get symref itself and ref flags
Date: Mon, 20 Sep 2021 07:37:53 +0000	[thread overview]
Message-ID: <22b69757e33d310e78232dbe520a1995486ec918.1632123476.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.1042.git.1632123476.gitgitgadget@gmail.com>

From: ZheNing Hu <adlternative@gmail.com>

expand_ref() can use to resolve a ref to its fullname, A symref will
also be resolved to the fullref name it refers to. But sometimes we
want get symref itself. So add a need_symref parameter to
repo_dwim_ref() and expand_ref(), which can help us get symref its
fullref name. At the same time, we add ref_flags parameter to
expand_ref() and repo_dwim_ref(), when it is set, it can get the
ref's flag from refs_resolve_ref_unsafe(), which can help us provide
ref's flags for interfaces like pretty_print_ref() later.

Signed-off-by: ZheNing Hu <adlternative@gmail.com>
---
 object-name.c |  6 +++---
 refs.c        | 15 ++++++++++-----
 refs.h        |  8 +++++---
 upload-pack.c |  2 +-
 4 files changed, 19 insertions(+), 12 deletions(-)

diff --git a/object-name.c b/object-name.c
index fdff4601b2c..a8cb1d6ab14 100644
--- a/object-name.c
+++ b/object-name.c
@@ -803,7 +803,7 @@ static int get_oid_basic(struct repository *r, const char *str, int len,
 
 	if (len == r->hash_algo->hexsz && !get_oid_hex(str, oid)) {
 		if (warn_ambiguous_refs && warn_on_object_refname_ambiguity) {
-			refs_found = repo_dwim_ref(r, str, len, &tmp_oid, &real_ref, 0);
+			refs_found = repo_dwim_ref(r, str, len, &tmp_oid, &real_ref, 0, 0, 0);
 			if (refs_found > 0) {
 				warning(warn_msg, len, str);
 				if (advice_enabled(ADVICE_OBJECT_NAME_WARNING))
@@ -854,11 +854,11 @@ static int get_oid_basic(struct repository *r, const char *str, int len,
 
 	if (!len && reflog_len)
 		/* allow "@{...}" to mean the current branch reflog */
-		refs_found = repo_dwim_ref(r, "HEAD", 4, oid, &real_ref, 0);
+		refs_found = repo_dwim_ref(r, "HEAD", 4, oid, &real_ref, 0, 0, 0);
 	else if (reflog_len)
 		refs_found = repo_dwim_log(r, str, len, oid, &real_ref);
 	else
-		refs_found = repo_dwim_ref(r, str, len, oid, &real_ref, 0);
+		refs_found = repo_dwim_ref(r, str, len, oid, &real_ref, 0, 0, 0);
 
 	if (!refs_found)
 		return -1;
diff --git a/refs.c b/refs.c
index 8b9f7c3a80a..67618a09992 100644
--- a/refs.c
+++ b/refs.c
@@ -637,17 +637,19 @@ static char *substitute_branch_name(struct repository *r,
 }
 
 int repo_dwim_ref(struct repository *r, const char *str, int len,
-		  struct object_id *oid, char **ref, int nonfatal_dangling_mark)
+		  struct object_id *oid, char **ref, int nonfatal_dangling_mark,
+		  int *ref_flags, int need_symref)
 {
 	char *last_branch = substitute_branch_name(r, &str, &len,
 						   nonfatal_dangling_mark);
-	int   refs_found  = expand_ref(r, str, len, oid, ref);
+	int   refs_found  = expand_ref(r, str, len, oid, ref, ref_flags, need_symref);
 	free(last_branch);
 	return refs_found;
 }
 
 int expand_ref(struct repository *repo, const char *str, int len,
-	       struct object_id *oid, char **ref)
+	       struct object_id *oid, char **ref, int *ref_flags,
+	       int need_symref)
 {
 	const char **p, *r;
 	int refs_found = 0;
@@ -666,8 +668,11 @@ int expand_ref(struct repository *repo, const char *str, int len,
 					    fullref.buf, RESOLVE_REF_READING,
 					    this_result, &flag);
 		if (r) {
-			if (!refs_found++)
-				*ref = xstrdup(r);
+			if (!refs_found++) {
+				*ref = xstrdup(need_symref ? fullref.buf : r);
+				if (ref_flags)
+					*ref_flags = flag;
+			}
 			if (!warn_ambiguous_refs)
 				break;
 		} else if ((flag & REF_ISSYMREF) && strcmp(fullref.buf, "HEAD")) {
diff --git a/refs.h b/refs.h
index 48970dfc7e0..1f977bdb188 100644
--- a/refs.h
+++ b/refs.h
@@ -152,15 +152,17 @@ int refname_match(const char *abbrev_name, const char *full_name);
 struct strvec;
 void expand_ref_prefix(struct strvec *prefixes, const char *prefix);
 
-int expand_ref(struct repository *r, const char *str, int len, struct object_id *oid, char **ref);
+int expand_ref(struct repository *r, const char *str, int len, struct object_id *oid, char **ref,
+	       int *ref_flags, int need_symref);
 int repo_dwim_ref(struct repository *r, const char *str, int len,
-		  struct object_id *oid, char **ref, int nonfatal_dangling_mark);
+		  struct object_id *oid, char **ref, int nonfatal_dangling_mark,
+		  int *ref_flags, int need_symref);
 int repo_dwim_log(struct repository *r, const char *str, int len, struct object_id *oid, char **ref);
 static inline int dwim_ref(const char *str, int len, struct object_id *oid,
 			   char **ref, int nonfatal_dangling_mark)
 {
 	return repo_dwim_ref(the_repository, str, len, oid, ref,
-			     nonfatal_dangling_mark);
+			     nonfatal_dangling_mark, 0, 0);
 }
 int dwim_log(const char *str, int len, struct object_id *oid, char **ref);
 
diff --git a/upload-pack.c b/upload-pack.c
index 6ce07231d3d..dfbdd6d9466 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -975,7 +975,7 @@ static int process_deepen_not(const char *line, struct string_list *deepen_not,
 	if (skip_prefix(line, "deepen-not ", &arg)) {
 		char *ref = NULL;
 		struct object_id oid;
-		if (expand_ref(the_repository, arg, strlen(arg), &oid, &ref) != 1)
+		if (expand_ref(the_repository, arg, strlen(arg), &oid, &ref, 0, 0) != 1)
 			die("git upload-pack: ambiguous deepen-not: %s", line);
 		string_list_append(deepen_not, ref);
 		free(ref);
-- 
gitgitgadget


  reply	other threads:[~2021-09-20  7:38 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-20  7:37 [PATCH 0/4] ref-filter: fix %(symref) for pretty_print_ref() ZheNing Hu via GitGitGadget
2021-09-20  7:37 ` ZheNing Hu via GitGitGadget [this message]
2021-09-20  7:37 ` [PATCH 2/4] ref-filter: provide ref_flags to pretty_print_ref() ZheNing Hu via GitGitGadget
2021-09-20  7:37 ` [PATCH 3/4] verify_tag: use repo_dwim_ref() to get ref fullname and ref_flags ZheNing Hu via GitGitGadget
2021-09-20  7:37 ` [PATCH 4/4] ref-filter: let tag verify use %(refname:lstrip=2) by default ZheNing Hu via GitGitGadget

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=22b69757e33d310e78232dbe520a1995486ec918.1632123476.git.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=adlternative@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=peff@peff.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.