Skip to content

Commit 3a14fde

Browse files
committed
Merge branch 'sl/const'
Code cleanup. * sl/const: various: tighten constness of some local variables
2 parents 257507a + 33de80b commit 3a14fde

File tree

4 files changed

+15
-15
lines changed

4 files changed

+15
-15
lines changed

builtin/diff.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ static int builtin_diff_blobs(struct rev_info *revs,
103103
int argc, const char **argv,
104104
struct object_array_entry **blob)
105105
{
106-
unsigned mode = canon_mode(S_IFREG | 0644);
106+
const unsigned mode = canon_mode(S_IFREG | 0644);
107107

108108
if (argc > 1)
109109
usage(builtin_diff_usage);

builtin/pack-objects.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1902,10 +1902,10 @@ static int type_size_sort(const void *_a, const void *_b)
19021902
{
19031903
const struct object_entry *a = *(struct object_entry **)_a;
19041904
const struct object_entry *b = *(struct object_entry **)_b;
1905-
enum object_type a_type = oe_type(a);
1906-
enum object_type b_type = oe_type(b);
1907-
unsigned long a_size = SIZE(a);
1908-
unsigned long b_size = SIZE(b);
1905+
const enum object_type a_type = oe_type(a);
1906+
const enum object_type b_type = oe_type(b);
1907+
const unsigned long a_size = SIZE(a);
1908+
const unsigned long b_size = SIZE(b);
19091909

19101910
if (a_type > b_type)
19111911
return -1;
@@ -1920,7 +1920,7 @@ static int type_size_sort(const void *_a, const void *_b)
19201920
if (a->preferred_base < b->preferred_base)
19211921
return 1;
19221922
if (use_delta_islands) {
1923-
int island_cmp = island_delta_cmp(&a->idx.oid, &b->idx.oid);
1923+
const int island_cmp = island_delta_cmp(&a->idx.oid, &b->idx.oid);
19241924
if (island_cmp)
19251925
return island_cmp;
19261926
}
@@ -2167,7 +2167,7 @@ static unsigned int check_delta_limit(struct object_entry *me, unsigned int n)
21672167
struct object_entry *child = DELTA_CHILD(me);
21682168
unsigned int m = n;
21692169
while (child) {
2170-
unsigned int c = check_delta_limit(child, n + 1);
2170+
const unsigned int c = check_delta_limit(child, n + 1);
21712171
if (m < c)
21722172
m = c;
21732173
child = DELTA_SIBLING(child);
@@ -2222,7 +2222,7 @@ static void find_deltas(struct object_entry **list, unsigned *list_size,
22222222
while (window_memory_limit &&
22232223
mem_usage > window_memory_limit &&
22242224
count > 1) {
2225-
uint32_t tail = (idx + window - count) % window;
2225+
const uint32_t tail = (idx + window - count) % window;
22262226
mem_usage -= free_unpacked(array + tail);
22272227
count--;
22282228
}

builtin/pack-redundant.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ static inline struct llist_item * llist_sorted_remove(struct llist *list, const
166166
l = (hint == NULL) ? list->front : hint;
167167
prev = NULL;
168168
while (l) {
169-
int cmp = oidcmp(l->oid, oid);
169+
const int cmp = oidcmp(l->oid, oid);
170170
if (cmp > 0) /* not in list, since sorted */
171171
return prev;
172172
if (!cmp) { /* found */
@@ -264,7 +264,7 @@ static void cmp_two_packs(struct pack_list *p1, struct pack_list *p2)
264264
while (p1_off < p1->pack->num_objects * p1_step &&
265265
p2_off < p2->pack->num_objects * p2_step)
266266
{
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);
268268
/* cmp ~ p1 - p2 */
269269
if (cmp == 0) {
270270
p1_hint = llist_sorted_remove(p1->unique_objects,

pack-revindex.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ static void sort_revindex(struct revindex_entry *entries, unsigned n, off_t max)
119119
*/
120120
static void create_pack_revindex(struct packed_git *p)
121121
{
122-
unsigned num_ent = p->num_objects;
122+
const unsigned num_ent = p->num_objects;
123123
unsigned i;
124124
const char *index = p->index_data;
125125
const unsigned hashsz = the_hash_algo->rawsz;
@@ -132,7 +132,7 @@ static void create_pack_revindex(struct packed_git *p)
132132
(uint32_t *)(index + 8 + p->num_objects * (hashsz + 4));
133133
const uint32_t *off_64 = off_32 + p->num_objects;
134134
for (i = 0; i < num_ent; i++) {
135-
uint32_t off = ntohl(*off_32++);
135+
const uint32_t off = ntohl(*off_32++);
136136
if (!(off & 0x80000000)) {
137137
p->revindex[i].offset = off;
138138
} else {
@@ -143,7 +143,7 @@ static void create_pack_revindex(struct packed_git *p)
143143
}
144144
} else {
145145
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));
147147
p->revindex[i].offset = ntohl(hl);
148148
p->revindex[i].nr = i;
149149
}
@@ -168,10 +168,10 @@ int find_revindex_position(struct packed_git *p, off_t ofs)
168168
{
169169
int lo = 0;
170170
int hi = p->num_objects + 1;
171-
struct revindex_entry *revindex = p->revindex;
171+
const struct revindex_entry *revindex = p->revindex;
172172

173173
do {
174-
unsigned mi = lo + (hi - lo) / 2;
174+
const unsigned mi = lo + (hi - lo) / 2;
175175
if (revindex[mi].offset == ofs) {
176176
return mi;
177177
} else if (ofs < revindex[mi].offset)

0 commit comments

Comments
 (0)