Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
git2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
git2
Commits
603bee07
Commit
603bee07
authored
Nov 12, 2012
by
Edward Thomson
Committed by
Edward Thomson
Nov 13, 2012
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove git_hash_ctx_new - callers now _ctx_init()
parent
d6fb0924
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
90 additions
and
175 deletions
+90
-175
src/filebuf.c
+10
-4
src/hash.c
+10
-10
src/hash.h
+3
-3
src/hash/hash_generic.c
+0
-17
src/hash/hash_generic.h
+3
-0
src/hash/hash_openssl.h
+2
-17
src/hash/hash_ppc.c
+0
-17
src/hash/hash_ppc.h
+3
-0
src/hash/hash_win32.c
+22
-35
src/indexer.c
+12
-12
src/odb.c
+7
-7
src/pack-objects.c
+9
-11
src/pack-objects.h
+1
-1
src/sha1.h
+0
-33
tests-clar/object/raw/hash.c
+8
-8
No files found.
src/filebuf.c
View file @
603bee07
...
...
@@ -108,8 +108,10 @@ void git_filebuf_cleanup(git_filebuf *file)
if
(
file
->
fd_is_open
&&
file
->
path_lock
&&
git_path_exists
(
file
->
path_lock
))
p_unlink
(
file
->
path_lock
);
if
(
file
->
digest
)
git_hash_ctx_free
(
file
->
digest
);
if
(
file
->
digest
)
{
git_hash_ctx_cleanup
(
file
->
digest
);
git__free
(
file
->
digest
);
}
if
(
file
->
buffer
)
git__free
(
file
->
buffer
);
...
...
@@ -221,8 +223,11 @@ int git_filebuf_open(git_filebuf *file, const char *path, int flags)
/* If we are hashing on-write, allocate a new hash context */
if
(
flags
&
GIT_FILEBUF_HASH_CONTENTS
)
{
file
->
digest
=
git_
hash_ctx_new
(
);
file
->
digest
=
git_
_calloc
(
1
,
sizeof
(
git_hash_ctx
)
);
GITERR_CHECK_ALLOC
(
file
->
digest
);
if
(
git_hash_ctx_init
(
file
->
digest
)
<
0
)
goto
cleanup
;
}
compression
=
flags
>>
GIT_FILEBUF_DEFLATE_SHIFT
;
...
...
@@ -299,7 +304,8 @@ int git_filebuf_hash(git_oid *oid, git_filebuf *file)
return
-
1
;
git_hash_final
(
oid
,
file
->
digest
);
git_hash_ctx_free
(
file
->
digest
);
git_hash_ctx_cleanup
(
file
->
digest
);
git__free
(
file
->
digest
);
file
->
digest
=
NULL
;
return
0
;
...
...
src/hash.c
View file @
603bee07
...
...
@@ -10,38 +10,38 @@
int
git_hash_buf
(
git_oid
*
out
,
const
void
*
data
,
size_t
len
)
{
git_hash_ctx
*
ctx
;
git_hash_ctx
ctx
;
int
error
=
0
;
if
(
(
ctx
=
git_hash_ctx_new
())
==
NULL
)
if
(
git_hash_ctx_init
(
&
ctx
)
<
0
)
return
-
1
;
if
((
error
=
git_hash_update
(
ctx
,
data
,
len
))
>=
0
)
error
=
git_hash_final
(
out
,
ctx
);
if
((
error
=
git_hash_update
(
&
ctx
,
data
,
len
))
>=
0
)
error
=
git_hash_final
(
out
,
&
ctx
);
git_hash_ctx_
free
(
ctx
);
git_hash_ctx_
cleanup
(
&
ctx
);
return
error
;
}
int
git_hash_vec
(
git_oid
*
out
,
git_buf_vec
*
vec
,
size_t
n
)
{
git_hash_ctx
*
ctx
;
git_hash_ctx
ctx
;
size_t
i
;
int
error
=
0
;
if
(
(
ctx
=
git_hash_ctx_new
())
==
NULL
)
if
(
git_hash_ctx_init
(
&
ctx
)
<
0
)
return
-
1
;
for
(
i
=
0
;
i
<
n
;
i
++
)
{
if
((
error
=
git_hash_update
(
ctx
,
vec
[
i
].
data
,
vec
[
i
].
len
))
<
0
)
if
((
error
=
git_hash_update
(
&
ctx
,
vec
[
i
].
data
,
vec
[
i
].
len
))
<
0
)
goto
done
;
}
error
=
git_hash_final
(
out
,
ctx
);
error
=
git_hash_final
(
out
,
&
ctx
);
done:
git_hash_ctx_
free
(
ctx
);
git_hash_ctx_
cleanup
(
&
ctx
);
return
error
;
}
src/hash.h
View file @
603bee07
...
...
@@ -12,6 +12,9 @@
typedef
struct
git_hash_prov
git_hash_prov
;
typedef
struct
git_hash_ctx
git_hash_ctx
;
int
git_hash_ctx_init
(
git_hash_ctx
*
ctx
);
void
git_hash_ctx_cleanup
(
git_hash_ctx
*
ctx
);
#if defined(OPENSSL_SHA1)
# include "hash/hash_openssl.h"
#elif defined(WIN32_SHA1)
...
...
@@ -27,9 +30,6 @@ typedef struct {
size_t
len
;
}
git_buf_vec
;
git_hash_ctx
*
git_hash_ctx_new
(
void
);
void
git_hash_ctx_free
(
git_hash_ctx
*
ctx
);
int
git_hash_init
(
git_hash_ctx
*
c
);
int
git_hash_update
(
git_hash_ctx
*
c
,
const
void
*
data
,
size_t
len
);
int
git_hash_final
(
git_oid
*
out
,
git_hash_ctx
*
c
);
...
...
src/hash/hash_generic.c
View file @
603bee07
...
...
@@ -221,18 +221,6 @@ static void hash__block(git_hash_ctx *ctx, const unsigned int *data)
ctx
->
H
[
4
]
+=
E
;
}
git_hash_ctx
*
git_hash_ctx_new
(
void
)
{
git_hash_ctx
*
ctx
=
git__malloc
(
sizeof
(
git_hash_ctx
));
if
(
!
ctx
)
return
NULL
;
git_hash_init
(
ctx
);
return
ctx
;
}
int
git_hash_init
(
git_hash_ctx
*
ctx
)
{
ctx
->
size
=
0
;
...
...
@@ -298,8 +286,3 @@ int git_hash_final(git_oid *out, git_hash_ctx *ctx)
return
0
;
}
void
git_hash_ctx_free
(
git_hash_ctx
*
ctx
)
{
if
(
ctx
)
git__free
(
ctx
);
}
src/hash/hash_generic.h
View file @
603bee07
...
...
@@ -16,4 +16,7 @@ struct git_hash_ctx {
unsigned
int
W
[
16
];
};
#define git_hash_ctx_init(ctx) git_hash_init(ctx)
#define git_hash_ctx_cleanup(ctx)
#endif
/* INCLUDE_hash_generic_h__ */
src/hash/hash_openssl.h
View file @
603bee07
...
...
@@ -16,23 +16,8 @@ struct git_hash_ctx {
SHA_CTX
c
;
};
GIT_INLINE
(
git_hash_ctx
*
)
git_hash_ctx_new
(
void
)
{
git_hash_ctx
*
ctx
=
git__malloc
(
sizeof
(
git_hash_ctx
));
if
(
!
ctx
)
return
NULL
;
SHA1_Init
(
&
ctx
->
c
);
return
ctx
;
}
GIT_INLINE
(
void
)
git_hash_ctx_free
(
git_hash_ctx
*
ctx
)
{
if
(
ctx
)
git__free
(
ctx
);
}
#define git_hash_ctx_init(ctx) git_hash_init(ctx)
#define git_hash_ctx_cleanup(ctx)
GIT_INLINE
(
int
)
git_hash_init
(
git_hash_ctx
*
ctx
)
{
...
...
src/hash/hash_ppc.c
View file @
603bee07
...
...
@@ -14,18 +14,6 @@
extern
void
hash_ppc_core
(
uint32_t
*
hash
,
const
unsigned
char
*
p
,
unsigned
int
nblocks
);
git_hash_ctx
*
git_hash_ctx_new
(
void
)
{
git_hash_ctx
*
ctx
=
git__malloc
(
sizeof
(
git_hash_ctx
));
if
(
!
ctx
)
return
NULL
;
git_hash_init
(
ctx
);
return
ctx
;
}
int
git_hash_init
(
git_hash_ctx
*
c
)
{
c
->
hash
[
0
]
=
0x67452301
;
...
...
@@ -84,8 +72,3 @@ int git_hash_final(git_oid *oid, git_hash_ctx *c)
return
0
;
}
void
git_hash_ctx_free
(
git_hash_ctx
*
ctx
)
{
if
(
ctx
)
git__free
(
ctx
);
}
src/hash/hash_ppc.h
View file @
603bee07
...
...
@@ -20,4 +20,7 @@ struct git_hash_ctx {
}
buf
;
};
#define git_hash_ctx_init(ctx) git_hash_init(ctx)
#define git_hash_ctx_cleanup(ctx)
#endif
/* INCLUDE_hash_generic_h__ */
src/hash/hash_win32.c
View file @
603bee07
...
...
@@ -100,22 +100,12 @@ static int hash_win32_prov_init(git_hash_prov *prov)
/* CryptoAPI: available in Windows XP and newer */
GIT_INLINE
(
git_hash_ctx
*
)
hash_ctx_cryptoapi_new
(
git_hash_prov
*
prov
)
GIT_INLINE
(
int
)
hash_ctx_cryptoapi_init
(
git_hash_ctx
*
ctx
,
git_hash_prov
*
prov
)
{
git_hash_ctx
*
ctx
;
if
((
ctx
=
git__calloc
(
1
,
sizeof
(
git_hash_ctx
)))
==
NULL
)
return
NULL
;
ctx
->
type
=
CRYPTOAPI
;
ctx
->
prov
=
prov
;
if
(
git_hash_init
(
ctx
)
<
0
)
{
git__free
(
ctx
);
return
NULL
;
}
return
ctx
;
return
git_hash_init
(
ctx
);
}
GIT_INLINE
(
int
)
hash_cryptoapi_init
(
git_hash_ctx
*
ctx
)
...
...
@@ -158,7 +148,7 @@ GIT_INLINE(int) hash_cryptoapi_final(git_oid *out, git_hash_ctx *ctx)
return
error
;
}
GIT_INLINE
(
void
)
hash_c
ryptoapi_free
(
git_hash_ctx
*
ctx
)
GIT_INLINE
(
void
)
hash_c
tx_cryptoapi_cleanup
(
git_hash_ctx
*
ctx
)
{
if
(
ctx
->
ctx
.
cryptoapi
.
valid
)
CryptDestroyHash
(
ctx
->
ctx
.
cryptoapi
.
hash_handle
);
...
...
@@ -166,24 +156,20 @@ GIT_INLINE(void) hash_cryptoapi_free(git_hash_ctx *ctx)
/* CNG: Available in Windows Server 2008 and newer */
GIT_INLINE
(
git_hash_ctx
*
)
hash_ctx_cng_new
(
git_hash_prov
*
prov
)
GIT_INLINE
(
int
)
hash_ctx_cng_init
(
git_hash_ctx
*
ctx
,
git_hash_prov
*
prov
)
{
git_hash_ctx
*
ctx
;
if
((
ctx
=
git__calloc
(
1
,
sizeof
(
git_hash_ctx
)))
==
NULL
||
(
ctx
->
ctx
.
cng
.
hash_object
=
git__malloc
(
prov
->
prov
.
cng
.
hash_object_size
))
==
NULL
)
return
NULL
;
if
((
ctx
->
ctx
.
cng
.
hash_object
=
git__malloc
(
prov
->
prov
.
cng
.
hash_object_size
))
==
NULL
)
return
-
1
;
if
(
prov
->
prov
.
cng
.
create_hash
(
prov
->
prov
.
cng
.
handle
,
&
ctx
->
ctx
.
cng
.
hash_handle
,
ctx
->
ctx
.
cng
.
hash_object
,
prov
->
prov
.
cng
.
hash_object_size
,
NULL
,
0
,
0
)
<
0
)
{
git__free
(
ctx
->
ctx
.
cng
.
hash_object
);
git__free
(
ctx
);
return
NULL
;
return
-
1
;
}
ctx
->
type
=
CNG
;
ctx
->
prov
=
prov
;
return
ctx
;
return
0
;
}
GIT_INLINE
(
int
)
hash_cng_init
(
git_hash_ctx
*
ctx
)
...
...
@@ -220,7 +206,7 @@ GIT_INLINE(int) hash_cng_final(git_oid *out, git_hash_ctx *ctx)
return
0
;
}
GIT_INLINE
(
void
)
hash_c
ng_free
(
git_hash_ctx
*
ctx
)
GIT_INLINE
(
void
)
hash_c
tx_cng_cleanup
(
git_hash_ctx
*
ctx
)
{
ctx
->
prov
->
prov
.
cng
.
destroy_hash
(
ctx
->
ctx
.
cng
.
hash_handle
);
git__free
(
ctx
->
ctx
.
cng
.
hash_object
);
...
...
@@ -228,20 +214,24 @@ GIT_INLINE(void) hash_cng_free(git_hash_ctx *ctx)
/* Indirection between CryptoAPI and CNG */
git_hash_ctx
*
git_hash_ctx_new
(
)
int
git_hash_ctx_init
(
git_hash_ctx
*
ctx
)
{
git_global_st
*
global_state
;
git_hash_prov
*
hash_prov
;
assert
(
ctx
);
memset
(
ctx
,
0x0
,
sizeof
(
git_hash_ctx
));
if
((
global_state
=
git__global_state
())
==
NULL
)
return
NULL
;
return
-
1
;
hash_prov
=
&
global_state
->
hash_prov
;
if
(
hash_prov
->
type
==
INVALID
&&
hash_win32_prov_init
(
hash_prov
)
<
0
)
return
NULL
;
return
-
1
;
return
(
hash_prov
->
type
==
CNG
)
?
hash_ctx_cng_
new
(
hash_prov
)
:
hash_ctx_cryptoapi_new
(
hash_prov
);
return
(
hash_prov
->
type
==
CNG
)
?
hash_ctx_cng_
init
(
ctx
,
hash_prov
)
:
hash_ctx_cryptoapi_init
(
ctx
,
hash_prov
);
}
int
git_hash_init
(
git_hash_ctx
*
ctx
)
...
...
@@ -262,15 +252,12 @@ int git_hash_final(git_oid *out, git_hash_ctx *ctx)
return
(
ctx
->
type
==
CNG
)
?
hash_cng_final
(
out
,
ctx
)
:
hash_cryptoapi_final
(
out
,
ctx
);
}
void
git_hash_ctx_
free
(
git_hash_ctx
*
ctx
)
void
git_hash_ctx_
cleanup
(
git_hash_ctx
*
ctx
)
{
if
(
ctx
==
NULL
)
return
;
assert
(
ctx
);
if
(
ctx
->
type
==
CNG
)
hash_cng_free
(
ctx
);
else
hash_cryptoapi_free
(
ctx
);
git__free
(
ctx
);
hash_ctx_cng_cleanup
(
ctx
);
else
if
(
ctx
->
type
==
CRYPTOAPI
)
hash_ctx_cryptoapi_cleanup
(
ctx
);
}
src/indexer.c
View file @
603bee07
...
...
@@ -461,10 +461,10 @@ int git_indexer_stream_finalize(git_indexer_stream *idx, git_transfer_progress *
struct
entry
*
entry
;
void
*
packfile_hash
;
git_oid
file_hash
;
git_hash_ctx
*
ctx
;
git_hash_ctx
ctx
;
ctx
=
git_hash_ctx_new
();
GITERR_CHECK_ALLOC
(
ctx
)
;
if
(
git_hash_ctx_init
(
&
ctx
)
<
0
)
return
-
1
;
/* Test for this before resolve_deltas(), as it plays with idx->off */
if
(
idx
->
off
<
idx
->
pack
->
mwf
.
size
-
GIT_OID_RAWSZ
)
{
...
...
@@ -506,9 +506,9 @@ int git_indexer_stream_finalize(git_indexer_stream *idx, git_transfer_progress *
/* Write out the object names (SHA-1 hashes) */
git_vector_foreach
(
&
idx
->
objects
,
i
,
entry
)
{
git_filebuf_write
(
&
idx
->
index_file
,
&
entry
->
oid
,
sizeof
(
git_oid
));
git_hash_update
(
ctx
,
&
entry
->
oid
,
GIT_OID_RAWSZ
);
git_hash_update
(
&
ctx
,
&
entry
->
oid
,
GIT_OID_RAWSZ
);
}
git_hash_final
(
&
idx
->
hash
,
ctx
);
git_hash_final
(
&
idx
->
hash
,
&
ctx
);
/* Write out the CRC32 values */
git_vector_foreach
(
&
idx
->
objects
,
i
,
entry
)
{
...
...
@@ -583,7 +583,7 @@ on_error:
p_close
(
idx
->
pack
->
mwf
.
fd
);
git_filebuf_cleanup
(
&
idx
->
index_file
);
git_buf_free
(
&
filename
);
git_hash_ctx_
free
(
ctx
);
git_hash_ctx_
cleanup
(
&
ctx
);
return
-
1
;
}
...
...
@@ -684,10 +684,10 @@ int git_indexer_write(git_indexer *idx)
struct
entry
*
entry
;
void
*
packfile_hash
;
git_oid
file_hash
;
git_hash_ctx
*
ctx
;
git_hash_ctx
ctx
;
ctx
=
git_hash_ctx_new
();
GITERR_CHECK_ALLOC
(
ctx
)
;
if
(
git_hash_ctx_init
(
&
ctx
)
<
0
)
return
-
1
;
git_vector_sort
(
&
idx
->
objects
);
...
...
@@ -719,11 +719,11 @@ int git_indexer_write(git_indexer *idx)
/* Write out the object names (SHA-1 hashes) */
git_vector_foreach
(
&
idx
->
objects
,
i
,
entry
)
{
if
((
error
=
git_filebuf_write
(
&
idx
->
file
,
&
entry
->
oid
,
sizeof
(
git_oid
)))
<
0
||
(
error
=
git_hash_update
(
ctx
,
&
entry
->
oid
,
GIT_OID_RAWSZ
))
<
0
)
(
error
=
git_hash_update
(
&
ctx
,
&
entry
->
oid
,
GIT_OID_RAWSZ
))
<
0
)
goto
cleanup
;
}
if
((
error
=
git_hash_final
(
&
idx
->
hash
,
ctx
))
<
0
)
if
((
error
=
git_hash_final
(
&
idx
->
hash
,
&
ctx
))
<
0
)
goto
cleanup
;
/* Write out the CRC32 values */
...
...
@@ -802,7 +802,7 @@ cleanup:
if
(
error
<
0
)
git_filebuf_cleanup
(
&
idx
->
file
);
git_buf_free
(
&
filename
);
git_hash_ctx_
free
(
ctx
);
git_hash_ctx_
cleanup
(
&
ctx
);
return
error
;
}
...
...
src/odb.c
View file @
603bee07
...
...
@@ -117,7 +117,7 @@ int git_odb__hashfd(git_oid *out, git_file fd, size_t size, git_otype type)
{
int
hdr_len
;
char
hdr
[
64
],
buffer
[
2048
];
git_hash_ctx
*
ctx
;
git_hash_ctx
ctx
;
ssize_t
read_len
=
0
;
int
error
=
0
;
...
...
@@ -126,16 +126,16 @@ int git_odb__hashfd(git_oid *out, git_file fd, size_t size, git_otype type)
return
-
1
;
}
ctx
=
git_hash_ctx_new
();
GITERR_CHECK_ALLOC
(
ctx
)
;
if
((
error
=
git_hash_ctx_init
(
&
ctx
))
<
0
)
return
-
1
;
hdr_len
=
format_object_header
(
hdr
,
sizeof
(
hdr
),
size
,
type
);
if
((
error
=
git_hash_update
(
ctx
,
hdr
,
hdr_len
))
<
0
)
if
((
error
=
git_hash_update
(
&
ctx
,
hdr
,
hdr_len
))
<
0
)
goto
done
;
while
(
size
>
0
&&
(
read_len
=
p_read
(
fd
,
buffer
,
sizeof
(
buffer
)))
>
0
)
{
if
((
error
=
git_hash_update
(
ctx
,
buffer
,
read_len
))
<
0
)
if
((
error
=
git_hash_update
(
&
ctx
,
buffer
,
read_len
))
<
0
)
goto
done
;
size
-=
read_len
;
...
...
@@ -152,10 +152,10 @@ int git_odb__hashfd(git_oid *out, git_file fd, size_t size, git_otype type)
return
-
1
;
}
error
=
git_hash_final
(
out
,
ctx
);
error
=
git_hash_final
(
out
,
&
ctx
);
done:
git_hash_ctx_
free
(
ctx
);
git_hash_ctx_
cleanup
(
&
ctx
);
return
error
;
}
...
...
src/pack-objects.c
View file @
603bee07
...
...
@@ -103,7 +103,7 @@ int git_packbuilder_new(git_packbuilder **out, git_repository *repo)
*
out
=
NULL
;
pb
=
git__calloc
(
sizeof
(
*
pb
),
1
);
pb
=
git__calloc
(
1
,
sizeof
(
*
pb
)
);
GITERR_CHECK_ALLOC
(
pb
);
pb
->
object_ix
=
git_oidmap_alloc
();
...
...
@@ -113,9 +113,8 @@ int git_packbuilder_new(git_packbuilder **out, git_repository *repo)
pb
->
repo
=
repo
;
pb
->
nr_threads
=
1
;
/* do not spawn any thread by default */
pb
->
ctx
=
git_hash_ctx_new
();
if
(
!
pb
->
ctx
||
if
(
git_hash_ctx_init
(
&
pb
->
ctx
)
<
0
||
git_repository_odb
(
&
pb
->
odb
,
repo
)
<
0
||
packbuilder_config
(
pb
)
<
0
)
goto
on_error
;
...
...
@@ -297,12 +296,12 @@ static int write_object(git_buf *buf, git_packbuilder *pb, git_pobject *po)
if
(
git_buf_put
(
buf
,
(
char
*
)
hdr
,
hdr_len
)
<
0
)
goto
on_error
;
if
(
git_hash_update
(
pb
->
ctx
,
hdr
,
hdr_len
)
<
0
)
if
(
git_hash_update
(
&
pb
->
ctx
,
hdr
,
hdr_len
)
<
0
)
goto
on_error
;
if
(
type
==
GIT_OBJ_REF_DELTA
)
{
if
(
git_buf_put
(
buf
,
(
char
*
)
po
->
delta
->
id
.
id
,
GIT_OID_RAWSZ
)
<
0
||
git_hash_update
(
pb
->
ctx
,
po
->
delta
->
id
.
id
,
GIT_OID_RAWSZ
)
<
0
)
git_hash_update
(
&
pb
->
ctx
,
po
->
delta
->
id
.
id
,
GIT_OID_RAWSZ
)
<
0
)
goto
on_error
;
}
...
...
@@ -319,7 +318,7 @@ static int write_object(git_buf *buf, git_packbuilder *pb, git_pobject *po)
}
if
(
git_buf_put
(
buf
,
data
,
size
)
<
0
||
git_hash_update
(
pb
->
ctx
,
data
,
size
)
<
0
)
git_hash_update
(
&
pb
->
ctx
,
data
,
size
)
<
0
)
goto
on_error
;
if
(
po
->
delta_data
)
...
...
@@ -571,7 +570,7 @@ static int write_pack(git_packbuilder *pb,
if
(
cb
(
&
ph
,
sizeof
(
ph
),
data
)
<
0
)
goto
on_error
;
if
(
git_hash_update
(
pb
->
ctx
,
&
ph
,
sizeof
(
ph
))
<
0
)
if
(
git_hash_update
(
&
pb
->
ctx
,
&
ph
,
sizeof
(
ph
))
<
0
)
goto
on_error
;
pb
->
nr_remaining
=
pb
->
nr_objects
;
...
...
@@ -592,7 +591,7 @@ static int write_pack(git_packbuilder *pb,
git__free
(
write_order
);
git_buf_free
(
&
buf
);
if
(
git_hash_final
(
&
pb
->
pack_oid
,
pb
->
ctx
)
<
0
)
if
(
git_hash_final
(
&
pb
->
pack_oid
,
&
pb
->
ctx
)
<
0
)
goto
on_error
;
return
cb
(
pb
->
pack_oid
.
id
,
GIT_OID_RAWSZ
,
data
);
...
...
@@ -1319,14 +1318,13 @@ void git_packbuilder_free(git_packbuilder *pb)
if
(
pb
->
odb
)
git_odb_free
(
pb
->
odb
);
if
(
pb
->
ctx
)
git_hash_ctx_free
(
pb
->
ctx
);
if
(
pb
->
object_ix
)
git_oidmap_free
(
pb
->
object_ix
);
if
(
pb
->
object_list
)
git__free
(
pb
->
object_list
);
git_hash_ctx_cleanup
(
&
pb
->
ctx
);
git__free
(
pb
);
}
src/pack-objects.h
View file @
603bee07
...
...
@@ -52,7 +52,7 @@ struct git_packbuilder {
git_repository
*
repo
;
/* associated repository */
git_odb
*
odb
;
/* associated object database */
git_hash_ctx
*
ctx
;
git_hash_ctx
ctx
;
uint32_t
nr_objects
,
nr_alloc
,
...
...
src/sha1.h
deleted
100644 → 0
View file @
d6fb0924
/*
* Copyright (C) 2009-2012 the libgit2 contributors
*
* This file is part of libgit2, distributed under the GNU GPL v2 with
* a Linking Exception. For full terms see the included COPYING file.
*/
#ifndef INCLUDE_sha1_h__
#define INCLUDE_sha1_h__
#ifdef OPENSSL_SHA
# include <openssl/sha.h>
#else
typedef
struct
{
unsigned
long
long
size
;
unsigned
int
H
[
5
];
unsigned
int
W
[
16
];
}
blk_SHA_CTX
;
void
git__blk_SHA1_Init
(
blk_SHA_CTX
*
ctx
);
void
git__blk_SHA1_Update
(
blk_SHA_CTX
*
ctx
,
const
void
*
dataIn
,
size_t
len
);
void
git__blk_SHA1_Final
(
unsigned
char
hashout
[
20
],
blk_SHA_CTX
*
ctx
);
#define SHA_CTX blk_SHA_CTX
#define SHA1_Init git__blk_SHA1_Init
#define SHA1_Update git__blk_SHA1_Update
#define SHA1_Final git__blk_SHA1_Final
#endif // OPENSSL_SHA
#endif
tests-clar/object/raw/hash.c
View file @
603bee07
...
...
@@ -23,25 +23,25 @@ static char *bye_text = "bye world\n";
void
test_object_raw_hash__hash_by_blocks
(
void
)
{
git_hash_ctx
*
ctx
;
git_hash_ctx
ctx
;
git_oid
id1
,
id2
;
cl_assert
((
ctx
=
git_hash_ctx_new
())
!=
NULL
);
cl_git_pass
(
git_hash_ctx_init
(
&
ctx
)
);
/* should already be init'd */
cl_git_pass
(
git_hash_update
(
ctx
,
hello_text
,
strlen
(
hello_text
)));
cl_git_pass
(
git_hash_final
(
&
id2
,
ctx
));
cl_git_pass
(
git_hash_update
(
&
ctx
,
hello_text
,
strlen
(
hello_text
)));
cl_git_pass
(
git_hash_final
(
&
id2
,
&
ctx
));
cl_git_pass
(
git_oid_fromstr
(
&
id1
,
hello_id
));
cl_assert
(
git_oid_cmp
(
&
id1
,
&
id2
)
==
0
);
/* reinit should permit reuse */
cl_git_pass
(
git_hash_init
(
ctx
));
cl_git_pass
(
git_hash_update
(
ctx
,
bye_text
,
strlen
(
bye_text
)));
cl_git_pass
(
git_hash_final
(
&
id2
,
ctx
));
cl_git_pass
(
git_hash_init
(
&
ctx
));
cl_git_pass
(
git_hash_update
(
&
ctx
,
bye_text
,
strlen
(
bye_text
)));
cl_git_pass
(
git_hash_final
(
&
id2
,
&
ctx
));
cl_git_pass
(
git_oid_fromstr
(
&
id1
,
bye_id
));
cl_assert
(
git_oid_cmp
(
&
id1
,
&
id2
)
==
0
);
git_hash_ctx_
free
(
ctx
);
git_hash_ctx_
cleanup
(
&
ctx
);
}
void
test_object_raw_hash__hash_buffer_in_single_call
(
void
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment