]> git.ipfire.org Git - thirdparty/git.git/commit
hex: add and use strbuf_add_oid_hex()
authorRené Scharfe <l.s.r@web.de>
Wed, 13 May 2026 15:49:11 +0000 (17:49 +0200)
committerJunio C Hamano <gitster@pobox.com>
Thu, 14 May 2026 06:59:25 +0000 (15:59 +0900)
commit63621bcbba81a131794d510bcedfa08d9318219c
treefd32a7b8ed8988f72d9876c9239044fe451ecd2f
parent94f057755b7941b321fd11fec1b2e3ca5313a4e0
hex: add and use strbuf_add_oid_hex()

Add a function for adding the full hexadecimal hash value of an object
ID to a strbuf.  It's thread-safe and slightly more efficient than using
strbuf_addstr() with oid_to_hex() because it doesn't have to determine
the length of the string or copy it from the intermediate static buffer.

Add and apply a semantic patch to use it throughout the code base.

I get a tiny speedup for git log showing a single hash per commit:

Benchmark 1: ./git_main log --format=%H
  Time (mean ± σ):      91.2 ms ±   0.7 ms    [User: 51.9 ms, System: 38.6 ms]
  Range (min … max):    89.8 ms …  92.6 ms    31 runs

Benchmark 2: ./git log --format=%H
  Time (mean ± σ):      90.5 ms ±   0.7 ms    [User: 51.0 ms, System: 38.8 ms]
  Range (min … max):    89.2 ms …  92.3 ms    32 runs

Summary
  ./git log --format=%H ran
    1.01 ± 0.01 times faster than ./git_main log --format=%H

Signed-off-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
14 files changed:
bisect.c
builtin/bisect.c
builtin/cat-file.c
builtin/replace.c
convert.c
fsck.c
hex.c
hex.h
pretty.c
refs.c
sequencer.c
shallow.c
tools/coccinelle/strbuf.cocci
transport-helper.c