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 <gitster@pobox.com>
Junio C Hamano committed
Jun 20, 2012 at 22:35 UTC
1703f9aa0b87d52278489029d538ef1a4aa37432
1 file changed
+22
-22
sha1_name.c
+22
-22
@@ -9,7 +9,7 @@
9
10
static int get_sha1_oneline(const char *, unsigned char *, struct commit_list *);
11
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)
13
{
14
struct alternate_object_database *alt;
15
char hex[40];
@@ -34,18 +34,18 @@ static int find_short_object_filename(int len, const char *name, unsigned char *
34
}
35
fakeent->next = alt_odb_list;
36
37
- sprintf(hex, "%.2s", name);
37
+ sprintf(hex, "%.2s", hex_pfx);
38
for (alt = fakeent; alt && found < 2; alt = alt->next) {
39
struct dirent *de;
40
DIR *dir;
41
- sprintf(alt->name, "%.2s/", name);
41
+ sprintf(alt->name, "%.2s/", hex_pfx);
42
dir = opendir(alt->base);
43
if (!dir)
44
continue;
45
while ((de = readdir(dir)) != NULL) {
46
if (strlen(de->d_name) != 38)
47
continue;
48
- if (memcmp(de->d_name, name + 2, len - 2))
48
+ if (memcmp(de->d_name, hex_pfx + 2, len - 2))
49
continue;
50
if (!found) {
51
memcpy(hex + 2, de->d_name, 38);
@@ -79,7 +79,7 @@ static int match_sha(unsigned len, const unsigned char *a, const unsigned char *
79
}
80
81
static int unique_in_pack(int len,
82
- const unsigned char *match,
82
+ const unsigned char *bin_pfx,
83
struct packed_git *p,
84
const unsigned char **found_sha1,
85
int seen_so_far)
@@ -96,7 +96,7 @@ static int unique_in_pack(int len,
96
int cmp;
97
98
current = nth_packed_object_sha1(p, mid);
99
- cmp = hashcmp(match, current);
99
+ cmp = hashcmp(bin_pfx, current);
100
if (!cmp) {
101
first = mid;
102
break;
@@ -110,12 +110,12 @@ static int unique_in_pack(int len,
110
111
/*
112
* 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
114
* 0, 1 or more objects that actually match(es).
115
*/
116
for (i = first; i < num; i++) {
117
current = nth_packed_object_sha1(p, first);
118
- if (!match_sha(len, match, current))
118
+ if (!match_sha(len, bin_pfx, current))
119
break;
120
121
/* current matches */
@@ -131,7 +131,7 @@ static int unique_in_pack(int len,
131
return seen_so_far;
132
}
133
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)
135
{
136
struct packed_git *p;
137
const unsigned char *found_sha1 = NULL;
@@ -139,7 +139,7 @@ static int find_short_packed_object(int len, const unsigned char *match, unsigne
139
140
prepare_packed_git();
141
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);
143
144
if (found == 1)
145
hashcpy(sha1, found_sha1);
@@ -149,15 +149,15 @@ static int find_short_packed_object(int len, const unsigned char *match, unsigne
149
#define SHORT_NAME_NOT_FOUND (-1)
150
#define SHORT_NAME_AMBIGUOUS (-2)
151
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)
154
{
155
int has_unpacked, has_packed;
156
unsigned char unpacked_sha1[20], packed_sha1[20];
157
158
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);
161
if (!has_unpacked && !has_packed)
162
return SHORT_NAME_NOT_FOUND;
163
if (1 < has_unpacked || 1 < has_packed)
@@ -177,13 +177,13 @@ static int get_short_sha1(const char *name, int len, unsigned char *sha1,
177
int quietly)
178
{
179
int i, status;
180
- char canonical[40];
181
- unsigned char res[20];
180
+ char hex_pfx[40];
181
+ unsigned char bin_pfx[20];
182
183
if (len < MINIMUM_ABBREV || len > 40)
184
return -1;
185
- hashclr(res);
186
- memset(canonical, 'x', 40);
185
+ hashclr(bin_pfx);
186
+ memset(hex_pfx, 'x', 40);
187
for (i = 0; i < len ;i++) {
188
unsigned char c = name[i];
189
unsigned char val;
@@ -197,15 +197,15 @@ static int get_short_sha1(const char *name, int len, unsigned char *sha1,
197
}
198
else
199
return -1;
200
- canonical[i] = c;
200
+ hex_pfx[i] = c;
201
if (!(i & 1))
202
val <<= 4;
203
- res[i >> 1] |= val;
203
+ bin_pfx[i >> 1] |= val;
204
}
205
206
- status = find_unique_short_object(i, canonical, res, sha1);
206
+ status = find_unique_short_object(i, hex_pfx, bin_pfx, sha1);
207
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);
209
return status;
210
}
211