Skip to content

Commit 1a876a6

Browse files
bk2204gitster
authored andcommitted
patch-id: convert to use struct object_id
Convert some magic numbers to the new GIT_SHA1 constants. Signed-off-by: brian m. carlson <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7683e2e commit 1a876a6

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

builtin/patch-id.c

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
#include "builtin.h"
22

3-
static void flush_current_id(int patchlen, unsigned char *id, unsigned char *result)
3+
static void flush_current_id(int patchlen, struct object_id *id, struct object_id *result)
44
{
55
char name[50];
66

77
if (!patchlen)
88
return;
99

10-
memcpy(name, sha1_to_hex(id), 41);
11-
printf("%s %s\n", sha1_to_hex(result), name);
10+
memcpy(name, oid_to_hex(id), GIT_SHA1_HEXSZ + 1);
11+
printf("%s %s\n", oid_to_hex(result), name);
1212
}
1313

1414
static int remove_space(char *line)
@@ -53,31 +53,31 @@ static int scan_hunk_header(const char *p, int *p_before, int *p_after)
5353
return 1;
5454
}
5555

56-
static void flush_one_hunk(unsigned char *result, git_SHA_CTX *ctx)
56+
static void flush_one_hunk(struct object_id *result, git_SHA_CTX *ctx)
5757
{
58-
unsigned char hash[20];
58+
unsigned char hash[GIT_SHA1_RAWSZ];
5959
unsigned short carry = 0;
6060
int i;
6161

6262
git_SHA1_Final(hash, ctx);
6363
git_SHA1_Init(ctx);
6464
/* 20-byte sum, with carry */
65-
for (i = 0; i < 20; ++i) {
66-
carry += result[i] + hash[i];
67-
result[i] = carry;
65+
for (i = 0; i < GIT_SHA1_RAWSZ; ++i) {
66+
carry += result->hash[i] + hash[i];
67+
result->hash[i] = carry;
6868
carry >>= 8;
6969
}
7070
}
7171

72-
static int get_one_patchid(unsigned char *next_sha1, unsigned char *result,
72+
static int get_one_patchid(struct object_id *next_oid, struct object_id *result,
7373
struct strbuf *line_buf, int stable)
7474
{
7575
int patchlen = 0, found_next = 0;
7676
int before = -1, after = -1;
7777
git_SHA_CTX ctx;
7878

7979
git_SHA1_Init(&ctx);
80-
hashclr(result);
80+
oidclr(result);
8181

8282
while (strbuf_getwholeline(line_buf, stdin, '\n') != EOF) {
8383
char *line = line_buf->buf;
@@ -93,7 +93,7 @@ static int get_one_patchid(unsigned char *next_sha1, unsigned char *result,
9393
else if (!memcmp(line, "\\ ", 2) && 12 < strlen(line))
9494
continue;
9595

96-
if (!get_sha1_hex(p, next_sha1)) {
96+
if (!get_oid_hex(p, next_oid)) {
9797
found_next = 1;
9898
break;
9999
}
@@ -143,7 +143,7 @@ static int get_one_patchid(unsigned char *next_sha1, unsigned char *result,
143143
}
144144

145145
if (!found_next)
146-
hashclr(next_sha1);
146+
oidclr(next_oid);
147147

148148
flush_one_hunk(result, &ctx);
149149

@@ -152,15 +152,15 @@ static int get_one_patchid(unsigned char *next_sha1, unsigned char *result,
152152

153153
static void generate_id_list(int stable)
154154
{
155-
unsigned char sha1[20], n[20], result[20];
155+
struct object_id oid, n, result;
156156
int patchlen;
157157
struct strbuf line_buf = STRBUF_INIT;
158158

159-
hashclr(sha1);
159+
oidclr(&oid);
160160
while (!feof(stdin)) {
161-
patchlen = get_one_patchid(n, result, &line_buf, stable);
162-
flush_current_id(patchlen, sha1, result);
163-
hashcpy(sha1, n);
161+
patchlen = get_one_patchid(&n, &result, &line_buf, stable);
162+
flush_current_id(patchlen, &oid, &result);
163+
oidcpy(&oid, &n);
164164
}
165165
strbuf_release(&line_buf);
166166
}

0 commit comments

Comments
 (0)