git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / mirror / code / Atom feed
* [PATCH] fast-export: factor out print_oid()
@ 2020-08-13 11:11 René Scharfe
  2020-08-13 11:58 ` Jeff King
  2020-08-13 15:18 ` Taylor Blau
  0 siblings, 2 replies; 10+ messages in thread
From: René Scharfe @ 2020-08-13 11:11 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Junio C Hamano

Simplify the output code by splitting it up and reducing duplication.
Reuse the logic for printing object IDs -- anonymized if needed -- by
moving it to its own function, print_oid().

Signed-off-by: René Scharfe <l.s.r@web.de>
---
 builtin/fast-export.c | 26 +++++++++++++++-----------
 1 file changed, 15 insertions(+), 11 deletions(-)

diff --git a/builtin/fast-export.c b/builtin/fast-export.c
index 9f37895d4cf..49bb50634ab 100644
--- a/builtin/fast-export.c
+++ b/builtin/fast-export.c
@@ -420,6 +420,14 @@ static const char *anonymize_oid(const char *oid_hex)
 	return anonymize_str(&objs, generate_fake_oid, oid_hex, len, NULL);
 }

+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);
+}
+
 static void show_filemodify(struct diff_queue_struct *q,
 			    struct diff_options *options, void *data)
 {
@@ -470,21 +478,19 @@ static void show_filemodify(struct diff_queue_struct *q,
 		case DIFF_STATUS_TYPE_CHANGED:
 		case DIFF_STATUS_MODIFIED:
 		case DIFF_STATUS_ADDED:
+			printf("M %06o ", spec->mode);
 			/*
 			 * Links refer to objects in another repositories;
 			 * output the SHA-1 verbatim.
 			 */
 			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));
+				print_oid(&spec->oid, anonymize);
 			else {
 				struct object *object = lookup_object(the_repository,
 								      &spec->oid);
-				printf("M %06o :%d ", spec->mode,
-				       get_object_mark(object));
+				printf(":%d", get_object_mark(object));
 			}
+			putchar(' ');
 			print_path(spec->path);
 			string_list_insert(changed, spec->path);
 			putchar('\n');
@@ -724,12 +730,10 @@ static void handle_commit(struct commit *commit, struct rev_info *rev,
 		else
 			printf("merge ");
 		if (mark)
-			printf(":%d\n", mark);
+			printf(":%d", mark);
 		else
-			printf("%s\n",
-			       anonymize ?
-			       anonymize_oid(oid_to_hex(&obj->oid)) :
-			       oid_to_hex(&obj->oid));
+			print_oid(&obj->oid, anonymize);
+		putchar('\n');
 		i++;
 	}

--
2.28.0

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

end of thread, other threads:[~2020-08-17 22:53 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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

Code repositories for project(s) associated with this 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).