]> git.ipfire.org Git - thirdparty/git.git/commitdiff
pack-revindex: remove unused 'find_revindex_position()'
authorTaylor Blau <me@ttaylorr.com>
Wed, 13 Jan 2021 22:25:02 +0000 (17:25 -0500)
committerJunio C Hamano <gitster@pobox.com>
Thu, 14 Jan 2021 05:53:48 +0000 (21:53 -0800)
Now that all 'find_revindex_position()' callers have been removed (and
converted to the more descriptive 'offset_to_pack_pos()'), it is almost
safe to get rid of 'find_revindex_position()' entirely. Almost, except
for the fact that 'offset_to_pack_pos()' calls
'find_revindex_position()'.

Inline 'find_revindex_position()' into 'offset_to_pack_pos()', and
then remove 'find_revindex_position()' entirely.

This is a straightforward refactoring with one minor snag.
'offset_to_pack_pos()' used to load the index before calling
'find_revindex_position()'. That means that by the time
'find_revindex_position()' starts executing, 'p->num_objects' can be
safely read. After inlining, be careful to not read 'p->num_objects'
until _after_ 'load_pack_revindex()' (which loads the index as a
side-effect) has been called.

Another small fix that is included is converting the upper- and
lower-bounds to be unsigned's instead of ints. This dates back to
92e5c77c37 (revindex: export new APIs, 2013-10-24)--ironically, the last
time we introduced new APIs here--but this unifies the types.

Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
pack-revindex.c
pack-revindex.h

index 16baafb2811e0a6b9a973ca83576825aea75c3c4..282fe9264050b834c0e580b82e0eca4f54de6366 100644 (file)
@@ -169,16 +169,23 @@ int load_pack_revindex(struct packed_git *p)
        return 0;
 }
 
-int find_revindex_position(struct packed_git *p, off_t ofs)
+int offset_to_pack_pos(struct packed_git *p, off_t ofs, uint32_t *pos)
 {
-       int lo = 0;
-       int hi = p->num_objects + 1;
-       const struct revindex_entry *revindex = p->revindex;
+       unsigned lo, hi;
+       const struct revindex_entry *revindex;
+
+       if (load_pack_revindex(p) < 0)
+               return -1;
+
+       lo = 0;
+       hi = p->num_objects + 1;
+       revindex = p->revindex;
 
        do {
                const unsigned mi = lo + (hi - lo) / 2;
                if (revindex[mi].offset == ofs) {
-                       return mi;
+                       *pos = mi;
+                       return 0;
                } else if (ofs < revindex[mi].offset)
                        hi = mi;
                else
@@ -189,20 +196,6 @@ int find_revindex_position(struct packed_git *p, off_t ofs)
        return -1;
 }
 
-int offset_to_pack_pos(struct packed_git *p, off_t ofs, uint32_t *pos)
-{
-       int ret;
-
-       if (load_pack_revindex(p) < 0)
-               return -1;
-
-       ret = find_revindex_position(p, ofs);
-       if (ret < 0)
-               return ret;
-       *pos = ret;
-       return 0;
-}
-
 uint32_t pack_pos_to_index(struct packed_git *p, uint32_t pos)
 {
        if (!p->revindex)
index f7094ba9a5d5b8de792d41bcc7a66211d17794aa..746776be7f6bc3bdea0626a05b6a48b9b9fc4525 100644 (file)
@@ -28,7 +28,6 @@ struct revindex_entry {
  * given pack, returning zero on success and a negative value otherwise.
  */
 int load_pack_revindex(struct packed_git *p);
-int find_revindex_position(struct packed_git *p, off_t ofs);
 
 /*
  * offset_to_pack_pos converts an object offset to a pack position. This