[PATCH 2/4] ref-filter: provide ref_flags to pretty_print_ref()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: ZheNing Hu <adlternative@xxxxxxxxx>

pretty_print_ref() creates a ref_item through new_ref_array_item(),
but such ref_item does not set its flag member, this means that %(symref)
will not be processed in populate_value().

So provide ref_flags parameter to pretty_print_ref() and verify_tag().
pretty_print_ref() has two callers: cmd_verify_tag(), verify_tag(),
let for_each_tag_name() use read_ref_full() instread of read_ref() to
generate the ref_flags and pass to pretty_print_ref(); However,
cmd_verify_tag() needs to be modified later to support providing ref_flags
to pretty_print_ref().

At the same time, let verify_tag() pass "ref" instread of "name" to
gpg_verify_tag() and pretty_print_ref(), which can help pretty_print_ref
get fullref name.

Signed-off-by: ZheNing Hu <adlternative@xxxxxxxxx>
---
 builtin/tag.c        | 15 ++++++++-------
 builtin/verify-tag.c |  2 +-
 ref-filter.c         |  3 ++-
 ref-filter.h         |  2 +-
 4 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/builtin/tag.c b/builtin/tag.c
index 065b6bf093e..ce5678d179f 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -83,7 +83,7 @@ static int list_tags(struct ref_filter *filter, struct ref_sorting *sorting,
 }
 
 typedef int (*each_tag_name_fn)(const char *name, const char *ref,
-				const struct object_id *oid, void *cb_data);
+				const struct object_id *oid, void *cb_data, int ref_flags);
 
 static int for_each_tag_name(const char **argv, each_tag_name_fn fn,
 			     void *cb_data)
@@ -92,16 +92,17 @@ static int for_each_tag_name(const char **argv, each_tag_name_fn fn,
 	struct strbuf ref = STRBUF_INIT;
 	int had_error = 0;
 	struct object_id oid;
+	int ref_flags;
 
 	for (p = argv; *p; p++) {
 		strbuf_reset(&ref);
 		strbuf_addf(&ref, "refs/tags/%s", *p);
-		if (read_ref(ref.buf, &oid)) {
+		if (read_ref_full(ref.buf, RESOLVE_REF_READING, &oid, &ref_flags)) {
 			error(_("tag '%s' not found."), *p);
 			had_error = 1;
 			continue;
 		}
-		if (fn(*p, ref.buf, &oid, cb_data))
+		if (fn(*p, ref.buf, &oid, cb_data, ref_flags))
 			had_error = 1;
 	}
 	strbuf_release(&ref);
@@ -109,7 +110,7 @@ static int for_each_tag_name(const char **argv, each_tag_name_fn fn,
 }
 
 static int collect_tags(const char *name, const char *ref,
-			const struct object_id *oid, void *cb_data)
+			const struct object_id *oid, void *cb_data, int unused_flags)
 {
 	struct string_list *ref_list = cb_data;
 
@@ -143,7 +144,7 @@ static int delete_tags(const char **argv)
 }
 
 static int verify_tag(const char *name, const char *ref,
-		      const struct object_id *oid, void *cb_data)
+		      const struct object_id *oid, void *cb_data, int ref_flags)
 {
 	int flags;
 	struct ref_format *format = cb_data;
@@ -152,11 +153,11 @@ static int verify_tag(const char *name, const char *ref,
 	if (format->format)
 		flags = GPG_VERIFY_OMIT_STATUS;
 
-	if (gpg_verify_tag(oid, name, flags))
+	if (gpg_verify_tag(oid, ref, flags))
 		return -1;
 
 	if (format->format)
-		pretty_print_ref(name, oid, format);
+		pretty_print_ref(ref, oid, format, ref_flags);
 
 	return 0;
 }
diff --git a/builtin/verify-tag.c b/builtin/verify-tag.c
index f45136a06ba..403f2080efa 100644
--- a/builtin/verify-tag.c
+++ b/builtin/verify-tag.c
@@ -71,7 +71,7 @@ int cmd_verify_tag(int argc, const char **argv, const char *prefix)
 		}
 
 		if (format.format)
-			pretty_print_ref(name, &oid, &format);
+			pretty_print_ref(name, &oid, &format, 0);
 	}
 	return had_error;
 }
diff --git a/ref-filter.c b/ref-filter.c
index 93ce2a6ef2e..6c51ef25136 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -2632,7 +2632,7 @@ int format_ref_array_item(struct ref_array_item *info,
 }
 
 void pretty_print_ref(const char *name, const struct object_id *oid,
-		      struct ref_format *format)
+		      struct ref_format *format, int ref_flags)
 {
 	struct ref_array_item *ref_item;
 	struct strbuf output = STRBUF_INIT;
@@ -2640,6 +2640,7 @@ void pretty_print_ref(const char *name, const struct object_id *oid,
 
 	ref_item = new_ref_array_item(name, oid);
 	ref_item->kind = ref_kind_from_refname(name);
+	ref_item->flag = ref_flags;
 	if (format_ref_array_item(ref_item, format, &output, &err))
 		die("%s", err.buf);
 	fwrite(output.buf, 1, output.len, stdout);
diff --git a/ref-filter.h b/ref-filter.h
index c15dee8d6b9..edd9a3b6652 100644
--- a/ref-filter.h
+++ b/ref-filter.h
@@ -140,7 +140,7 @@ void setup_ref_filter_porcelain_msg(void);
  * name must be a fully qualified refname.
  */
 void pretty_print_ref(const char *name, const struct object_id *oid,
-		      struct ref_format *format);
+		      struct ref_format *format, int ref_flags);
 
 /*
  * Push a single ref onto the array; this can be used to construct your own
-- 
gitgitgadget




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux