Skip to content

Commit 1703f9a

Browse files
committed
sha1_name.c: correct misnamed "canonical" and "res"
These are hexadecimal and binary representation of the short object name given to the callchain as its input. Rename them with _pfx suffix to make it clear they are prefixes, and call them hex and bin respectively. Signed-off-by: Junio C Hamano <[email protected]>
1 parent f703e6e commit 1703f9a

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

sha1_name.c

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
static int get_sha1_oneline(const char *, unsigned char *, struct commit_list *);
1111

12-
static int find_short_object_filename(int len, const char *name, unsigned char *sha1)
12+
static int find_short_object_filename(int len, const char *hex_pfx, unsigned char *sha1)
1313
{
1414
struct alternate_object_database *alt;
1515
char hex[40];
@@ -34,18 +34,18 @@ static int find_short_object_filename(int len, const char *name, unsigned char *
3434
}
3535
fakeent->next = alt_odb_list;
3636

37-
sprintf(hex, "%.2s", name);
37+
sprintf(hex, "%.2s", hex_pfx);
3838
for (alt = fakeent; alt && found < 2; alt = alt->next) {
3939
struct dirent *de;
4040
DIR *dir;
41-
sprintf(alt->name, "%.2s/", name);
41+
sprintf(alt->name, "%.2s/", hex_pfx);
4242
dir = opendir(alt->base);
4343
if (!dir)
4444
continue;
4545
while ((de = readdir(dir)) != NULL) {
4646
if (strlen(de->d_name) != 38)
4747
continue;
48-
if (memcmp(de->d_name, name + 2, len - 2))
48+
if (memcmp(de->d_name, hex_pfx + 2, len - 2))
4949
continue;
5050
if (!found) {
5151
memcpy(hex + 2, de->d_name, 38);
@@ -79,7 +79,7 @@ static int match_sha(unsigned len, const unsigned char *a, const unsigned char *
7979
}
8080

8181
static int unique_in_pack(int len,
82-
const unsigned char *match,
82+
const unsigned char *bin_pfx,
8383
struct packed_git *p,
8484
const unsigned char **found_sha1,
8585
int seen_so_far)
@@ -96,7 +96,7 @@ static int unique_in_pack(int len,
9696
int cmp;
9797

9898
current = nth_packed_object_sha1(p, mid);
99-
cmp = hashcmp(match, current);
99+
cmp = hashcmp(bin_pfx, current);
100100
if (!cmp) {
101101
first = mid;
102102
break;
@@ -110,12 +110,12 @@ static int unique_in_pack(int len,
110110

111111
/*
112112
* At this point, "first" is the location of the lowest object
113-
* with an object name that could match "match". See if we have
113+
* with an object name that could match "bin_pfx". See if we have
114114
* 0, 1 or more objects that actually match(es).
115115
*/
116116
for (i = first; i < num; i++) {
117117
current = nth_packed_object_sha1(p, first);
118-
if (!match_sha(len, match, current))
118+
if (!match_sha(len, bin_pfx, current))
119119
break;
120120

121121
/* current matches */
@@ -131,15 +131,15 @@ static int unique_in_pack(int len,
131131
return seen_so_far;
132132
}
133133

134-
static int find_short_packed_object(int len, const unsigned char *match, unsigned char *sha1)
134+
static int find_short_packed_object(int len, const unsigned char *bin_pfx, unsigned char *sha1)
135135
{
136136
struct packed_git *p;
137137
const unsigned char *found_sha1 = NULL;
138138
int found = 0;
139139

140140
prepare_packed_git();
141141
for (p = packed_git; p && found < 2; p = p->next)
142-
found = unique_in_pack(len, match, p, &found_sha1, found);
142+
found = unique_in_pack(len, bin_pfx, p, &found_sha1, found);
143143

144144
if (found == 1)
145145
hashcpy(sha1, found_sha1);
@@ -149,15 +149,15 @@ static int find_short_packed_object(int len, const unsigned char *match, unsigne
149149
#define SHORT_NAME_NOT_FOUND (-1)
150150
#define SHORT_NAME_AMBIGUOUS (-2)
151151

152-
static int find_unique_short_object(int len, char *canonical,
153-
unsigned char *res, unsigned char *sha1)
152+
static int find_unique_short_object(int len, char *hex_pfx,
153+
unsigned char *bin_pfx, unsigned char *sha1)
154154
{
155155
int has_unpacked, has_packed;
156156
unsigned char unpacked_sha1[20], packed_sha1[20];
157157

158158
prepare_alt_odb();
159-
has_unpacked = find_short_object_filename(len, canonical, unpacked_sha1);
160-
has_packed = find_short_packed_object(len, res, packed_sha1);
159+
has_unpacked = find_short_object_filename(len, hex_pfx, unpacked_sha1);
160+
has_packed = find_short_packed_object(len, bin_pfx, packed_sha1);
161161
if (!has_unpacked && !has_packed)
162162
return SHORT_NAME_NOT_FOUND;
163163
if (1 < has_unpacked || 1 < has_packed)
@@ -177,13 +177,13 @@ static int get_short_sha1(const char *name, int len, unsigned char *sha1,
177177
int quietly)
178178
{
179179
int i, status;
180-
char canonical[40];
181-
unsigned char res[20];
180+
char hex_pfx[40];
181+
unsigned char bin_pfx[20];
182182

183183
if (len < MINIMUM_ABBREV || len > 40)
184184
return -1;
185-
hashclr(res);
186-
memset(canonical, 'x', 40);
185+
hashclr(bin_pfx);
186+
memset(hex_pfx, 'x', 40);
187187
for (i = 0; i < len ;i++) {
188188
unsigned char c = name[i];
189189
unsigned char val;
@@ -197,15 +197,15 @@ static int get_short_sha1(const char *name, int len, unsigned char *sha1,
197197
}
198198
else
199199
return -1;
200-
canonical[i] = c;
200+
hex_pfx[i] = c;
201201
if (!(i & 1))
202202
val <<= 4;
203-
res[i >> 1] |= val;
203+
bin_pfx[i >> 1] |= val;
204204
}
205205

206-
status = find_unique_short_object(i, canonical, res, sha1);
206+
status = find_unique_short_object(i, hex_pfx, bin_pfx, sha1);
207207
if (!quietly && (status == SHORT_NAME_AMBIGUOUS))
208-
return error("short SHA1 %.*s is ambiguous.", len, canonical);
208+
return error("short SHA1 %.*s is ambiguous.", len, hex_pfx);
209209
return status;
210210
}
211211

0 commit comments

Comments
 (0)