various: tighten constness of some local variables
Signed-off-by: Shahzad Lone <shahzadlone@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Shahzad Lone committed
Feb 2, 2019 at 23:16 UTC
33de80b1d50773f79e380eff33b4fc5c8ae1dd25
4 files changed
+15
-15
builtin/diff.c
+1
-1
@@ -102,7 +102,7 @@ static int builtin_diff_blobs(struct rev_info *revs,
102
int argc, const char **argv,
103
struct object_array_entry **blob)
104
{
105
- unsigned mode = canon_mode(S_IFREG | 0644);
105
+ const unsigned mode = canon_mode(S_IFREG | 0644);
106
107
if (argc > 1)
108
usage(builtin_diff_usage);
builtin/pack-objects.c
+7
-7
@@ -1901,10 +1901,10 @@ static int type_size_sort(const void *_a, const void *_b)
1901
{
1902
const struct object_entry *a = *(struct object_entry **)_a;
1903
const struct object_entry *b = *(struct object_entry **)_b;
1904
- enum object_type a_type = oe_type(a);
1905
- enum object_type b_type = oe_type(b);
1906
- unsigned long a_size = SIZE(a);
1907
- unsigned long b_size = SIZE(b);
1904
+ const enum object_type a_type = oe_type(a);
1905
+ const enum object_type b_type = oe_type(b);
1906
+ const unsigned long a_size = SIZE(a);
1907
+ const unsigned long b_size = SIZE(b);
1908
1909
if (a_type > b_type)
1910
return -1;
@@ -1919,7 +1919,7 @@ static int type_size_sort(const void *_a, const void *_b)
1919
if (a->preferred_base < b->preferred_base)
1920
return 1;
1921
if (use_delta_islands) {
1922
- int island_cmp = island_delta_cmp(&a->idx.oid, &b->idx.oid);
1922
+ const int island_cmp = island_delta_cmp(&a->idx.oid, &b->idx.oid);
1923
if (island_cmp)
1924
return island_cmp;
1925
}
@@ -2171,7 +2171,7 @@ static unsigned int check_delta_limit(struct object_entry *me, unsigned int n)
2171
struct object_entry *child = DELTA_CHILD(me);
2172
unsigned int m = n;
2173
while (child) {
2174
- unsigned int c = check_delta_limit(child, n + 1);
2174
+ const unsigned int c = check_delta_limit(child, n + 1);
2175
if (m < c)
2176
m = c;
2177
child = DELTA_SIBLING(child);
@@ -2226,7 +2226,7 @@ static void find_deltas(struct object_entry **list, unsigned *list_size,
2226
while (window_memory_limit &&
2227
mem_usage > window_memory_limit &&
2228
count > 1) {
2229
- uint32_t tail = (idx + window - count) % window;
2229
+ const uint32_t tail = (idx + window - count) % window;
2230
mem_usage -= free_unpacked(array + tail);
2231
count--;
2232
}
builtin/pack-redundant.c
+2
-2
@@ -166,7 +166,7 @@ redo_from_start:
166
l = (hint == NULL) ? list->front : hint;
167
prev = NULL;
168
while (l) {
169
- int cmp = oidcmp(l->oid, oid);
169
+ const int cmp = oidcmp(l->oid, oid);
170
if (cmp > 0) /* not in list, since sorted */
171
return prev;
172
if (!cmp) { /* found */
@@ -264,7 +264,7 @@ static void cmp_two_packs(struct pack_list *p1, struct pack_list *p2)
264
while (p1_off < p1->pack->num_objects * p1_step &&
265
p2_off < p2->pack->num_objects * p2_step)
266
{
267
- int cmp = hashcmp(p1_base + p1_off, p2_base + p2_off);
267
+ const int cmp = hashcmp(p1_base + p1_off, p2_base + p2_off);
268
/* cmp ~ p1 - p2 */
269
if (cmp == 0) {
270
p1_hint = llist_sorted_remove(p1->unique_objects,
pack-revindex.c
+5
-5
@@ -119,7 +119,7 @@ static void sort_revindex(struct revindex_entry *entries, unsigned n, off_t max)
119
*/
120
static void create_pack_revindex(struct packed_git *p)
121
{
122
- unsigned num_ent = p->num_objects;
122
+ const unsigned num_ent = p->num_objects;
123
unsigned i;
124
const char *index = p->index_data;
125
const unsigned hashsz = the_hash_algo->rawsz;
@@ -132,7 +132,7 @@ static void create_pack_revindex(struct packed_git *p)
132
(uint32_t *)(index + 8 + p->num_objects * (hashsz + 4));
133
const uint32_t *off_64 = off_32 + p->num_objects;
134
for (i = 0; i < num_ent; i++) {
135
- uint32_t off = ntohl(*off_32++);
135
+ const uint32_t off = ntohl(*off_32++);
136
if (!(off & 0x80000000)) {
137
p->revindex[i].offset = off;
138
} else {
@@ -143,7 +143,7 @@ static void create_pack_revindex(struct packed_git *p)
143
}
144
} else {
145
for (i = 0; i < num_ent; i++) {
146
- uint32_t hl = *((uint32_t *)(index + (hashsz + 4) * i));
146
+ const uint32_t hl = *((uint32_t *)(index + (hashsz + 4) * i));
147
p->revindex[i].offset = ntohl(hl);
148
p->revindex[i].nr = i;
149
}
@@ -168,10 +168,10 @@ int find_revindex_position(struct packed_git *p, off_t ofs)
168
{
169
int lo = 0;
170
int hi = p->num_objects + 1;
171
- struct revindex_entry *revindex = p->revindex;
171
+ const struct revindex_entry *revindex = p->revindex;
172
173
do {
174
- unsigned mi = lo + (hi - lo) / 2;
174
+ const unsigned mi = lo + (hi - lo) / 2;
175
if (revindex[mi].offset == ofs) {
176
return mi;
177
} else if (ofs < revindex[mi].offset)