| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
/* |
|
2
|
|
|
|
|
|
|
* Copyright (C) the libgit2 contributors. All rights reserved. |
|
3
|
|
|
|
|
|
|
* |
|
4
|
|
|
|
|
|
|
* This file is part of libgit2, distributed under the GNU GPL v2 with |
|
5
|
|
|
|
|
|
|
* a Linking Exception. For full terms see the included COPYING file. |
|
6
|
|
|
|
|
|
|
*/ |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
#include "hash.h" |
|
9
|
|
|
|
|
|
|
|
|
10
|
86
|
|
|
|
|
|
int git_hash_global_init(void) |
|
11
|
|
|
|
|
|
|
{ |
|
12
|
86
|
|
|
|
|
|
return git_hash_sha1_global_init(); |
|
13
|
|
|
|
|
|
|
} |
|
14
|
|
|
|
|
|
|
|
|
15
|
1398
|
|
|
|
|
|
int git_hash_ctx_init(git_hash_ctx *ctx) |
|
16
|
|
|
|
|
|
|
{ |
|
17
|
|
|
|
|
|
|
int error; |
|
18
|
|
|
|
|
|
|
|
|
19
|
1398
|
50
|
|
|
|
|
if ((error = git_hash_sha1_ctx_init(&ctx->sha1)) < 0) |
|
20
|
0
|
|
|
|
|
|
return error; |
|
21
|
|
|
|
|
|
|
|
|
22
|
1398
|
|
|
|
|
|
ctx->algo = GIT_HASH_ALGO_SHA1; |
|
23
|
|
|
|
|
|
|
|
|
24
|
1398
|
|
|
|
|
|
return 0; |
|
25
|
|
|
|
|
|
|
} |
|
26
|
|
|
|
|
|
|
|
|
27
|
1398
|
|
|
|
|
|
void git_hash_ctx_cleanup(git_hash_ctx *ctx) |
|
28
|
|
|
|
|
|
|
{ |
|
29
|
1398
|
50
|
|
|
|
|
switch (ctx->algo) { |
|
30
|
|
|
|
|
|
|
case GIT_HASH_ALGO_SHA1: |
|
31
|
1398
|
|
|
|
|
|
git_hash_sha1_ctx_cleanup(&ctx->sha1); |
|
32
|
1398
|
|
|
|
|
|
return; |
|
33
|
|
|
|
|
|
|
default: |
|
34
|
0
|
|
|
|
|
|
assert(0); |
|
35
|
|
|
|
|
|
|
} |
|
36
|
|
|
|
|
|
|
} |
|
37
|
|
|
|
|
|
|
|
|
38
|
47
|
|
|
|
|
|
int git_hash_init(git_hash_ctx *ctx) |
|
39
|
|
|
|
|
|
|
{ |
|
40
|
47
|
50
|
|
|
|
|
switch (ctx->algo) { |
|
41
|
|
|
|
|
|
|
case GIT_HASH_ALGO_SHA1: |
|
42
|
47
|
|
|
|
|
|
return git_hash_sha1_init(&ctx->sha1); |
|
43
|
|
|
|
|
|
|
default: |
|
44
|
0
|
|
|
|
|
|
assert(0); |
|
45
|
|
|
|
|
|
|
return -1; |
|
46
|
|
|
|
|
|
|
} |
|
47
|
|
|
|
|
|
|
} |
|
48
|
|
|
|
|
|
|
|
|
49
|
2875
|
|
|
|
|
|
int git_hash_update(git_hash_ctx *ctx, const void *data, size_t len) |
|
50
|
|
|
|
|
|
|
{ |
|
51
|
2875
|
50
|
|
|
|
|
switch (ctx->algo) { |
|
52
|
|
|
|
|
|
|
case GIT_HASH_ALGO_SHA1: |
|
53
|
2875
|
|
|
|
|
|
return git_hash_sha1_update(&ctx->sha1, data, len); |
|
54
|
|
|
|
|
|
|
default: |
|
55
|
0
|
|
|
|
|
|
assert(0); |
|
56
|
|
|
|
|
|
|
return -1; |
|
57
|
|
|
|
|
|
|
} |
|
58
|
|
|
|
|
|
|
} |
|
59
|
|
|
|
|
|
|
|
|
60
|
1387
|
|
|
|
|
|
int git_hash_final(git_oid *out, git_hash_ctx *ctx) |
|
61
|
|
|
|
|
|
|
{ |
|
62
|
1387
|
50
|
|
|
|
|
switch (ctx->algo) { |
|
63
|
|
|
|
|
|
|
case GIT_HASH_ALGO_SHA1: |
|
64
|
1387
|
|
|
|
|
|
return git_hash_sha1_final(out, &ctx->sha1); |
|
65
|
|
|
|
|
|
|
default: |
|
66
|
0
|
|
|
|
|
|
assert(0); |
|
67
|
|
|
|
|
|
|
return -1; |
|
68
|
|
|
|
|
|
|
} |
|
69
|
|
|
|
|
|
|
} |
|
70
|
|
|
|
|
|
|
|
|
71
|
98
|
|
|
|
|
|
int git_hash_buf(git_oid *out, const void *data, size_t len) |
|
72
|
|
|
|
|
|
|
{ |
|
73
|
|
|
|
|
|
|
git_hash_ctx ctx; |
|
74
|
98
|
|
|
|
|
|
int error = 0; |
|
75
|
|
|
|
|
|
|
|
|
76
|
98
|
50
|
|
|
|
|
if (git_hash_ctx_init(&ctx) < 0) |
|
77
|
0
|
|
|
|
|
|
return -1; |
|
78
|
|
|
|
|
|
|
|
|
79
|
98
|
50
|
|
|
|
|
if ((error = git_hash_update(&ctx, data, len)) >= 0) |
|
80
|
98
|
|
|
|
|
|
error = git_hash_final(out, &ctx); |
|
81
|
|
|
|
|
|
|
|
|
82
|
98
|
|
|
|
|
|
git_hash_ctx_cleanup(&ctx); |
|
83
|
|
|
|
|
|
|
|
|
84
|
98
|
|
|
|
|
|
return error; |
|
85
|
|
|
|
|
|
|
} |
|
86
|
|
|
|
|
|
|
|
|
87
|
970
|
|
|
|
|
|
int git_hash_vec(git_oid *out, git_buf_vec *vec, size_t n) |
|
88
|
|
|
|
|
|
|
{ |
|
89
|
|
|
|
|
|
|
git_hash_ctx ctx; |
|
90
|
|
|
|
|
|
|
size_t i; |
|
91
|
970
|
|
|
|
|
|
int error = 0; |
|
92
|
|
|
|
|
|
|
|
|
93
|
970
|
50
|
|
|
|
|
if (git_hash_ctx_init(&ctx) < 0) |
|
94
|
0
|
|
|
|
|
|
return -1; |
|
95
|
|
|
|
|
|
|
|
|
96
|
2910
|
100
|
|
|
|
|
for (i = 0; i < n; i++) { |
|
97
|
1940
|
50
|
|
|
|
|
if ((error = git_hash_update(&ctx, vec[i].data, vec[i].len)) < 0) |
|
98
|
0
|
|
|
|
|
|
goto done; |
|
99
|
|
|
|
|
|
|
} |
|
100
|
|
|
|
|
|
|
|
|
101
|
970
|
|
|
|
|
|
error = git_hash_final(out, &ctx); |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
done: |
|
104
|
970
|
|
|
|
|
|
git_hash_ctx_cleanup(&ctx); |
|
105
|
|
|
|
|
|
|
|
|
106
|
970
|
|
|
|
|
|
return error; |
|
107
|
|
|
|
|
|
|
} |