git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Olga Telezhnaya <olyatelezhnaya@gmail.com>
To: git@vger.kernel.org
Subject: [PATCH RFC v2 2/4] ref-filter: add objectsize:disk formatting option
Date: Fri, 18 May 2018 08:19:09 +0000	[thread overview]
Message-ID: <010201637254c9fc-6c6958f9-5b32-44df-abbe-8455d4ca9535-000000@eu-west-1.amazonses.com> (raw)
In-Reply-To: <010201637254c969-a346030e-0b75-41ad-8ef3-2ac7e04ba4fb-000000@eu-west-1.amazonses.com>

Add %(objectsize:disk) support. It is still not working for deref:
I am thinking how to support it in a more elegant way.

Signed-off-by: Olga Telezhnaia <olyatelezhnaya@gmail.com>
---
 ref-filter.c | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/ref-filter.c b/ref-filter.c
index 4008351553391..c00de58455301 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -277,10 +277,15 @@ static int objecttype_atom_parser(const struct ref_format *format, struct used_a
 }
 
 static int objectsize_atom_parser(const struct ref_format *format, struct used_atom *atom,
-				  const char *arg, struct strbuf *unused_err)
+				  const char *arg, struct strbuf *err)
 {
+	if (!arg)
+		oi_data.info.sizep = &oi_data.size;
+	else if (!strcmp(arg, "disk"))
+		oi_data.info.disk_sizep = &oi_data.disk_size;
+	else
+		return strbuf_addf_ret(err, -1, _("unrecognized %%(objectsize) argument: %s"), arg);
 	oi_data.use_data = 1;
-	oi_data.info.sizep = &oi_data.size;
 	return 0;
 }
 
@@ -1557,9 +1562,15 @@ static int populate_value(struct ref_array_item *ref, struct strbuf *err)
 		} else if (!deref && !strcmp(name, "objecttype") && oi_data.use_data) {
 			v->s = type_name(oi_data.type);
 			continue;
-		} else if (!deref && !strcmp(name, "objectsize") && oi_data.use_data) {
-			v->value = oi_data.size;
-			v->s = xstrfmt("%lu", oi_data.size);
+		} else if (!deref && starts_with(name, "objectsize") && oi_data.use_data) {
+			if (!strcmp(name, "objectsize")) {
+				v->value = oi_data.size;
+				v->s = xstrfmt("%lu", oi_data.size);
+			} else {
+				/* It can be only objectsize:disk, we checked it in parser */
+				v->value = oi_data.disk_size;
+				v->s = xstrfmt("%lu", oi_data.disk_size);
+			}
 			continue;
 		} else if (!strcmp(name, "HEAD")) {
 			if (atom->u.head && !strcmp(ref->refname, atom->u.head))

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

  parent reply	other threads:[~2018-05-18  9:11 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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   ` Olga Telezhnaya [this message]
2018-05-18  8:19   ` [PATCH RFC v2 4/4] ref-filter: add deltabase formatting option Olga Telezhnaya

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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=010201637254c9fc-6c6958f9-5b32-44df-abbe-8455d4ca9535-000000@eu-west-1.amazonses.com \
    --to=olyatelezhnaya@gmail.com \
    --cc=git@vger.kernel.org \
    /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.
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).