patch-id: convert to use struct object_id
Convert some magic numbers to the new GIT_SHA1 constants. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
brian m. carlson committed
Mar 13, 2015 at 23:39 UTC
1a876a69af6552d16827ecc1931c42e2287a83a0
1 file changed
+17
-17
builtin/patch-id.c
+17
-17
@@ -1,14 +1,14 @@
1
#include "builtin.h"
2
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)
4
{
5
char name[50];
6
7
if (!patchlen)
8
return;
9
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);
12
}
13
14
static int remove_space(char *line)
@@ -53,23 +53,23 @@ static int scan_hunk_header(const char *p, int *p_before, int *p_after)
53
return 1;
54
}
55
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)
57
{
58
- unsigned char hash[20];
58
+ unsigned char hash[GIT_SHA1_RAWSZ];
59
unsigned short carry = 0;
60
int i;
61
62
git_SHA1_Final(hash, ctx);
63
git_SHA1_Init(ctx);
64
/* 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;
68
carry >>= 8;
69
}
70
}
71
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,
73
struct strbuf *line_buf, int stable)
74
{
75
int patchlen = 0, found_next = 0;
@@ -77,7 +77,7 @@ static int get_one_patchid(unsigned char *next_sha1, unsigned char *result,
77
git_SHA_CTX ctx;
78
79
git_SHA1_Init(&ctx);
80
- hashclr(result);
80
+ oidclr(result);
81
82
while (strbuf_getwholeline(line_buf, stdin, '\n') != EOF) {
83
char *line = line_buf->buf;
@@ -93,7 +93,7 @@ static int get_one_patchid(unsigned char *next_sha1, unsigned char *result,
93
else if (!memcmp(line, "\\ ", 2) && 12 < strlen(line))
94
continue;
95
96
- if (!get_sha1_hex(p, next_sha1)) {
96
+ if (!get_oid_hex(p, next_oid)) {
97
found_next = 1;
98
break;
99
}
@@ -143,7 +143,7 @@ static int get_one_patchid(unsigned char *next_sha1, unsigned char *result,
143
}
144
145
if (!found_next)
146
- hashclr(next_sha1);
146
+ oidclr(next_oid);
147
148
flush_one_hunk(result, &ctx);
149
@@ -152,15 +152,15 @@ static int get_one_patchid(unsigned char *next_sha1, unsigned char *result,
152
153
static void generate_id_list(int stable)
154
{
155
- unsigned char sha1[20], n[20], result[20];
155
+ struct object_id oid, n, result;
156
int patchlen;
157
struct strbuf line_buf = STRBUF_INIT;
158
159
- hashclr(sha1);
159
+ oidclr(&oid);
160
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);
164
}
165
strbuf_release(&line_buf);
166
}