git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH RFC] ref-filter: start using oid_object_info
@ 2018-05-14  9:59 Olga Telezhnaya
  2018-05-15  3:24 ` Junio C Hamano
  2018-05-18  8:19 ` [PATCH RFC v2 1/4] " Olga Telezhnaya
  0 siblings, 2 replies; 7+ messages in thread
From: Olga Telezhnaya @ 2018-05-14  9:59 UTC (permalink / raw)
  To: git

Start using oid_object_info_extended(). So, if info from this function
is enough, we do not need to get and parse whole object (as it was before).
It's good for 3 reasons:
1. Some Git commands potentially will work faster.
2. It's much easier to add support for objectsize:disk and deltabase.
   (I have plans to add this support further)
3. It's easier to move formatting from cat-file command to this logic
   (It pretends to be unified formatting logic in the end)

Signed-off-by: Olga Telezhnaia <olyatelezhnaya@gmail.com>
---
 ref-filter.c | 34 +++++++++++++++++++++++++++++++---
 ref-filter.h | 21 +++++++++++++++++++++
 2 files changed, 52 insertions(+), 3 deletions(-)

diff --git a/ref-filter.c b/ref-filter.c
index 39e2744c949bb..7c4693ed084bb 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -100,6 +100,7 @@ static struct used_atom {
 	} u;
 } *used_atom;
 static int used_atom_cnt, need_tagged, need_symref;
+static struct expand_data format_data;
 
 /*
  * Expand string, append it to strbuf *sb, then return error code ret.
@@ -267,6 +268,22 @@ static int contents_atom_parser(const struct ref_format *format, struct used_ato
 	return 0;
 }
 
+static int objecttype_atom_parser(const struct ref_format *format, struct used_atom *atom,
+				  const char *arg, struct strbuf *unused_err)
+{
+	format_data.use_data = 1;
+	format_data.info.typep = &format_data.type;
+	return 0;
+}
+
+static int objectsize_atom_parser(const struct ref_format *format, struct used_atom *atom,
+				  const char *arg, struct strbuf *unused_err)
+{
+	format_data.use_data = 1;
+	format_data.info.sizep = &format_data.size;
+	return 0;
+}
+
 static int objectname_atom_parser(const struct ref_format *format, struct used_atom *atom,
 				  const char *arg, struct strbuf *err)
 {
@@ -383,9 +400,9 @@ static struct {
 	int (*parser)(const struct ref_format *format, struct used_atom *atom,
 		      const char *arg, struct strbuf *err);
 } valid_atom[] = {
-	{ "refname" , FIELD_STR, refname_atom_parser },
-	{ "objecttype" },
-	{ "objectsize", FIELD_ULONG },
+	{ "refname", FIELD_STR, refname_atom_parser },
+	{ "objecttype", FIELD_STR, objecttype_atom_parser },
+	{ "objectsize", FIELD_ULONG, objectsize_atom_parser },
 	{ "objectname", FIELD_STR, objectname_atom_parser },
 	{ "tree" },
 	{ "parent" },
@@ -1536,6 +1553,13 @@ static int populate_value(struct ref_array_item *ref, struct strbuf *err)
 			continue;
 		} else if (!deref && grab_objectname(name, &ref->objectname, v, atom)) {
 			continue;
+		} else if (!deref && !strcmp(name, "objecttype")) {
+			v->s = type_name(format_data.type);
+			continue;
+		} else if (!deref && !strcmp(name, "objectsize")) {
+			v->value = format_data.size;
+			v->s = xstrfmt("%lu", format_data.size);
+			continue;
 		} else if (!strcmp(name, "HEAD")) {
 			if (atom->u.head && !strcmp(ref->refname, atom->u.head))
 				v->s = "*";
@@ -2226,6 +2250,10 @@ int format_ref_array_item(struct ref_array_item *info,
 {
 	const char *cp, *sp, *ep;
 	struct ref_formatting_state state = REF_FORMATTING_STATE_INIT;
+	format_data.oid = info->objectname;
+	if (format_data.use_data && oid_object_info_extended(&format_data.oid, &format_data.info,
+							     OBJECT_INFO_LOOKUP_REPLACE) < 0)
+		return strbuf_addf_ret(error_buf, -1, "format: could not get object info");
 
 	state.quote_style = format->quote_style;
 	push_stack_element(&state.stack);
diff --git a/ref-filter.h b/ref-filter.h
index 85c8ebc3b904e..857e8c5318a8f 100644
--- a/ref-filter.h
+++ b/ref-filter.h
@@ -85,6 +85,27 @@ struct ref_format {
 	int need_color_reset_at_eol;
 };
 
+struct expand_data {
+	struct object_id oid;
+	enum object_type type;
+	unsigned long size;
+	off_t disk_size;
+	struct object_id delta_base_oid;
+
+	/*
+	 * This object_info is set up to be passed to oid_object_info_extended.
+	 * It will point to the data elements above, so you can retrieve
+	 * the response from there.
+	 */
+	struct object_info info;
+
+	/*
+	 * This flag will be true if the requested format and options
+	 * require us to call oid_object_info_extended.
+	 */
+	unsigned use_data : 1;
+};
+
 #define REF_FORMAT_INIT { NULL, 0, -1 }
 
 /*  Macros for checking --merged and --no-merged options */

--
https://github.com/git/git/pull/493

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

end of thread, other threads:[~2018-05-18  9:11 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-14  9:59 [PATCH RFC] ref-filter: start using oid_object_info Olga Telezhnaya
2018-05-15  3:24 ` Junio C Hamano
2018-05-15  3:53   ` Junio C Hamano
2018-05-18  8:19 ` [PATCH RFC v2 1/4] " Olga Telezhnaya
2018-05-18  8:19   ` [PATCH RFC v2 3/4] ref-filter: add tests for objectsize:disk Olga Telezhnaya
2018-05-18  8:19   ` [PATCH RFC v2 2/4] ref-filter: add objectsize:disk formatting option Olga Telezhnaya
2018-05-18  8:19   ` [PATCH RFC v2 4/4] ref-filter: add deltabase " Olga Telezhnaya

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).