<feed xmlns='http://www.w3.org/2005/Atom'>
<title>git/hex.c, branch v2.35.2</title>
<subtitle>Mirror of https://git.kernel.org/pub/scm/git/git.git/
</subtitle>
<id>https://git.shady.money/git/atom?h=v2.35.2</id>
<link rel='self' href='https://git.shady.money/git/atom?h=v2.35.2'/>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/'/>
<updated>2021-04-27T07:31:39Z</updated>
<entry>
<title>hex: print objects using the hash algorithm member</title>
<updated>2021-04-27T07:31:39Z</updated>
<author>
<name>brian m. carlson</name>
<email>sandals@crustytoothpaste.net</email>
</author>
<published>2021-04-26T01:03:01Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=3dd71461e25b4cc7ea2a2d8deef1c0486bb32580'/>
<id>urn:sha1:3dd71461e25b4cc7ea2a2d8deef1c0486bb32580</id>
<content type='text'>
Now that all code paths correctly set the hash algorithm member of
struct object_id, write an object's hex representation using the hash
algorithm member embedded in it.

Signed-off-by: brian m. carlson &lt;sandals@crustytoothpaste.net&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>hex: default to the_hash_algo on zero algorithm value</title>
<updated>2021-04-27T07:31:39Z</updated>
<author>
<name>brian m. carlson</name>
<email>sandals@crustytoothpaste.net</email>
</author>
<published>2021-04-26T01:03:00Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=b8505ecbf2b1e4ef27b9597fd113cb1679792b29'/>
<id>urn:sha1:b8505ecbf2b1e4ef27b9597fd113cb1679792b29</id>
<content type='text'>
There are numerous places in the codebase where we assume we can
initialize data by zeroing all its bytes.  However, when we do that with
a struct object_id, it leaves the structure with a zero value for the
algorithm, which is invalid.

We could forbid this pattern and require that all struct object_id
instances be initialized using oidclr, but this seems burdensome and
it's unnatural to most C programmers.  Instead, if the algorithm is
zero, assume we wanted to use the default hash algorithm instead.

Signed-off-by: brian m. carlson &lt;sandals@crustytoothpaste.net&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>hash: set, copy, and use algo field in struct object_id</title>
<updated>2021-04-27T07:31:38Z</updated>
<author>
<name>brian m. carlson</name>
<email>sandals@crustytoothpaste.net</email>
</author>
<published>2021-04-26T01:02:55Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=5a6dce70d7bb12ee2bc7926254c5b6741b91ac5f'/>
<id>urn:sha1:5a6dce70d7bb12ee2bc7926254c5b6741b91ac5f</id>
<content type='text'>
Now that struct object_id has an algorithm field, we should populate it.
This will allow us to handle object IDs in any supported algorithm and
distinguish between them.  Ensure that the field is written whenever we
write an object ID by storing it explicitly every time we write an
object.  Set values for the empty blob and tree values as well.

In addition, use the algorithm field to compare object IDs.  Note that
because we zero-initialize struct object_id in many places throughout
the codebase, we default to the default algorithm in cases where the
algorithm field is zero rather than explicitly initialize all of those
locations.

This leads to a branch on every comparison, but the alternative is to
compare the entire buffer each time and padding the buffer for SHA-1.
That alternative ranges up to 3.9% worse than this approach on the perf
t0001, t1450, and t1451.

Signed-off-by: brian m. carlson &lt;sandals@crustytoothpaste.net&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>hex: add functions to parse hex object IDs in any algorithm</title>
<updated>2020-02-24T17:33:21Z</updated>
<author>
<name>brian m. carlson</name>
<email>sandals@crustytoothpaste.net</email>
</author>
<published>2020-02-22T20:17:29Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=61e2a70ff26f83f761fa36e0cc16996878d8dd59'/>
<id>urn:sha1:61e2a70ff26f83f761fa36e0cc16996878d8dd59</id>
<content type='text'>
There are some places where we need to parse a hex object ID in any
algorithm without knowing beforehand which algorithm is in use. An
example is when parsing fast-import marks.

Add a get_oid_hex_any to parse an object ID and return the algorithm it
belongs to, and additionally add parse_oid_hex_any which is the
equivalent change for parse_oid_hex. If the object is not parseable, we
return GIT_HASH_UNKNOWN.

Signed-off-by: brian m. carlson &lt;sandals@crustytoothpaste.net&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>hex: introduce parsing variants taking hash algorithms</title>
<updated>2020-02-24T17:33:21Z</updated>
<author>
<name>brian m. carlson</name>
<email>sandals@crustytoothpaste.net</email>
</author>
<published>2020-02-22T20:17:28Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=dadacf10dc9e11046e2c8c49347174e71cef3fa3'/>
<id>urn:sha1:dadacf10dc9e11046e2c8c49347174e71cef3fa3</id>
<content type='text'>
Introduce variants of get_oid_hex and parse_oid_hex that parse an
arbitrary hash algorithm, implementing internal functions to avoid
duplication.  These functions can be used in the transport code to parse
refs properly.

Signed-off-by: brian m. carlson &lt;sandals@crustytoothpaste.net&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>hex: drop sha1_to_hex()</title>
<updated>2019-11-13T01:09:10Z</updated>
<author>
<name>Jeff King</name>
<email>peff@peff.net</email>
</author>
<published>2019-11-11T09:04:18Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=b19f3fe9dd1a0c00fb8b30df9896912727f2eea2'/>
<id>urn:sha1:b19f3fe9dd1a0c00fb8b30df9896912727f2eea2</id>
<content type='text'>
There's only a single caller left of sha1_to_hex(), since everybody
that has an object name in "unsigned char[]" now uses hash_to_hex()
instead.

This case is in the sha1dc wrapper, where we print a hex sha1 when
we find a collision. This one will always be sha1, regardless of the
current hash algorithm, so we can't use hash_to_hex() here. In
practice we'd probably not be running sha1 at all if it isn't the
current algorithm, but it's possible we might still occasionally
need to compute a sha1 in a post-sha256 world.

Since sha1_to_hex() is just a wrapper for hash_to_hex_algop(), let's
call that ourselves. There's value in getting rid of the sha1-specific
wrapper to de-clutter the global namespace, and to make sure nobody uses
it (and as with sha1_to_hex_r() in the previous patch, we'll drop the
coccinelle transformations, too).

The sha1_to_hex() function is mentioned in a comment; we can easily
swap that out for oid_to_hex() to give a better example.  Also
update the comment that was left stale when we added "struct
object_id *" as a way to name an object and added functions to
convert it to hex.

The function is also mentioned in some test vectors in t4100, but
that's not runnable code, so there's no point in trying to clean it
up.

Signed-off-by: Jeff King &lt;peff@peff.net&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>hex: drop sha1_to_hex_r()</title>
<updated>2019-11-11T09:11:41Z</updated>
<author>
<name>Jeff King</name>
<email>peff@peff.net</email>
</author>
<published>2019-11-11T09:04:11Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=aa6d7f93edc39361c926e1748fbee3b4243808f8'/>
<id>urn:sha1:aa6d7f93edc39361c926e1748fbee3b4243808f8</id>
<content type='text'>
There are no callers left; everybody uses oid_to_hex_r() or
hash_to_hex_algop_r(). This used to actually be the underlying
implementation for oid_to_hex_r(), but that's no longer the case since
47edb64997 (hex: introduce functions to print arbitrary hashes,
2018-11-14).

Let's get rid of it to de-clutter and to make sure nobody uses it.
Likewise we can drop the coccinelle rules that mention it, since the
compiler will make it quite clear that the code does not work.

Signed-off-by: Jeff King &lt;peff@peff.net&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>hex: introduce functions to print arbitrary hashes</title>
<updated>2018-11-14T07:54:52Z</updated>
<author>
<name>brian m. carlson</name>
<email>sandals@crustytoothpaste.net</email>
</author>
<published>2018-11-14T04:09:29Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=47edb649973cf5cd5f7066b5c936b330f78d687b'/>
<id>urn:sha1:47edb649973cf5cd5f7066b5c936b330f78d687b</id>
<content type='text'>
Currently, we have functions that turn an arbitrary SHA-1 value or an
object ID into hex format, either using a static buffer or with a
user-provided buffer.  Add variants of these functions that can handle
an arbitrary hash algorithm, specified by constant.  Update the
documentation as well.

While we're at it, remove the "extern" declaration from this family of
functions, since it's not needed and our style now recommends against
it.

We use the variant taking the algorithm structure pointer as the
internal variant, since taking an algorithm pointer is the easiest way
to handle all of the variants in use.

Note that we maintain these functions because there are hashes which
must change based on the hash algorithm in use but are not object IDs
(such as pack checksums).

Signed-off-by: brian m. carlson &lt;sandals@crustytoothpaste.net&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>hex: switch to using the_hash_algo</title>
<updated>2018-07-16T21:27:39Z</updated>
<author>
<name>brian m. carlson</name>
<email>sandals@crustytoothpaste.net</email>
</author>
<published>2018-07-16T01:27:55Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=d9cd734990a5fedbf7fc34debe6c10d5d10e954a'/>
<id>urn:sha1:d9cd734990a5fedbf7fc34debe6c10d5d10e954a</id>
<content type='text'>
Instead of using the GIT_SHA1_* constants, switch to using the_hash_algo
to convert object IDs to and from hex format.

Signed-off-by: brian m. carlson &lt;sandals@crustytoothpaste.net&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>notes: move hex_to_bytes() to hex.c and export it</title>
<updated>2017-11-01T01:35:35Z</updated>
<author>
<name>René Scharfe</name>
<email>l.s.r@web.de</email>
</author>
<published>2017-10-31T13:46:49Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=0ec218656a02ea48e173262f7b80513feeb7f263'/>
<id>urn:sha1:0ec218656a02ea48e173262f7b80513feeb7f263</id>
<content type='text'>
Make the function for converting pairs of hexadecimal digits to binary
available to other call sites.

Signed-off-by: Rene Scharfe &lt;l.s.r@web.de&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
</feed>
