|  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
 | 
1470
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 int git_hash_ctx_init(git_hash_ctx *ctx)  | 
| 
16
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 {  | 
| 
17
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 	int error;  | 
| 
18
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
19
 | 
1470
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 	if ((error = git_hash_sha1_ctx_init(&ctx->sha1)) < 0)  | 
| 
20
 | 
  
0
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 		return error;  | 
| 
21
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
22
 | 
1470
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 	ctx->algo = GIT_HASH_ALGO_SHA1;  | 
| 
23
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
24
 | 
1470
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 	return 0;  | 
| 
25
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
26
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
27
 | 
1470
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 void git_hash_ctx_cleanup(git_hash_ctx *ctx)  | 
| 
28
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 {  | 
| 
29
 | 
1470
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 	switch (ctx->algo) {  | 
| 
30
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 		case GIT_HASH_ALGO_SHA1:  | 
| 
31
 | 
1470
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 			git_hash_sha1_ctx_cleanup(&ctx->sha1);  | 
| 
32
 | 
1470
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 			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
 | 
2994
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 int git_hash_update(git_hash_ctx *ctx, const void *data, size_t len)  | 
| 
50
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 {  | 
| 
51
 | 
2994
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 	switch (ctx->algo) {  | 
| 
52
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 		case GIT_HASH_ALGO_SHA1:  | 
| 
53
 | 
2994
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 			return git_hash_sha1_update(&ctx->sha1, data, len);  | 
| 
54
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 		default:  | 
| 
55
 | 
  
0
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 			assert(0);  | 
| 
56
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 			return -1;  | 
| 
57
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 	}  | 
| 
58
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
59
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
60
 | 
1459
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 int git_hash_final(git_oid *out, git_hash_ctx *ctx)  | 
| 
61
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 {  | 
| 
62
 | 
1459
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 	switch (ctx->algo) {  | 
| 
63
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 		case GIT_HASH_ALGO_SHA1:  | 
| 
64
 | 
1459
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 			return git_hash_sha1_final(out, &ctx->sha1);  | 
| 
65
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 		default:  | 
| 
66
 | 
  
0
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 			assert(0);  | 
| 
67
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 			return -1;  | 
| 
68
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 	}  | 
| 
69
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
70
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
71
 | 
117
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 int git_hash_buf(git_oid *out, const void *data, size_t len)  | 
| 
72
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 {  | 
| 
73
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 	git_hash_ctx ctx;  | 
| 
74
 | 
117
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 	int error = 0;  | 
| 
75
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
76
 | 
117
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 	if (git_hash_ctx_init(&ctx) < 0)  | 
| 
77
 | 
  
0
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 		return -1;  | 
| 
78
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
79
 | 
117
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 	if ((error = git_hash_update(&ctx, data, len)) >= 0)  | 
| 
80
 | 
117
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 		error = git_hash_final(out, &ctx);  | 
| 
81
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
82
 | 
117
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 	git_hash_ctx_cleanup(&ctx);  | 
| 
83
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 	  | 
| 
84
 | 
117
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 	return error;  | 
| 
85
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
86
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
87
 | 
994
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 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
 | 
994
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 	int error = 0;  | 
| 
92
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
93
 | 
994
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 	if (git_hash_ctx_init(&ctx) < 0)  | 
| 
94
 | 
  
0
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 		return -1;  | 
| 
95
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
96
 | 
2982
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 	for (i = 0; i < n; i++) {  | 
| 
97
 | 
1988
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 		if ((error = git_hash_update(&ctx, vec[i].data, vec[i].len)) < 0)  | 
| 
98
 | 
0
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 			goto done;  | 
| 
99
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 	}  | 
| 
100
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
101
 | 
994
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 	error = git_hash_final(out, &ctx);  | 
| 
102
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
103
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 done:  | 
| 
104
 | 
994
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 	git_hash_ctx_cleanup(&ctx);  | 
| 
105
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
106
 | 
994
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 	return error;  | 
| 
107
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  |