git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] patch-id: use oid_to_hex() to print multiple object IDs
@ 2019-12-07 19:16 René Scharfe
  2019-12-09  2:06 ` brian m. carlson
  0 siblings, 1 reply; 2+ messages in thread
From: René Scharfe @ 2019-12-07 19:16 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Junio C Hamano, brian m. carlson

flush_current_id() prints the hexadecimal representation of two object
IDs.  When the code was added in f97672225b (Add "git-patch-id" program
to generate patch ID's., 2005-06-23), sha1_to_hex() had only a single
internal static buffer, so the result of one invocation had to be stored
in a local buffer.

Since dcb3450fd8 (sha1_to_hex() usage cleanup, 2006-05-03) it rotates
through four buffers, which allows to print up to four object IDs at the
same time.  1a876a69af6 (patch-id: convert to use struct object_id,
2015-03-13) replaced sha1_to_hex() with oid_to_hex(), which has the same
feature.  Use it to simplify the code.

Signed-off-by: René Scharfe <l.s.r@web.de>
---
 builtin/patch-id.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/builtin/patch-id.c b/builtin/patch-id.c
index 3059e525b8..822ffff51f 100644
--- a/builtin/patch-id.c
+++ b/builtin/patch-id.c
@@ -5,13 +5,8 @@

 static void flush_current_id(int patchlen, struct object_id *id, struct object_id *result)
 {
-	char name[GIT_MAX_HEXSZ + 1];
-
-	if (!patchlen)
-		return;
-
-	memcpy(name, oid_to_hex(id), the_hash_algo->hexsz + 1);
-	printf("%s %s\n", oid_to_hex(result), name);
+	if (patchlen)
+		printf("%s %s\n", oid_to_hex(result), oid_to_hex(id));
 }

 static int remove_space(char *line)
--
2.24.0

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

* Re: [PATCH] patch-id: use oid_to_hex() to print multiple object IDs
  2019-12-07 19:16 [PATCH] patch-id: use oid_to_hex() to print multiple object IDs René Scharfe
@ 2019-12-09  2:06 ` brian m. carlson
  0 siblings, 0 replies; 2+ messages in thread
From: brian m. carlson @ 2019-12-09  2:06 UTC (permalink / raw)
  To: René Scharfe; +Cc: Git Mailing List, Junio C Hamano

[-- Attachment #1: Type: text/plain, Size: 796 bytes --]

On 2019-12-07 at 19:16:51, René Scharfe wrote:
> diff --git a/builtin/patch-id.c b/builtin/patch-id.c
> index 3059e525b8..822ffff51f 100644
> --- a/builtin/patch-id.c
> +++ b/builtin/patch-id.c
> @@ -5,13 +5,8 @@
> 
>  static void flush_current_id(int patchlen, struct object_id *id, struct object_id *result)
>  {
> -	char name[GIT_MAX_HEXSZ + 1];
> -
> -	if (!patchlen)
> -		return;
> -
> -	memcpy(name, oid_to_hex(id), the_hash_algo->hexsz + 1);
> -	printf("%s %s\n", oid_to_hex(result), name);
> +	if (patchlen)
> +		printf("%s %s\n", oid_to_hex(result), oid_to_hex(id));
>  }
> 
>  static int remove_space(char *line)

This seems like a nice cleanup to me.  Thanks for sending the patch.
-- 
brian m. carlson: Houston, Texas, US
OpenPGP: https://keybase.io/bk2204

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 868 bytes --]

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

end of thread, other threads:[~2019-12-09  2:06 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-07 19:16 [PATCH] patch-id: use oid_to_hex() to print multiple object IDs René Scharfe
2019-12-09  2:06 ` brian m. carlson

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