1515#include "refs.h"
1616#include "remote.h"
1717#include "dir.h"
18+ #include "odb.h"
1819#include "oid-array.h"
19- #include "packfile.h"
2020#include "pretty.h"
21- #include "object-file.h"
2221#include "read-cache-ll.h"
2322#include "repo-settings.h"
2423#include "repository.h"
@@ -569,19 +568,6 @@ int repo_for_each_abbrev(struct repository *r, const char *prefix,
569568 return ret ;
570569}
571570
572- /*
573- * Return the slot of the most-significant bit set in "val". There are various
574- * ways to do this quickly with fls() or __builtin_clzl(), but speed is
575- * probably not a big deal here.
576- */
577- static unsigned msb (unsigned long val )
578- {
579- unsigned r = 0 ;
580- while (val >>= 1 )
581- r ++ ;
582- return r ;
583- }
584-
585571void strbuf_repo_add_unique_abbrev (struct strbuf * sb , struct repository * repo ,
586572 const struct object_id * oid , int abbrev_len )
587573{
@@ -602,49 +588,14 @@ int repo_find_unique_abbrev_r(struct repository *r, char *hex,
602588{
603589 const struct git_hash_algo * algo =
604590 oid -> algo ? & hash_algos [oid -> algo ] : r -> hash_algo ;
605- const unsigned hexsz = algo -> hexsz ;
606591 unsigned len ;
607592
608- if (min_len < 0 ) {
609- unsigned long count ;
610-
611- if (odb_count_objects (r -> objects , ODB_COUNT_OBJECTS_APPROXIMATE , & count ) < 0 )
612- count = 0 ;
613-
614- /*
615- * Add one because the MSB only tells us the highest bit set,
616- * not including the value of all the _other_ bits (so "15"
617- * is only one off of 2^4, but the MSB is the 3rd bit.
618- */
619- len = msb (count ) + 1 ;
620- /*
621- * We now know we have on the order of 2^len objects, which
622- * expects a collision at 2^(len/2). But we also care about hex
623- * chars, not bits, and there are 4 bits per hex. So all
624- * together we need to divide by 2 and round up.
625- */
626- len = DIV_ROUND_UP (len , 2 );
627- /*
628- * For very small repos, we stick with our regular fallback.
629- */
630- if (len < FALLBACK_DEFAULT_ABBREV )
631- len = FALLBACK_DEFAULT_ABBREV ;
632- } else {
633- len = min_len ;
634- }
593+ if (odb_find_abbrev_len (r -> objects , oid , min_len , & len ) < 0 )
594+ len = algo -> hexsz ;
635595
636596 oid_to_hex_r (hex , oid );
637- if (len >= hexsz || !len )
638- return hexsz ;
639-
640- odb_prepare_alternates (r -> objects );
641- for (struct odb_source * s = r -> objects -> sources ; s ; s = s -> next ) {
642- struct odb_source_files * files = odb_source_files_downcast (s );
643- packfile_store_find_abbrev_len (files -> packed , oid , len , & len );
644- odb_source_loose_find_abbrev_len (s , oid , len , & len );
645- }
646-
647597 hex [len ] = 0 ;
598+
648599 return len ;
649600}
650601
0 commit comments