@@ -16,6 +16,11 @@ static int sha1_compare(const void *_a, const void *_b)
16
16
return hashcmp (a -> sha1 , b -> sha1 );
17
17
}
18
18
19
+ static int need_large_offset (off_t offset , const struct pack_idx_option * opts )
20
+ {
21
+ return (offset >> 31 ) || (opts -> off32_limit < offset );
22
+ }
23
+
19
24
/*
20
25
* On entry *sha1 contains the pack content SHA1 hash, on exit it is
21
26
* the SHA1 hash of sorted object names. The objects array passed in
@@ -65,7 +70,7 @@ const char *write_idx_file(const char *index_name, struct pack_idx_entry **objec
65
70
}
66
71
67
72
/* if last object's offset is >= 2^31 we should use index V2 */
68
- index_version = (last_obj_offset >> 31 ) ? 2 : opts -> version ;
73
+ index_version = need_large_offset (last_obj_offset , opts ) ? 2 : opts -> version ;
69
74
70
75
/* index versions 2 and above need a header */
71
76
if (index_version >= 2 ) {
@@ -125,8 +130,11 @@ const char *write_idx_file(const char *index_name, struct pack_idx_entry **objec
125
130
list = sorted_by_sha ;
126
131
for (i = 0 ; i < nr_objects ; i ++ ) {
127
132
struct pack_idx_entry * obj = * list ++ ;
128
- uint32_t offset = (obj -> offset <= opts -> off32_limit ) ?
129
- obj -> offset : (0x80000000 | nr_large_offset ++ );
133
+ uint32_t offset ;
134
+
135
+ offset = (need_large_offset (obj -> offset , opts )
136
+ ? (0x80000000 | nr_large_offset ++ )
137
+ : obj -> offset );
130
138
offset = htonl (offset );
131
139
sha1write (f , & offset , 4 );
132
140
}
@@ -136,13 +144,14 @@ const char *write_idx_file(const char *index_name, struct pack_idx_entry **objec
136
144
while (nr_large_offset ) {
137
145
struct pack_idx_entry * obj = * list ++ ;
138
146
uint64_t offset = obj -> offset ;
139
- if (offset > opts -> off32_limit ) {
140
- uint32_t split [2 ];
141
- split [0 ] = htonl (offset >> 32 );
142
- split [1 ] = htonl (offset & 0xffffffff );
143
- sha1write (f , split , 8 );
144
- nr_large_offset -- ;
145
- }
147
+ uint32_t split [2 ];
148
+
149
+ if (!need_large_offset (offset , opts ))
150
+ continue ;
151
+ split [0 ] = htonl (offset >> 32 );
152
+ split [1 ] = htonl (offset & 0xffffffff );
153
+ sha1write (f , split , 8 );
154
+ nr_large_offset -- ;
146
155
}
147
156
}
148
157
0 commit comments