git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Taylor Blau <me@ttaylorr.com>
Cc: "René Scharfe" <l.s.r@web.de>, "Git Mailing List" <git@vger.kernel.org>
Subject: Re: [PATCH] fast-export: factor out print_oid()
Date: Thu, 13 Aug 2020 11:19:58 -0700	[thread overview]
Message-ID: <xmqqmu2y2ysx.fsf@gitster.c.googlers.com> (raw)
In-Reply-To: <20200813151856.GE2244@syl.lan> (Taylor Blau's message of "Thu, 13 Aug 2020 11:18:56 -0400")

Taylor Blau <me@ttaylorr.com> writes:

>> +static void print_oid(const struct object_id *oid, int anonymize)
>> +{
>> +	const char *oid_hex = oid_to_hex(oid);
>> +	if (anonymize)
>> +		oid_hex = anonymize_oid(oid_hex);
>> +	fputs(oid_hex, stdout);
>> +}
>> +
>
> The fact that this calls fputs makes this patch (in my own opinion)
> noisier than it needs to be. This is because of all of the factoring out
> of the other printfs. I'd expect that this looks something more like:
>
>   -				       anonymize ?
>   -				       anonymize_oid(oid_to_hex(&spec->oid)) :
>   -				       oid_to_hex(&spec->oid));
>   +				       anonymize_oid(anonymize, &spec->oid));
>
> without moving around all of the other printf code.
> ...
> So, I guess what I'm trying to say is that this patch doesn't look
> wrong, other than that it seems more invasive than I would have expected
> it to be.

Yes, that matches my knee-jerk reaction.  I also shared Peff's
reaction that the code to generate the message is now even more
fragmented into pieces.

Just for comparison purposes, I tried to fold anonymize_oid()'s body
into René's print_oid() and adjusted the calling sites, which did
not look too bad.

So, I dunno.

 builtin/fast-export.c | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/builtin/fast-export.c b/builtin/fast-export.c
index 9f37895d4c..bef2c01bd8 100644
--- a/builtin/fast-export.c
+++ b/builtin/fast-export.c
@@ -413,11 +413,16 @@ static char *generate_fake_oid(void *data)
 	return hash_to_hex_algop_r(hex, out, the_hash_algo);
 }
 
-static const char *anonymize_oid(const char *oid_hex)
+static const char *anonymize_oid(const struct object_id *oid, int anonymize)
 {
-	static struct hashmap objs;
-	size_t len = strlen(oid_hex);
-	return anonymize_str(&objs, generate_fake_oid, oid_hex, len, NULL);
+	const char *oid_hex = oid_to_hex(oid);
+	if (anonymize) {
+		static struct hashmap objs;
+		size_t len = strlen(oid_hex);
+		return anonymize_str(&objs, generate_fake_oid, oid_hex, len, NULL);
+	} else {
+		return oid_hex;
+	}
 }
 
 static void show_filemodify(struct diff_queue_struct *q,
@@ -476,9 +481,7 @@ static void show_filemodify(struct diff_queue_struct *q,
 			 */
 			if (no_data || S_ISGITLINK(spec->mode))
 				printf("M %06o %s ", spec->mode,
-				       anonymize ?
-				       anonymize_oid(oid_to_hex(&spec->oid)) :
-				       oid_to_hex(&spec->oid));
+				       anonymize_oid(&spec->oid, anonymize));
 			else {
 				struct object *object = lookup_object(the_repository,
 								      &spec->oid);
@@ -726,10 +729,7 @@ static void handle_commit(struct commit *commit, struct rev_info *rev,
 		if (mark)
 			printf(":%d\n", mark);
 		else
-			printf("%s\n",
-			       anonymize ?
-			       anonymize_oid(oid_to_hex(&obj->oid)) :
-			       oid_to_hex(&obj->oid));
+			printf("%s\n", anonymize_oid(&obj->oid, anonymize));
 		i++;
 	}
 

      parent reply	other threads:[~2020-08-13 18:20 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-13 11:11 [PATCH] fast-export: factor out print_oid() René Scharfe
2020-08-13 11:58 ` Jeff King
2020-08-13 17:17   ` René Scharfe
2020-08-13 15:18 ` Taylor Blau
2020-08-13 17:17   ` René Scharfe
2020-08-13 17:25     ` Jeff King
2020-08-15  7:14       ` René Scharfe
2020-08-17 22:08         ` Jeff King
2020-08-17 22:53           ` Junio C Hamano
2020-08-13 18:19   ` Junio C Hamano [this message]

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=xmqqmu2y2ysx.fsf@gitster.c.googlers.com \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=l.s.r@web.de \
    --cc=me@ttaylorr.com \
    /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 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 NNTP newsgroup(s).