Thread (45 messages) 45 messages, 8 authors, 2018-06-06

Re: [RFC PATCH 2/2] sha1-name: add core.validateAbbrev & relative core.abbrev

From: Christian Couder <hidden>
Date: 2018-06-06 12:05:03

On Wed, Jun 6, 2018 at 12:27 PM, Ævar Arnfjörð Bjarmason
[off-list ref] wrote:
+This setting changes that to `O(1)`, but with the trade-off that
+depending on the value of `core.abbrev` way may be printing
s/way may be printing/we may be printing/
+abbreviated hashes that collide. Too see how likely this is, try
s/Too see/To see/
+running:
[...]
+Even without `core.validateAbbrev=false` the results abbreviation
+already a bit of a probability game.
s/the results abbreviation already a bit of/the resulting abbreviation
is already a bit of/ maybe?
quoted hunk ↗ jump to hunk
diff --git a/sha1-name.c b/sha1-name.c
index 60d9ef3c7e..aa7ccea14d 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -576,6 +576,7 @@ int find_unique_abbrev_r(char *hex, const struct object_id *oid, int len)
        struct disambiguate_state ds;
        struct min_abbrev_data mad;
        struct object_id oid_ret;
+       int dar = default_abbrev_relative;
        if (len < 0) {
                unsigned long count = approximate_object_count();
                /*
@@ -602,6 +603,20 @@ int find_unique_abbrev_r(char *hex, const struct object_id *oid, int len)
        if (len == GIT_SHA1_HEXSZ || !len)
                return GIT_SHA1_HEXSZ;

+       if (dar) {
+               if (len + dar < MINIMUM_ABBREV) {
+                       len = MINIMUM_ABBREV;
+                       dar = 0;
+               }
+
+               if (validate_abbrev) {
+                       len += dar;
+               } else {
+                       hex[len + dar] = 0;
+                       return len + dar;
+               }
I wonder what happens if len + dar > GIT_SHA1_HEXSZ
+       }
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help