v6 fixes the one optimization that I just couldn't get right, fixes
two off-by-one error messages and a couple commit message update
(biggest change is in 11/11 to record some numbers from AEvar)

diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index fb2aba80bf..4406af640f 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -3112,10 +3112,10 @@ int cmd_pack_objects(int argc, const char **argv, const 
char *prefix)
 
        if (depth >= (1 << OE_DEPTH_BITS))
                die(_("delta chain depth %d is greater than maximum limit %d"),
-                   depth, (1 << OE_DEPTH_BITS));
+                   depth, (1 << OE_DEPTH_BITS) - 1);
        if (cache_max_small_delta_size >= (1 << OE_Z_DELTA_BITS))
                die(_("pack.deltaCacheLimit is greater than maximum limit %d"),
-                   1 << OE_Z_DELTA_BITS);
+                   (1 << OE_Z_DELTA_BITS) - 1);
 
        argv_array_push(&rp, "pack-objects");
        if (thin) {
diff --git a/pack-objects.h b/pack-objects.h
index 55358da9f3..af40211105 100644
--- a/pack-objects.h
+++ b/pack-objects.h
@@ -275,7 +275,7 @@ static inline unsigned long oe_size(const struct 
object_entry *e)
        }
 }
 
-static inline int contains_in_32bits(unsigned long limit)
+static inline int oe_fits_in_32bits(unsigned long limit)
 {
        uint32_t truncated_limit = (uint32_t)limit;
 
@@ -287,8 +287,8 @@ static inline int oe_size_less_than(const struct 
object_entry *e,
 {
        if (e->size_valid)
                return e->size_ < limit;
-       if (contains_in_32bits(limit))
-               return 1;
+       if (oe_fits_in_32bits(limit)) /* limit < 2^32 <= size ? */
+               return 0;
        return oe_size(e) < limit;
 }
 
@@ -297,8 +297,8 @@ static inline int oe_size_greater_than(const struct 
object_entry *e,
 {
        if (e->size_valid)
                return e->size_ > limit;
-       if (contains_in_32bits(limit))
-               return 0;
+       if (oe_fits_in_32bits(limit)) /* limit < 2^32 <= size ? */
+               return 1;
        return oe_size(e) > limit;
 }
 
@@ -307,6 +307,14 @@ static inline void oe_set_size(struct object_entry *e,
 {
        e->size_ = size;
        e->size_valid = e->size_ == size;
+
+       if (!e->size_valid) {
+               unsigned long real_size;
+
+               if (sha1_object_info(e->idx.oid.hash, &real_size) < 0 ||
+                   size != real_size)
+                       die("BUG: 'size' is supposed to be the object size!");
+       }
 }
 
 static inline unsigned long oe_delta_size(struct packing_data *pack,

-- 
2.17.0.rc0.347.gf9cf61673a

Reply via email to