Skip to content

Commit 33de80b

Browse files
shahzadlonegitster
authored andcommitted
various: tighten constness of some local variables
Signed-off-by: Shahzad Lone <shahzadlone@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent b5101f9 commit 33de80b

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
@@ -102,7 +102,7 @@ static int builtin_diff_blobs(struct rev_info *revs,
102102
int argc, const char **argv,
103103
struct object_array_entry **blob)
104104
{
105-
unsigned mode = canon_mode(S_IFREG | 0644);
105+
const unsigned mode = canon_mode(S_IFREG | 0644);
106106

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

builtin/pack-objects.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1901,10 +1901,10 @@ static int type_size_sort(const void *_a, const void *_b)
19011901
{
19021902
const struct object_entry *a = *(struct object_entry **)_a;
19031903
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);
19081908

19091909
if (a_type > b_type)
19101910
return -1;
@@ -1919,7 +1919,7 @@ static int type_size_sort(const void *_a, const void *_b)
19191919
if (a->preferred_base < b->preferred_base)
19201920
return 1;
19211921
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);
19231923
if (island_cmp)
19241924
return island_cmp;
19251925
}
@@ -2171,7 +2171,7 @@ static unsigned int check_delta_limit(struct object_entry *me, unsigned int n)
21712171
struct object_entry *child = DELTA_CHILD(me);
21722172
unsigned int m = n;
21732173
while (child) {
2174-
unsigned int c = check_delta_limit(child, n + 1);
2174+
const unsigned int c = check_delta_limit(child, n + 1);
21752175
if (m < c)
21762176
m = c;
21772177
child = DELTA_SIBLING(child);
@@ -2226,7 +2226,7 @@ static void find_deltas(struct object_entry **list, unsigned *list_size,
22262226
while (window_memory_limit &&
22272227
mem_usage > window_memory_limit &&
22282228
count > 1) {
2229-
uint32_t tail = (idx + window - count) % window;
2229+
const uint32_t tail = (idx + window - count) % window;
22302230
mem_usage -= free_unpacked(array + tail);
22312231
count--;
22322232
}

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)