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
3b52e5f5
Unverified
Commit
3b52e5f5
authored
Apr 18, 2022
by
Edward Thomson
Committed by
GitHub
Apr 18, 2022
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #6265 from libgit2/ethomson/sha256_two
sha256: refactoring in preparation for sha256
parents
63970244
f8821405
Show whitespace changes
Inline
Side-by-side
Showing
22 changed files
with
148 additions
and
119 deletions
+148
-119
fuzzers/packfile_fuzzer.c
+1
-1
src/libgit2/commit_graph.c
+20
-17
src/libgit2/commit_graph.h
+1
-1
src/libgit2/index.c
+6
-6
src/libgit2/indexer.c
+2
-2
src/libgit2/iterator.c
+3
-3
src/libgit2/midx.c
+18
-15
src/libgit2/midx.h
+2
-1
src/libgit2/oid.c
+2
-21
src/libgit2/oid.h
+35
-2
src/libgit2/oidmap.c
+1
-1
src/libgit2/pack.c
+24
-18
src/libgit2/pack.h
+2
-1
src/libgit2/remote.c
+1
-1
src/libgit2/tree-cache.c
+1
-1
src/libgit2/tree.c
+13
-20
src/libgit2/tree.h
+1
-1
tests/libgit2/iterator/tree.c
+1
-1
tests/libgit2/object/raw/hash.c
+8
-3
tests/libgit2/object/raw/short.c
+4
-1
tests/libgit2/object/tree/parse.c
+1
-1
tests/libgit2/pack/packbuilder.c
+1
-1
No files found.
fuzzers/packfile_fuzzer.c
View file @
3b52e5f5
...
@@ -94,7 +94,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
...
@@ -94,7 +94,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
fprintf
(
stderr
,
"Failed to compute the SHA1 hash
\n
"
);
fprintf
(
stderr
,
"Failed to compute the SHA1 hash
\n
"
);
abort
();
abort
();
}
}
if
(
git_indexer_append
(
indexer
,
&
oid
,
sizeof
(
oid
)
,
&
stats
)
<
0
)
{
if
(
git_indexer_append
(
indexer
,
&
oid
.
id
,
GIT_OID_RAWSZ
,
&
stats
)
<
0
)
{
goto
cleanup
;
goto
cleanup
;
}
}
}
}
...
...
src/libgit2/commit_graph.c
View file @
3b52e5f5
...
@@ -138,7 +138,7 @@ static int commit_graph_parse_oid_lookup(
...
@@ -138,7 +138,7 @@ static int commit_graph_parse_oid_lookup(
struct
git_commit_graph_chunk
*
chunk_oid_lookup
)
struct
git_commit_graph_chunk
*
chunk_oid_lookup
)
{
{
uint32_t
i
;
uint32_t
i
;
git_oid
*
oid
,
*
prev_oid
,
zero_oid
=
{{
0
}
};
unsigned
char
*
oid
,
*
prev_oid
,
zero_oid
[
GIT_OID_RAWSZ
]
=
{
0
};
if
(
chunk_oid_lookup
->
offset
==
0
)
if
(
chunk_oid_lookup
->
offset
==
0
)
return
commit_graph_error
(
"missing OID Lookup chunk"
);
return
commit_graph_error
(
"missing OID Lookup chunk"
);
...
@@ -147,10 +147,10 @@ static int commit_graph_parse_oid_lookup(
...
@@ -147,10 +147,10 @@ static int commit_graph_parse_oid_lookup(
if
(
chunk_oid_lookup
->
length
!=
file
->
num_commits
*
GIT_OID_RAWSZ
)
if
(
chunk_oid_lookup
->
length
!=
file
->
num_commits
*
GIT_OID_RAWSZ
)
return
commit_graph_error
(
"OID Lookup chunk has wrong length"
);
return
commit_graph_error
(
"OID Lookup chunk has wrong length"
);
file
->
oid_lookup
=
oid
=
(
git_oid
*
)(
data
+
chunk_oid_lookup
->
offset
);
file
->
oid_lookup
=
oid
=
(
unsigned
char
*
)(
data
+
chunk_oid_lookup
->
offset
);
prev_oid
=
&
zero_oid
;
prev_oid
=
zero_oid
;
for
(
i
=
0
;
i
<
file
->
num_commits
;
++
i
,
++
oid
)
{
for
(
i
=
0
;
i
<
file
->
num_commits
;
++
i
,
oid
+=
GIT_OID_RAWSZ
)
{
if
(
git_oid_cmp
(
prev_oid
,
oid
)
>=
0
)
if
(
git_oid_
raw_
cmp
(
prev_oid
,
oid
)
>=
0
)
return
commit_graph_error
(
"OID Lookup index is non-monotonic"
);
return
commit_graph_error
(
"OID Lookup index is non-monotonic"
);
prev_oid
=
oid
;
prev_oid
=
oid
;
}
}
...
@@ -437,7 +437,7 @@ static int git_commit_graph_entry_get_byindex(
...
@@ -437,7 +437,7 @@ static int git_commit_graph_entry_get_byindex(
}
}
commit_data
=
file
->
commit_data
+
pos
*
(
GIT_OID_RAWSZ
+
4
*
sizeof
(
uint32_t
));
commit_data
=
file
->
commit_data
+
pos
*
(
GIT_OID_RAWSZ
+
4
*
sizeof
(
uint32_t
));
git_oid_
cpy
(
&
e
->
tree_oid
,
(
const
git_oid
*
)
commit_data
);
git_oid_
fromraw
(
&
e
->
tree_oid
,
commit_data
);
e
->
parent_indices
[
0
]
=
ntohl
(
*
((
uint32_t
*
)(
commit_data
+
GIT_OID_RAWSZ
)));
e
->
parent_indices
[
0
]
=
ntohl
(
*
((
uint32_t
*
)(
commit_data
+
GIT_OID_RAWSZ
)));
e
->
parent_indices
[
1
]
=
ntohl
(
e
->
parent_indices
[
1
]
=
ntohl
(
*
((
uint32_t
*
)(
commit_data
+
GIT_OID_RAWSZ
+
sizeof
(
uint32_t
))));
*
((
uint32_t
*
)(
commit_data
+
GIT_OID_RAWSZ
+
sizeof
(
uint32_t
))));
...
@@ -470,7 +470,8 @@ static int git_commit_graph_entry_get_byindex(
...
@@ -470,7 +470,8 @@ static int git_commit_graph_entry_get_byindex(
e
->
parent_count
++
;
e
->
parent_count
++
;
}
}
}
}
git_oid_cpy
(
&
e
->
sha1
,
&
file
->
oid_lookup
[
pos
]);
git_oid_fromraw
(
&
e
->
sha1
,
&
file
->
oid_lookup
[
pos
*
GIT_OID_RAWSZ
]);
return
0
;
return
0
;
}
}
...
@@ -514,7 +515,7 @@ int git_commit_graph_entry_find(
...
@@ -514,7 +515,7 @@ int git_commit_graph_entry_find(
{
{
int
pos
,
found
=
0
;
int
pos
,
found
=
0
;
uint32_t
hi
,
lo
;
uint32_t
hi
,
lo
;
const
git_oid
*
current
=
NULL
;
const
unsigned
char
*
current
=
NULL
;
GIT_ASSERT_ARG
(
e
);
GIT_ASSERT_ARG
(
e
);
GIT_ASSERT_ARG
(
file
);
GIT_ASSERT_ARG
(
file
);
...
@@ -528,27 +529,26 @@ int git_commit_graph_entry_find(
...
@@ -528,27 +529,26 @@ int git_commit_graph_entry_find(
if
(
pos
>=
0
)
{
if
(
pos
>=
0
)
{
/* An object matching exactly the oid was found */
/* An object matching exactly the oid was found */
found
=
1
;
found
=
1
;
current
=
file
->
oid_lookup
+
pos
;
current
=
file
->
oid_lookup
+
(
pos
*
GIT_OID_RAWSZ
)
;
}
else
{
}
else
{
/* No object was found */
/* No object was found */
/* pos refers to the object with the "closest" oid to short_oid */
/* pos refers to the object with the "closest" oid to short_oid */
pos
=
-
1
-
pos
;
pos
=
-
1
-
pos
;
if
(
pos
<
(
int
)
file
->
num_commits
)
{
if
(
pos
<
(
int
)
file
->
num_commits
)
{
current
=
file
->
oid_lookup
+
pos
;
current
=
file
->
oid_lookup
+
(
pos
*
GIT_OID_RAWSZ
)
;
if
(
!
git_oid_
ncmp
(
short_o
id
,
current
,
len
))
if
(
!
git_oid_
raw_ncmp
(
short_oid
->
id
,
current
,
len
))
found
=
1
;
found
=
1
;
}
}
}
}
if
(
found
&&
len
!=
GIT_OID_HEXSZ
&&
pos
+
1
<
(
int
)
file
->
num_commits
)
{
if
(
found
&&
len
!=
GIT_OID_HEXSZ
&&
pos
+
1
<
(
int
)
file
->
num_commits
)
{
/* Check for ambiguousity */
/* Check for ambiguousity */
const
git_oid
*
next
=
current
+
1
;
const
unsigned
char
*
next
=
current
+
GIT_OID_RAWSZ
;
if
(
!
git_oid_
ncmp
(
short_oid
,
next
,
len
))
{
if
(
!
git_oid_
raw_ncmp
(
short_oid
->
id
,
next
,
len
))
found
=
2
;
found
=
2
;
}
}
}
if
(
!
found
)
if
(
!
found
)
return
git_odb__error_notfound
(
return
git_odb__error_notfound
(
...
@@ -1019,7 +1019,9 @@ static int commit_graph_write(
...
@@ -1019,7 +1019,9 @@ static int commit_graph_write(
/* Fill the OID Lookup table. */
/* Fill the OID Lookup table. */
git_vector_foreach
(
&
w
->
commits
,
i
,
packed_commit
)
{
git_vector_foreach
(
&
w
->
commits
,
i
,
packed_commit
)
{
error
=
git_str_put
(
&
oid_lookup
,
error
=
git_str_put
(
&
oid_lookup
,
(
const
char
*
)
&
packed_commit
->
sha1
,
sizeof
(
git_oid
));
(
const
char
*
)
&
packed_commit
->
sha1
.
id
,
GIT_OID_RAWSZ
);
if
(
error
<
0
)
if
(
error
<
0
)
goto
cleanup
;
goto
cleanup
;
}
}
...
@@ -1034,8 +1036,9 @@ static int commit_graph_write(
...
@@ -1034,8 +1036,9 @@ static int commit_graph_write(
unsigned
int
parentcount
=
(
unsigned
int
)
git_array_size
(
packed_commit
->
parents
);
unsigned
int
parentcount
=
(
unsigned
int
)
git_array_size
(
packed_commit
->
parents
);
error
=
git_str_put
(
&
commit_data
,
error
=
git_str_put
(
&
commit_data
,
(
const
char
*
)
&
packed_commit
->
tree_oid
,
(
const
char
*
)
&
packed_commit
->
tree_oid
.
id
,
sizeof
(
git_oid
));
GIT_OID_RAWSZ
);
if
(
error
<
0
)
if
(
error
<
0
)
goto
cleanup
;
goto
cleanup
;
...
...
src/libgit2/commit_graph.h
View file @
3b52e5f5
...
@@ -36,7 +36,7 @@ typedef struct git_commit_graph_file {
...
@@ -36,7 +36,7 @@ typedef struct git_commit_graph_file {
uint32_t
num_commits
;
uint32_t
num_commits
;
/* The OID Lookup table. */
/* The OID Lookup table. */
git_oid
*
oid_lookup
;
unsigned
char
*
oid_lookup
;
/*
/*
* The Commit Data table. Each entry contains the OID of the commit followed
* The Commit Data table. Each entry contains the OID of the commit followed
...
...
src/libgit2/index.c
View file @
3b52e5f5
...
@@ -74,7 +74,7 @@ struct entry_short {
...
@@ -74,7 +74,7 @@ struct entry_short {
uint32_t
uid
;
uint32_t
uid
;
uint32_t
gid
;
uint32_t
gid
;
uint32_t
file_size
;
uint32_t
file_size
;
git_oid
oid
;
unsigned
char
oid
[
GIT_OID_RAWSZ
]
;
uint16_t
flags
;
uint16_t
flags
;
char
path
[
1
];
/* arbitrary length */
char
path
[
1
];
/* arbitrary length */
};
};
...
@@ -88,7 +88,7 @@ struct entry_long {
...
@@ -88,7 +88,7 @@ struct entry_long {
uint32_t
uid
;
uint32_t
uid
;
uint32_t
gid
;
uint32_t
gid
;
uint32_t
file_size
;
uint32_t
file_size
;
git_oid
oid
;
unsigned
char
oid
[
GIT_OID_RAWSZ
]
;
uint16_t
flags
;
uint16_t
flags
;
uint16_t
flags_extended
;
uint16_t
flags_extended
;
char
path
[
1
];
/* arbitrary length */
char
path
[
1
];
/* arbitrary length */
...
@@ -2480,9 +2480,11 @@ static int read_entry(
...
@@ -2480,9 +2480,11 @@ static int read_entry(
entry
.
uid
=
ntohl
(
source
.
uid
);
entry
.
uid
=
ntohl
(
source
.
uid
);
entry
.
gid
=
ntohl
(
source
.
gid
);
entry
.
gid
=
ntohl
(
source
.
gid
);
entry
.
file_size
=
ntohl
(
source
.
file_size
);
entry
.
file_size
=
ntohl
(
source
.
file_size
);
git_oid_cpy
(
&
entry
.
id
,
&
source
.
oid
);
entry
.
flags
=
ntohs
(
source
.
flags
);
entry
.
flags
=
ntohs
(
source
.
flags
);
if
(
git_oid_fromraw
(
&
entry
.
id
,
source
.
oid
)
<
0
)
return
-
1
;
if
(
entry
.
flags
&
GIT_INDEX_ENTRY_EXTENDED
)
{
if
(
entry
.
flags
&
GIT_INDEX_ENTRY_EXTENDED
)
{
uint16_t
flags_raw
;
uint16_t
flags_raw
;
size_t
flags_offset
;
size_t
flags_offset
;
...
@@ -2803,9 +2805,7 @@ static int write_disk_entry(git_filebuf *file, git_index_entry *entry, const cha
...
@@ -2803,9 +2805,7 @@ static int write_disk_entry(git_filebuf *file, git_index_entry *entry, const cha
ondisk
.
uid
=
htonl
(
entry
->
uid
);
ondisk
.
uid
=
htonl
(
entry
->
uid
);
ondisk
.
gid
=
htonl
(
entry
->
gid
);
ondisk
.
gid
=
htonl
(
entry
->
gid
);
ondisk
.
file_size
=
htonl
((
uint32_t
)
entry
->
file_size
);
ondisk
.
file_size
=
htonl
((
uint32_t
)
entry
->
file_size
);
git_oid_raw_cpy
(
ondisk
.
oid
,
entry
->
id
.
id
);
git_oid_cpy
(
&
ondisk
.
oid
,
&
entry
->
id
);
ondisk
.
flags
=
htons
(
entry
->
flags
);
ondisk
.
flags
=
htons
(
entry
->
flags
);
if
(
entry
->
flags
&
GIT_INDEX_ENTRY_EXTENDED
)
{
if
(
entry
->
flags
&
GIT_INDEX_ENTRY_EXTENDED
)
{
...
...
src/libgit2/indexer.c
View file @
3b52e5f5
...
@@ -385,7 +385,7 @@ static int check_object_connectivity(git_indexer *idx, const git_rawobj *obj)
...
@@ -385,7 +385,7 @@ static int check_object_connectivity(git_indexer *idx, const git_rawobj *obj)
size_t
i
;
size_t
i
;
git_array_foreach
(
tree
->
entries
,
i
,
entry
)
git_array_foreach
(
tree
->
entries
,
i
,
entry
)
if
(
add_expected_oid
(
idx
,
entry
->
oid
)
<
0
)
if
(
add_expected_oid
(
idx
,
&
entry
->
oid
)
<
0
)
goto
out
;
goto
out
;
break
;
break
;
...
@@ -1269,7 +1269,7 @@ int git_indexer_commit(git_indexer *idx, git_indexer_progress *stats)
...
@@ -1269,7 +1269,7 @@ int git_indexer_commit(git_indexer *idx, git_indexer_progress *stats)
/* Write out the object names (SHA-1 hashes) */
/* Write out the object names (SHA-1 hashes) */
git_vector_foreach
(
&
idx
->
objects
,
i
,
entry
)
{
git_vector_foreach
(
&
idx
->
objects
,
i
,
entry
)
{
git_filebuf_write
(
&
index_file
,
&
entry
->
oid
,
sizeof
(
git_oid
)
);
git_filebuf_write
(
&
index_file
,
&
entry
->
oid
.
id
,
GIT_OID_RAWSZ
);
}
}
/* Write out the CRC32 values */
/* Write out the CRC32 values */
...
...
src/libgit2/iterator.c
View file @
3b52e5f5
...
@@ -613,7 +613,7 @@ GIT_INLINE(int) tree_iterator_frame_push_neighbors(
...
@@ -613,7 +613,7 @@ GIT_INLINE(int) tree_iterator_frame_push_neighbors(
break
;
break
;
if
((
error
=
git_tree_lookup
(
&
tree
,
if
((
error
=
git_tree_lookup
(
&
tree
,
iter
->
base
.
repo
,
entry
->
tree_entry
->
oid
))
<
0
)
iter
->
base
.
repo
,
&
entry
->
tree_entry
->
oid
))
<
0
)
break
;
break
;
if
(
git_vector_insert
(
&
parent_frame
->
similar_trees
,
tree
)
<
0
)
if
(
git_vector_insert
(
&
parent_frame
->
similar_trees
,
tree
)
<
0
)
...
@@ -659,7 +659,7 @@ GIT_INLINE(int) tree_iterator_frame_push(
...
@@ -659,7 +659,7 @@ GIT_INLINE(int) tree_iterator_frame_push(
int
error
;
int
error
;
if
((
error
=
git_tree_lookup
(
&
tree
,
if
((
error
=
git_tree_lookup
(
&
tree
,
iter
->
base
.
repo
,
entry
->
tree_entry
->
oid
))
<
0
||
iter
->
base
.
repo
,
&
entry
->
tree_entry
->
oid
))
<
0
||
(
error
=
tree_iterator_frame_init
(
iter
,
tree
,
entry
))
<
0
)
(
error
=
tree_iterator_frame_init
(
iter
,
tree
,
entry
))
<
0
)
goto
done
;
goto
done
;
...
@@ -740,7 +740,7 @@ static void tree_iterator_set_current(
...
@@ -740,7 +740,7 @@ static void tree_iterator_set_current(
iter
->
entry
.
mode
=
tree_entry
->
attr
;
iter
->
entry
.
mode
=
tree_entry
->
attr
;
iter
->
entry
.
path
=
iter
->
entry_path
.
ptr
;
iter
->
entry
.
path
=
iter
->
entry_path
.
ptr
;
git_oid_cpy
(
&
iter
->
entry
.
id
,
tree_entry
->
oid
);
git_oid_cpy
(
&
iter
->
entry
.
id
,
&
tree_entry
->
oid
);
}
}
static
int
tree_iterator_advance
(
const
git_index_entry
**
out
,
git_iterator
*
i
)
static
int
tree_iterator_advance
(
const
git_index_entry
**
out
,
git_iterator
*
i
)
...
...
src/libgit2/midx.c
View file @
3b52e5f5
...
@@ -115,7 +115,7 @@ static int midx_parse_oid_lookup(
...
@@ -115,7 +115,7 @@ static int midx_parse_oid_lookup(
struct
git_midx_chunk
*
chunk_oid_lookup
)
struct
git_midx_chunk
*
chunk_oid_lookup
)
{
{
uint32_t
i
;
uint32_t
i
;
git_oid
*
oid
,
*
prev_oid
,
zero_oid
=
{{
0
}
};
unsigned
char
*
oid
,
*
prev_oid
,
zero_oid
[
GIT_OID_RAWSZ
]
=
{
0
};
if
(
chunk_oid_lookup
->
offset
==
0
)
if
(
chunk_oid_lookup
->
offset
==
0
)
return
midx_error
(
"missing OID Lookup chunk"
);
return
midx_error
(
"missing OID Lookup chunk"
);
...
@@ -124,10 +124,10 @@ static int midx_parse_oid_lookup(
...
@@ -124,10 +124,10 @@ static int midx_parse_oid_lookup(
if
(
chunk_oid_lookup
->
length
!=
idx
->
num_objects
*
GIT_OID_RAWSZ
)
if
(
chunk_oid_lookup
->
length
!=
idx
->
num_objects
*
GIT_OID_RAWSZ
)
return
midx_error
(
"OID Lookup chunk has wrong length"
);
return
midx_error
(
"OID Lookup chunk has wrong length"
);
idx
->
oid_lookup
=
oid
=
(
git_oid
*
)(
data
+
chunk_oid_lookup
->
offset
);
idx
->
oid_lookup
=
oid
=
(
unsigned
char
*
)(
data
+
chunk_oid_lookup
->
offset
);
prev_oid
=
&
zero_oid
;
prev_oid
=
zero_oid
;
for
(
i
=
0
;
i
<
idx
->
num_objects
;
++
i
,
++
oid
)
{
for
(
i
=
0
;
i
<
idx
->
num_objects
;
++
i
,
oid
+=
GIT_OID_RAWSZ
)
{
if
(
git_oid_cmp
(
prev_oid
,
oid
)
>=
0
)
if
(
git_oid_
raw_
cmp
(
prev_oid
,
oid
)
>=
0
)
return
midx_error
(
"OID Lookup index is non-monotonic"
);
return
midx_error
(
"OID Lookup index is non-monotonic"
);
prev_oid
=
oid
;
prev_oid
=
oid
;
}
}
...
@@ -389,7 +389,7 @@ int git_midx_entry_find(
...
@@ -389,7 +389,7 @@ int git_midx_entry_find(
int
pos
,
found
=
0
;
int
pos
,
found
=
0
;
size_t
pack_index
;
size_t
pack_index
;
uint32_t
hi
,
lo
;
uint32_t
hi
,
lo
;
const
git_oid
*
current
=
NULL
;
unsigned
char
*
current
=
NULL
;
const
unsigned
char
*
object_offset
;
const
unsigned
char
*
object_offset
;
off64_t
offset
;
off64_t
offset
;
...
@@ -403,27 +403,26 @@ int git_midx_entry_find(
...
@@ -403,27 +403,26 @@ int git_midx_entry_find(
if
(
pos
>=
0
)
{
if
(
pos
>=
0
)
{
/* An object matching exactly the oid was found */
/* An object matching exactly the oid was found */
found
=
1
;
found
=
1
;
current
=
idx
->
oid_lookup
+
pos
;
current
=
idx
->
oid_lookup
+
(
pos
*
GIT_OID_RAWSZ
)
;
}
else
{
}
else
{
/* No object was found */
/* No object was found */
/* pos refers to the object with the "closest" oid to short_oid */
/* pos refers to the object with the "closest" oid to short_oid */
pos
=
-
1
-
pos
;
pos
=
-
1
-
pos
;
if
(
pos
<
(
int
)
idx
->
num_objects
)
{
if
(
pos
<
(
int
)
idx
->
num_objects
)
{
current
=
idx
->
oid_lookup
+
pos
;
current
=
idx
->
oid_lookup
+
(
pos
*
GIT_OID_RAWSZ
)
;
if
(
!
git_oid_
ncmp
(
short_o
id
,
current
,
len
))
if
(
!
git_oid_
raw_ncmp
(
short_oid
->
id
,
current
,
len
))
found
=
1
;
found
=
1
;
}
}
}
}
if
(
found
&&
len
!=
GIT_OID_HEXSZ
&&
pos
+
1
<
(
int
)
idx
->
num_objects
)
{
if
(
found
&&
len
!=
GIT_OID_HEXSZ
&&
pos
+
1
<
(
int
)
idx
->
num_objects
)
{
/* Check for ambiguousity */
/* Check for ambiguousity */
const
git_oid
*
next
=
current
+
1
;
const
unsigned
char
*
next
=
current
+
GIT_OID_RAWSZ
;
if
(
!
git_oid_
ncmp
(
short_oid
,
next
,
len
))
{
if
(
!
git_oid_
raw_ncmp
(
short_oid
->
id
,
next
,
len
))
found
=
2
;
found
=
2
;
}
}
}
if
(
!
found
)
if
(
!
found
)
return
git_odb__error_notfound
(
"failed to find offset for multi-pack index entry"
,
short_oid
,
len
);
return
git_odb__error_notfound
(
"failed to find offset for multi-pack index entry"
,
short_oid
,
len
);
...
@@ -450,7 +449,7 @@ int git_midx_entry_find(
...
@@ -450,7 +449,7 @@ int git_midx_entry_find(
return
midx_error
(
"invalid index into the packfile names table"
);
return
midx_error
(
"invalid index into the packfile names table"
);
e
->
pack_index
=
pack_index
;
e
->
pack_index
=
pack_index
;
e
->
offset
=
offset
;
e
->
offset
=
offset
;
git_oid_
cpy
(
&
e
->
sha1
,
current
);
git_oid_
fromraw
(
&
e
->
sha1
,
current
);
return
0
;
return
0
;
}
}
...
@@ -459,13 +458,17 @@ int git_midx_foreach_entry(
...
@@ -459,13 +458,17 @@ int git_midx_foreach_entry(
git_odb_foreach_cb
cb
,
git_odb_foreach_cb
cb
,
void
*
data
)
void
*
data
)
{
{
git_oid
oid
;
size_t
i
;
size_t
i
;
int
error
;
int
error
;
GIT_ASSERT_ARG
(
idx
);
GIT_ASSERT_ARG
(
idx
);
for
(
i
=
0
;
i
<
idx
->
num_objects
;
++
i
)
{
for
(
i
=
0
;
i
<
idx
->
num_objects
;
++
i
)
{
if
((
error
=
cb
(
&
idx
->
oid_lookup
[
i
],
data
))
!=
0
)
if
((
error
=
git_oid_fromraw
(
&
oid
,
&
idx
->
oid_lookup
[
i
*
GIT_OID_RAWSZ
]))
<
0
)
return
error
;
if
((
error
=
cb
(
&
oid
,
data
))
!=
0
)
return
git_error_set_after_callback
(
error
);
return
git_error_set_after_callback
(
error
);
}
}
...
@@ -751,7 +754,7 @@ static int midx_write(
...
@@ -751,7 +754,7 @@ static int midx_write(
/* Fill the OID Lookup table. */
/* Fill the OID Lookup table. */
git_vector_foreach
(
&
object_entries
,
i
,
entry
)
{
git_vector_foreach
(
&
object_entries
,
i
,
entry
)
{
error
=
git_str_put
(
&
oid_lookup
,
(
c
onst
char
*
)
&
entry
->
sha1
,
sizeof
(
entry
->
sha1
)
);
error
=
git_str_put
(
&
oid_lookup
,
(
c
har
*
)
&
entry
->
sha1
.
id
,
GIT_OID_RAWSZ
);
if
(
error
<
0
)
if
(
error
<
0
)
goto
cleanup
;
goto
cleanup
;
}
}
...
...
src/libgit2/midx.h
View file @
3b52e5f5
...
@@ -17,6 +17,7 @@
...
@@ -17,6 +17,7 @@
#include "map.h"
#include "map.h"
#include "mwindow.h"
#include "mwindow.h"
#include "odb.h"
#include "odb.h"
#include "oid.h"
/*
/*
* A multi-pack-index file.
* A multi-pack-index file.
...
@@ -40,7 +41,7 @@ typedef struct git_midx_file {
...
@@ -40,7 +41,7 @@ typedef struct git_midx_file {
uint32_t
num_objects
;
uint32_t
num_objects
;
/* The OID Lookup table. */
/* The OID Lookup table. */
git_oid
*
oid_lookup
;
unsigned
char
*
oid_lookup
;
/* The Object Offsets table. Each entry has two 4-byte fields with the pack index and the offset. */
/* The Object Offsets table. Each entry has two 4-byte fields with the pack index and the offset. */
const
unsigned
char
*
object_offsets
;
const
unsigned
char
*
object_offsets
;
...
...
src/libgit2/oid.c
View file @
3b52e5f5
...
@@ -187,8 +187,7 @@ int git_oid_fromraw(git_oid *out, const unsigned char *raw)
...
@@ -187,8 +187,7 @@ int git_oid_fromraw(git_oid *out, const unsigned char *raw)
int
git_oid_cpy
(
git_oid
*
out
,
const
git_oid
*
src
)
int
git_oid_cpy
(
git_oid
*
out
,
const
git_oid
*
src
)
{
{
memcpy
(
out
->
id
,
src
->
id
,
sizeof
(
out
->
id
));
return
git_oid_raw_cpy
(
out
->
id
,
src
->
id
);
return
0
;
}
}
int
git_oid_cmp
(
const
git_oid
*
a
,
const
git_oid
*
b
)
int
git_oid_cmp
(
const
git_oid
*
a
,
const
git_oid
*
b
)
...
@@ -203,25 +202,7 @@ int git_oid_equal(const git_oid *a, const git_oid *b)
...
@@ -203,25 +202,7 @@ int git_oid_equal(const git_oid *a, const git_oid *b)
int
git_oid_ncmp
(
const
git_oid
*
oid_a
,
const
git_oid
*
oid_b
,
size_t
len
)
int
git_oid_ncmp
(
const
git_oid
*
oid_a
,
const
git_oid
*
oid_b
,
size_t
len
)
{
{
const
unsigned
char
*
a
=
oid_a
->
id
;
return
git_oid_raw_ncmp
(
oid_a
->
id
,
oid_b
->
id
,
len
);
const
unsigned
char
*
b
=
oid_b
->
id
;
if
(
len
>
GIT_OID_HEXSZ
)
len
=
GIT_OID_HEXSZ
;
while
(
len
>
1
)
{
if
(
*
a
!=
*
b
)
return
1
;
a
++
;
b
++
;
len
-=
2
;
};
if
(
len
)
if
((
*
a
^
*
b
)
&
0xf0
)
return
1
;
return
0
;
}
}
int
git_oid_strcmp
(
const
git_oid
*
oid_a
,
const
char
*
str
)
int
git_oid_strcmp
(
const
git_oid
*
oid_a
,
const
char
*
str
)
...
...
src/libgit2/oid.h
View file @
3b52e5f5
...
@@ -25,11 +25,44 @@ extern const git_oid git_oid__empty_tree_sha1;
...
@@ -25,11 +25,44 @@ extern const git_oid git_oid__empty_tree_sha1;
*/
*/
char
*
git_oid_allocfmt
(
const
git_oid
*
id
);
char
*
git_oid_allocfmt
(
const
git_oid
*
id
);
GIT_INLINE
(
int
)
git_oid__hashcmp
(
const
unsigned
char
*
sha1
,
const
unsigned
char
*
sha2
)
GIT_INLINE
(
int
)
git_oid_raw_ncmp
(
const
unsigned
char
*
sha1
,
const
unsigned
char
*
sha2
,
size_t
len
)
{
if
(
len
>
GIT_OID_HEXSZ
)
len
=
GIT_OID_HEXSZ
;
while
(
len
>
1
)
{
if
(
*
sha1
!=
*
sha2
)
return
1
;
sha1
++
;
sha2
++
;
len
-=
2
;
};
if
(
len
)
if
((
*
sha1
^
*
sha2
)
&
0xf0
)
return
1
;
return
0
;
}
GIT_INLINE
(
int
)
git_oid_raw_cmp
(
const
unsigned
char
*
sha1
,
const
unsigned
char
*
sha2
)
{
{
return
memcmp
(
sha1
,
sha2
,
GIT_OID_RAWSZ
);
return
memcmp
(
sha1
,
sha2
,
GIT_OID_RAWSZ
);
}
}
GIT_INLINE
(
int
)
git_oid_raw_cpy
(
unsigned
char
*
dst
,
const
unsigned
char
*
src
)
{
memcpy
(
dst
,
src
,
GIT_OID_RAWSZ
);
return
0
;
}
/*
/*
* Compare two oid structures.
* Compare two oid structures.
*
*
...
@@ -39,7 +72,7 @@ GIT_INLINE(int) git_oid__hashcmp(const unsigned char *sha1, const unsigned char
...
@@ -39,7 +72,7 @@ GIT_INLINE(int) git_oid__hashcmp(const unsigned char *sha1, const unsigned char
*/
*/
GIT_INLINE
(
int
)
git_oid__cmp
(
const
git_oid
*
a
,
const
git_oid
*
b
)
GIT_INLINE
(
int
)
git_oid__cmp
(
const
git_oid
*
a
,
const
git_oid
*
b
)
{
{
return
git_oid_
_hash
cmp
(
a
->
id
,
b
->
id
);
return
git_oid_
raw_
cmp
(
a
->
id
,
b
->
id
);
}
}
GIT_INLINE
(
void
)
git_oid__cpy_prefix
(
GIT_INLINE
(
void
)
git_oid__cpy_prefix
(
...
...
src/libgit2/oidmap.c
View file @
3b52e5f5
...
@@ -19,7 +19,7 @@ __KHASH_TYPE(oid, const git_oid *, void *)
...
@@ -19,7 +19,7 @@ __KHASH_TYPE(oid, const git_oid *, void *)
GIT_INLINE
(
khint_t
)
git_oidmap_hash
(
const
git_oid
*
oid
)
GIT_INLINE
(
khint_t
)
git_oidmap_hash
(
const
git_oid
*
oid
)
{
{
khint_t
h
;
khint_t
h
;
memcpy
(
&
h
,
oid
,
sizeof
(
khint_t
));
memcpy
(
&
h
,
oid
->
id
,
sizeof
(
khint_t
));
return
h
;
return
h
;
}
}
...
...
src/libgit2/pack.c
View file @
3b52e5f5
...
@@ -1001,13 +1001,14 @@ int get_delta_base(
...
@@ -1001,13 +1001,14 @@ int get_delta_base(
base_offset
=
delta_obj_offset
-
unsigned_base_offset
;
base_offset
=
delta_obj_offset
-
unsigned_base_offset
;
*
curpos
+=
used
;
*
curpos
+=
used
;
}
else
if
(
type
==
GIT_OBJECT_REF_DELTA
)
{
}
else
if
(
type
==
GIT_OBJECT_REF_DELTA
)
{
git_oid
base_oid
;
git_oid_fromraw
(
&
base_oid
,
base_info
);
/* If we have the cooperative cache, search in it first */
/* If we have the cooperative cache, search in it first */
if
(
p
->
has_cache
)
{
if
(
p
->
has_cache
)
{
struct
git_pack_entry
*
entry
;
struct
git_pack_entry
*
entry
;
git_oid
oid
;
git_oid_fromraw
(
&
oid
,
base_info
);
if
((
entry
=
git_oidmap_get
(
p
->
idx_cache
,
&
base_oid
))
!=
NULL
)
{
if
((
entry
=
git_oidmap_get
(
p
->
idx_cache
,
&
oid
))
!=
NULL
)
{
if
(
entry
->
offset
==
0
)
if
(
entry
->
offset
==
0
)
return
packfile_error
(
"delta offset is zero"
);
return
packfile_error
(
"delta offset is zero"
);
...
@@ -1024,7 +1025,7 @@ int get_delta_base(
...
@@ -1024,7 +1025,7 @@ int get_delta_base(
}
}
/* The base entry _must_ be in the same pack */
/* The base entry _must_ be in the same pack */
if
(
pack_entry_find_offset
(
&
base_offset
,
&
unused
,
p
,
(
git_oid
*
)
base_info
,
GIT_OID_HEXSZ
)
<
0
)
if
(
pack_entry_find_offset
(
&
base_offset
,
&
unused
,
p
,
&
base_oid
,
GIT_OID_HEXSZ
)
<
0
)
return
packfile_error
(
"base entry delta is not in the same pack"
);
return
packfile_error
(
"base entry delta is not in the same pack"
);
*
curpos
+=
20
;
*
curpos
+=
20
;
}
else
}
else
...
@@ -1082,7 +1083,7 @@ static int packfile_open_locked(struct git_pack_file *p)
...
@@ -1082,7 +1083,7 @@ static int packfile_open_locked(struct git_pack_file *p)
{
{
struct
stat
st
;
struct
stat
st
;
struct
git_pack_header
hdr
;
struct
git_pack_header
hdr
;
git_oid
sha1
;
unsigned
char
sha1
[
GIT_OID_RAWSZ
]
;
unsigned
char
*
idx_sha1
;
unsigned
char
*
idx_sha1
;
if
(
pack_index_open_locked
(
p
)
<
0
)
if
(
pack_index_open_locked
(
p
)
<
0
)
...
@@ -1130,12 +1131,12 @@ static int packfile_open_locked(struct git_pack_file *p)
...
@@ -1130,12 +1131,12 @@ static int packfile_open_locked(struct git_pack_file *p)
/* Verify the pack matches its index. */
/* Verify the pack matches its index. */
if
(
p
->
num_objects
!=
ntohl
(
hdr
.
hdr_entries
)
||
if
(
p
->
num_objects
!=
ntohl
(
hdr
.
hdr_entries
)
||
p_pread
(
p
->
mwf
.
fd
,
sha1
.
id
,
GIT_OID_RAWSZ
,
p
->
mwf
.
size
-
GIT_OID_RAWSZ
)
<
0
)
p_pread
(
p
->
mwf
.
fd
,
sha1
,
GIT_OID_RAWSZ
,
p
->
mwf
.
size
-
GIT_OID_RAWSZ
)
<
0
)
goto
cleanup
;
goto
cleanup
;
idx_sha1
=
((
unsigned
char
*
)
p
->
index_map
.
data
)
+
p
->
index_map
.
len
-
40
;
idx_sha1
=
((
unsigned
char
*
)
p
->
index_map
.
data
)
+
p
->
index_map
.
len
-
40
;
if
(
git_oid_
_cmp
(
&
sha1
,
(
git_oid
*
)
idx_sha1
)
!=
0
)
if
(
git_oid_
raw_cmp
(
sha1
,
idx_sha1
)
!=
0
)
goto
cleanup
;
goto
cleanup
;
if
(
git_mwindow_file_register
(
&
p
->
mwf
)
<
0
)
if
(
git_mwindow_file_register
(
&
p
->
mwf
)
<
0
)
...
@@ -1340,10 +1341,14 @@ int git_pack_foreach_entry(
...
@@ -1340,10 +1341,14 @@ int git_pack_foreach_entry(
}
}
git_vector_free
(
&
offsets
);
git_vector_free
(
&
offsets
);
p
->
oids
=
(
git_oid
**
)
git_vector_detach
(
NULL
,
NULL
,
&
oids
);
p
->
oids
=
(
unsigned
char
**
)
git_vector_detach
(
NULL
,
NULL
,
&
oids
);
}
}
/* We need to copy the OIDs to another array before we relinquish the lock to avoid races. */
/*
* We need to copy the OIDs to another array before we
* relinquish the lock to avoid races. We can also take
* this opportunity to put them into normal form.
*/
git_array_init_to_size
(
oids
,
p
->
num_objects
);
git_array_init_to_size
(
oids
,
p
->
num_objects
);
if
(
!
oids
.
ptr
)
{
if
(
!
oids
.
ptr
)
{
git_mutex_unlock
(
&
p
->
lock
);
git_mutex_unlock
(
&
p
->
lock
);
...
@@ -1357,7 +1362,7 @@ int git_pack_foreach_entry(
...
@@ -1357,7 +1362,7 @@ int git_pack_foreach_entry(
git_array_clear
(
oids
);
git_array_clear
(
oids
);
GIT_ERROR_CHECK_ALLOC
(
oid
);
GIT_ERROR_CHECK_ALLOC
(
oid
);
}
}
git_oid_
cpy
(
oid
,
p
->
oids
[
i
]);
git_oid_
fromraw
(
oid
,
p
->
oids
[
i
]);
}
}
git_mutex_unlock
(
&
p
->
lock
);
git_mutex_unlock
(
&
p
->
lock
);
...
@@ -1380,7 +1385,7 @@ int git_pack_foreach_entry_offset(
...
@@ -1380,7 +1385,7 @@ int git_pack_foreach_entry_offset(
{
{
const
unsigned
char
*
index
;
const
unsigned
char
*
index
;
off64_t
current_offset
;
off64_t
current_offset
;
const
git_oid
*
current_oid
;
git_oid
current_oid
;
uint32_t
i
;
uint32_t
i
;
int
error
=
0
;
int
error
=
0
;
...
@@ -1422,8 +1427,9 @@ int git_pack_foreach_entry_offset(
...
@@ -1422,8 +1427,9 @@ int git_pack_foreach_entry_offset(
current_offset
=
(((
off64_t
)
ntohl
(
*
((
uint32_t
*
)(
large_offset_ptr
+
0
))))
<<
32
)
|
current_offset
=
(((
off64_t
)
ntohl
(
*
((
uint32_t
*
)(
large_offset_ptr
+
0
))))
<<
32
)
|
ntohl
(
*
((
uint32_t
*
)(
large_offset_ptr
+
4
)));
ntohl
(
*
((
uint32_t
*
)(
large_offset_ptr
+
4
)));
}
}
current_oid
=
(
const
git_oid
*
)(
index
+
20
*
i
);
if
((
error
=
cb
(
current_oid
,
current_offset
,
data
))
!=
0
)
{
git_oid_fromraw
(
&
current_oid
,
(
index
+
20
*
i
));
if
((
error
=
cb
(
&
current_oid
,
current_offset
,
data
))
!=
0
)
{
error
=
git_error_set_after_callback
(
error
);
error
=
git_error_set_after_callback
(
error
);
goto
cleanup
;
goto
cleanup
;
}
}
...
@@ -1431,8 +1437,8 @@ int git_pack_foreach_entry_offset(
...
@@ -1431,8 +1437,8 @@ int git_pack_foreach_entry_offset(
}
else
{
}
else
{
for
(
i
=
0
;
i
<
p
->
num_objects
;
i
++
)
{
for
(
i
=
0
;
i
<
p
->
num_objects
;
i
++
)
{
current_offset
=
ntohl
(
*
(
const
uint32_t
*
)(
index
+
24
*
i
));
current_offset
=
ntohl
(
*
(
const
uint32_t
*
)(
index
+
24
*
i
));
current_oid
=
(
const
git_oid
*
)(
index
+
24
*
i
+
4
);
git_oid_fromraw
(
&
current_oid
,
(
index
+
24
*
i
+
4
)
);
if
((
error
=
cb
(
current_oid
,
current_offset
,
data
))
!=
0
)
{
if
((
error
=
cb
(
&
current_oid
,
current_offset
,
data
))
!=
0
)
{
error
=
git_error_set_after_callback
(
error
);
error
=
git_error_set_after_callback
(
error
);
goto
cleanup
;
goto
cleanup
;
}
}
...
@@ -1451,7 +1457,7 @@ int git_pack__lookup_sha1(const void *oid_lookup_table, size_t stride, unsigned
...
@@ -1451,7 +1457,7 @@ int git_pack__lookup_sha1(const void *oid_lookup_table, size_t stride, unsigned
while
(
lo
<
hi
)
{
while
(
lo
<
hi
)
{
unsigned
mi
=
(
lo
+
hi
)
/
2
;
unsigned
mi
=
(
lo
+
hi
)
/
2
;
int
cmp
=
git_oid_
_hash
cmp
(
base
+
mi
*
stride
,
oid_prefix
);
int
cmp
=
git_oid_
raw_
cmp
(
base
+
mi
*
stride
,
oid_prefix
);
if
(
!
cmp
)
if
(
!
cmp
)
return
mi
;
return
mi
;
...
@@ -1530,7 +1536,7 @@ static int pack_entry_find_offset(
...
@@ -1530,7 +1536,7 @@ static int pack_entry_find_offset(
if
(
pos
<
(
int
)
p
->
num_objects
)
{
if
(
pos
<
(
int
)
p
->
num_objects
)
{
current
=
index
+
pos
*
stride
;
current
=
index
+
pos
*
stride
;
if
(
!
git_oid_
ncmp
(
short_oid
,
(
const
git_oid
*
)
current
,
len
))
if
(
!
git_oid_
raw_ncmp
(
short_oid
->
id
,
current
,
len
))
found
=
1
;
found
=
1
;
}
}
}
}
...
@@ -1539,7 +1545,7 @@ static int pack_entry_find_offset(
...
@@ -1539,7 +1545,7 @@ static int pack_entry_find_offset(
/* Check for ambiguousity */
/* Check for ambiguousity */
const
unsigned
char
*
next
=
current
+
stride
;
const
unsigned
char
*
next
=
current
+
stride
;
if
(
!
git_oid_
ncmp
(
short_oid
,
(
const
git_oid
*
)
next
,
len
))
{
if
(
!
git_oid_
raw_ncmp
(
short_oid
->
id
,
next
,
len
))
{
found
=
2
;
found
=
2
;
}
}
}
}
...
...
src/libgit2/pack.h
View file @
3b52e5f5
...
@@ -19,6 +19,7 @@
...
@@ -19,6 +19,7 @@
#include "offmap.h"
#include "offmap.h"
#include "oidmap.h"
#include "oidmap.h"
#include "zstream.h"
#include "zstream.h"
#include "oid.h"
/**
/**
* Function type for callbacks from git_pack_foreach_entry_offset.
* Function type for callbacks from git_pack_foreach_entry_offset.
...
@@ -104,7 +105,7 @@ struct git_pack_file {
...
@@ -104,7 +105,7 @@ struct git_pack_file {
git_time_t
mtime
;
git_time_t
mtime
;
unsigned
pack_local
:
1
,
pack_keep
:
1
,
has_cache
:
1
;
unsigned
pack_local
:
1
,
pack_keep
:
1
,
has_cache
:
1
;
git_oidmap
*
idx_cache
;
git_oidmap
*
idx_cache
;
git_oid
**
oids
;
unsigned
char
**
oids
;
git_pack_cache
bases
;
/* delta base cache */
git_pack_cache
bases
;
/* delta base cache */
...
...
src/libgit2/remote.c
View file @
3b52e5f5
...
@@ -1830,7 +1830,7 @@ static int update_one_tip(
...
@@ -1830,7 +1830,7 @@ static int update_one_tip(
}
}
if
(
error
==
GIT_ENOTFOUND
)
{
if
(
error
==
GIT_ENOTFOUND
)
{
memset
(
&
old
,
0
,
GIT_OID_RAWSZ
);
memset
(
&
old
,
0
,
sizeof
(
git_oid
)
);
error
=
0
;
error
=
0
;
if
(
autotag
&&
(
error
=
git_vector_insert
(
update_heads
,
head
))
<
0
)
if
(
autotag
&&
(
error
=
git_vector_insert
(
update_heads
,
head
))
<
0
)
...
...
src/libgit2/tree-cache.c
View file @
3b52e5f5
...
@@ -263,7 +263,7 @@ static void write_tree(git_str *out, git_tree_cache *tree)
...
@@ -263,7 +263,7 @@ static void write_tree(git_str *out, git_tree_cache *tree)
git_str_printf
(
out
,
"%s%c%"
PRIdZ
" %"
PRIuZ
"
\n
"
,
tree
->
name
,
0
,
tree
->
entry_count
,
tree
->
children_count
);
git_str_printf
(
out
,
"%s%c%"
PRIdZ
" %"
PRIuZ
"
\n
"
,
tree
->
name
,
0
,
tree
->
entry_count
,
tree
->
children_count
);
if
(
tree
->
entry_count
!=
-
1
)
if
(
tree
->
entry_count
!=
-
1
)
git_str_put
(
out
,
(
c
onst
char
*
)
&
tree
->
o
id
,
GIT_OID_RAWSZ
);
git_str_put
(
out
,
(
c
har
*
)
&
tree
->
oid
.
id
,
GIT_OID_RAWSZ
);
for
(
i
=
0
;
i
<
tree
->
children_count
;
i
++
)
for
(
i
=
0
;
i
<
tree
->
children_count
;
i
++
)
write_tree
(
out
,
tree
->
children
[
i
]);
write_tree
(
out
,
tree
->
children
[
i
]);
...
...
src/libgit2/tree.c
View file @
3b52e5f5
...
@@ -82,6 +82,7 @@ int git_tree_entry_cmp(const git_tree_entry *e1, const git_tree_entry *e2)
...
@@ -82,6 +82,7 @@ int git_tree_entry_cmp(const git_tree_entry *e1, const git_tree_entry *e2)
static
git_tree_entry
*
alloc_entry
(
const
char
*
filename
,
size_t
filename_len
,
const
git_oid
*
id
)
static
git_tree_entry
*
alloc_entry
(
const
char
*
filename
,
size_t
filename_len
,
const
git_oid
*
id
)
{
{
git_tree_entry
*
entry
=
NULL
;
git_tree_entry
*
entry
=
NULL
;
char
*
filename_ptr
;
size_t
tree_len
;
size_t
tree_len
;
TREE_ENTRY_CHECK_NAMELEN
(
filename_len
);
TREE_ENTRY_CHECK_NAMELEN
(
filename_len
);
...
@@ -95,21 +96,13 @@ static git_tree_entry *alloc_entry(const char *filename, size_t filename_len, co
...
@@ -95,21 +96,13 @@ static git_tree_entry *alloc_entry(const char *filename, size_t filename_len, co
if
(
!
entry
)
if
(
!
entry
)
return
NULL
;
return
NULL
;
{
char
*
filename_ptr
;
void
*
id_ptr
;
filename_ptr
=
((
char
*
)
entry
)
+
sizeof
(
git_tree_entry
);
filename_ptr
=
((
char
*
)
entry
)
+
sizeof
(
git_tree_entry
);
memcpy
(
filename_ptr
,
filename
,
filename_len
);
memcpy
(
filename_ptr
,
filename
,
filename_len
);
entry
->
filename
=
filename_ptr
;
entry
->
filename
=
filename_ptr
;
id_ptr
=
filename_ptr
+
filename_len
+
1
;
git_oid_cpy
(
id_ptr
,
id
);
entry
->
oid
=
id_ptr
;
}
entry
->
filename_len
=
(
uint16_t
)
filename_len
;
entry
->
filename_len
=
(
uint16_t
)
filename_len
;
git_oid_cpy
(
&
entry
->
oid
,
id
);
return
entry
;
return
entry
;
}
}
...
@@ -231,7 +224,7 @@ int git_tree_entry_dup(git_tree_entry **dest, const git_tree_entry *source)
...
@@ -231,7 +224,7 @@ int git_tree_entry_dup(git_tree_entry **dest, const git_tree_entry *source)
GIT_ASSERT_ARG
(
source
);
GIT_ASSERT_ARG
(
source
);
cpy
=
alloc_entry
(
source
->
filename
,
source
->
filename_len
,
source
->
oid
);
cpy
=
alloc_entry
(
source
->
filename
,
source
->
filename_len
,
&
source
->
oid
);
if
(
cpy
==
NULL
)
if
(
cpy
==
NULL
)
return
-
1
;
return
-
1
;
...
@@ -269,7 +262,7 @@ const char *git_tree_entry_name(const git_tree_entry *entry)
...
@@ -269,7 +262,7 @@ const char *git_tree_entry_name(const git_tree_entry *entry)
const
git_oid
*
git_tree_entry_id
(
const
git_tree_entry
*
entry
)
const
git_oid
*
git_tree_entry_id
(
const
git_tree_entry
*
entry
)
{
{
GIT_ASSERT_ARG_WITH_RETVAL
(
entry
,
NULL
);
GIT_ASSERT_ARG_WITH_RETVAL
(
entry
,
NULL
);
return
entry
->
oid
;
return
&
entry
->
oid
;
}
}
git_object_t
git_tree_entry_type
(
const
git_tree_entry
*
entry
)
git_object_t
git_tree_entry_type
(
const
git_tree_entry
*
entry
)
...
@@ -292,7 +285,7 @@ int git_tree_entry_to_object(
...
@@ -292,7 +285,7 @@ int git_tree_entry_to_object(
GIT_ASSERT_ARG
(
entry
);
GIT_ASSERT_ARG
(
entry
);
GIT_ASSERT_ARG
(
object_out
);
GIT_ASSERT_ARG
(
object_out
);
return
git_object_lookup
(
object_out
,
repo
,
entry
->
oid
,
GIT_OBJECT_ANY
);
return
git_object_lookup
(
object_out
,
repo
,
&
entry
->
oid
,
GIT_OBJECT_ANY
);
}
}
static
const
git_tree_entry
*
entry_fromname
(
static
const
git_tree_entry
*
entry_fromname
(
...
@@ -331,7 +324,7 @@ const git_tree_entry *git_tree_entry_byid(
...
@@ -331,7 +324,7 @@ const git_tree_entry *git_tree_entry_byid(
GIT_ASSERT_ARG_WITH_RETVAL
(
tree
,
NULL
);
GIT_ASSERT_ARG_WITH_RETVAL
(
tree
,
NULL
);
git_array_foreach
(
tree
->
entries
,
i
,
e
)
{
git_array_foreach
(
tree
->
entries
,
i
,
e
)
{
if
(
memcmp
(
&
e
->
oid
->
id
,
&
id
->
id
,
sizeof
(
id
->
id
))
==
0
)
if
(
git_oid_equal
(
&
e
->
oid
,
id
)
)
return
e
;
return
e
;
}
}
...
@@ -432,7 +425,7 @@ int git_tree__parse_raw(void *_tree, const char *data, size_t size)
...
@@ -432,7 +425,7 @@ int git_tree__parse_raw(void *_tree, const char *data, size_t size)
entry
->
attr
=
attr
;
entry
->
attr
=
attr
;
entry
->
filename_len
=
(
uint16_t
)
filename_len
;
entry
->
filename_len
=
(
uint16_t
)
filename_len
;
entry
->
filename
=
buffer
;
entry
->
filename
=
buffer
;
entry
->
oid
=
(
git_oid
*
)
((
char
*
)
buffer
+
filename_len
+
1
);
git_oid_fromraw
(
&
entry
->
oid
,
((
unsigned
char
*
)
buffer
+
filename_len
+
1
)
);
}
}
buffer
+=
filename_len
+
1
;
buffer
+=
filename_len
+
1
;
...
@@ -536,7 +529,7 @@ static int git_treebuilder__write_with_buffer(
...
@@ -536,7 +529,7 @@ static int git_treebuilder__write_with_buffer(
git_str_printf
(
buf
,
"%o "
,
entry
->
attr
);
git_str_printf
(
buf
,
"%o "
,
entry
->
attr
);
git_str_put
(
buf
,
entry
->
filename
,
entry
->
filename_len
+
1
);
git_str_put
(
buf
,
entry
->
filename
,
entry
->
filename_len
+
1
);
git_str_put
(
buf
,
(
char
*
)
entry
->
oid
->
id
,
GIT_OID_RAWSZ
);
git_str_put
(
buf
,
(
char
*
)
entry
->
oid
.
id
,
GIT_OID_RAWSZ
);
if
(
git_str_oom
(
buf
))
{
if
(
git_str_oom
(
buf
))
{
error
=
-
1
;
error
=
-
1
;
...
@@ -765,7 +758,7 @@ int git_treebuilder_new(
...
@@ -765,7 +758,7 @@ int git_treebuilder_new(
git_array_foreach
(
source
->
entries
,
i
,
entry_src
)
{
git_array_foreach
(
source
->
entries
,
i
,
entry_src
)
{
if
(
append_entry
(
if
(
append_entry
(
bld
,
entry_src
->
filename
,
bld
,
entry_src
->
filename
,
entry_src
->
oid
,
&
entry_src
->
oid
,
entry_src
->
attr
,
entry_src
->
attr
,
false
)
<
0
)
false
)
<
0
)
goto
on_error
;
goto
on_error
;
...
@@ -798,7 +791,7 @@ int git_treebuilder_insert(
...
@@ -798,7 +791,7 @@ int git_treebuilder_insert(
return
error
;
return
error
;
if
((
entry
=
git_strmap_get
(
bld
->
map
,
filename
))
!=
NULL
)
{
if
((
entry
=
git_strmap_get
(
bld
->
map
,
filename
))
!=
NULL
)
{
git_oid_cpy
(
(
git_oid
*
)
entry
->
oid
,
id
);
git_oid_cpy
(
&
entry
->
oid
,
id
);
}
else
{
}
else
{
entry
=
alloc_entry
(
filename
,
strlen
(
filename
),
id
);
entry
=
alloc_entry
(
filename
,
strlen
(
filename
),
id
);
GIT_ERROR_CHECK_ALLOC
(
entry
);
GIT_ERROR_CHECK_ALLOC
(
entry
);
...
@@ -954,7 +947,7 @@ int git_tree_entry_bypath(
...
@@ -954,7 +947,7 @@ int git_tree_entry_bypath(
return
git_tree_entry_dup
(
entry_out
,
entry
);
return
git_tree_entry_dup
(
entry_out
,
entry
);
}
}
if
(
git_tree_lookup
(
&
subtree
,
root
->
object
.
repo
,
entry
->
oid
)
<
0
)
if
(
git_tree_lookup
(
&
subtree
,
root
->
object
.
repo
,
&
entry
->
oid
)
<
0
)
return
-
1
;
return
-
1
;
error
=
git_tree_entry_bypath
(
error
=
git_tree_entry_bypath
(
...
@@ -995,7 +988,7 @@ static int tree_walk(
...
@@ -995,7 +988,7 @@ static int tree_walk(
git_tree
*
subtree
;
git_tree
*
subtree
;
size_t
path_len
=
git_str_len
(
path
);
size_t
path_len
=
git_str_len
(
path
);
error
=
git_tree_lookup
(
&
subtree
,
tree
->
object
.
repo
,
entry
->
oid
);
error
=
git_tree_lookup
(
&
subtree
,
tree
->
object
.
repo
,
&
entry
->
oid
);
if
(
error
<
0
)
if
(
error
<
0
)
break
;
break
;
...
...
src/libgit2/tree.h
View file @
3b52e5f5
...
@@ -19,7 +19,7 @@
...
@@ -19,7 +19,7 @@
struct
git_tree_entry
{
struct
git_tree_entry
{
uint16_t
attr
;
uint16_t
attr
;
uint16_t
filename_len
;
uint16_t
filename_len
;
const
git_oid
*
oid
;
git_oid
oid
;
const
char
*
filename
;
const
char
*
filename
;
};
};
...
...
tests/libgit2/iterator/tree.c
View file @
3b52e5f5
...
@@ -268,7 +268,7 @@ static void check_tree_entry(
...
@@ -268,7 +268,7 @@ static void check_tree_entry(
cl_git_pass
(
git_iterator_current_tree_entry
(
&
te
,
i
));
cl_git_pass
(
git_iterator_current_tree_entry
(
&
te
,
i
));
cl_assert
(
te
);
cl_assert
(
te
);
cl_assert
(
git_oid_streq
(
te
->
oid
,
oid
)
==
0
);
cl_assert
(
git_oid_streq
(
&
te
->
oid
,
oid
)
==
0
);
cl_git_pass
(
git_iterator_current
(
&
ie
,
i
));
cl_git_pass
(
git_iterator_current
(
&
ie
,
i
));
...
...
tests/libgit2/object/raw/hash.c
View file @
3b52e5f5
...
@@ -24,20 +24,23 @@ static char *bye_text = "bye world\n";
...
@@ -24,20 +24,23 @@ static char *bye_text = "bye world\n";
void
test_object_raw_hash__hash_by_blocks
(
void
)
void
test_object_raw_hash__hash_by_blocks
(
void
)
{
{
git_hash_ctx
ctx
;
git_hash_ctx
ctx
;
unsigned
char
hash
[
GIT_HASH_SHA1_SIZE
];
git_oid
id1
,
id2
;
git_oid
id1
,
id2
;
cl_git_pass
(
git_hash_ctx_init
(
&
ctx
,
GIT_HASH_ALGORITHM_SHA1
));
cl_git_pass
(
git_hash_ctx_init
(
&
ctx
,
GIT_HASH_ALGORITHM_SHA1
));
/* should already be init'd */
/* should already be init'd */
cl_git_pass
(
git_hash_update
(
&
ctx
,
hello_text
,
strlen
(
hello_text
)));
cl_git_pass
(
git_hash_update
(
&
ctx
,
hello_text
,
strlen
(
hello_text
)));
cl_git_pass
(
git_hash_final
(
id2
.
id
,
&
ctx
));
cl_git_pass
(
git_hash_final
(
hash
,
&
ctx
));
cl_git_pass
(
git_oid_fromraw
(
&
id2
,
hash
));
cl_git_pass
(
git_oid_fromstr
(
&
id1
,
hello_id
));
cl_git_pass
(
git_oid_fromstr
(
&
id1
,
hello_id
));
cl_assert
(
git_oid_cmp
(
&
id1
,
&
id2
)
==
0
);
cl_assert
(
git_oid_cmp
(
&
id1
,
&
id2
)
==
0
);
/* reinit should permit reuse */
/* reinit should permit reuse */
cl_git_pass
(
git_hash_init
(
&
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_update
(
&
ctx
,
bye_text
,
strlen
(
bye_text
)));
cl_git_pass
(
git_hash_final
(
id2
.
id
,
&
ctx
));
cl_git_pass
(
git_hash_final
(
hash
,
&
ctx
));
cl_git_pass
(
git_oid_fromraw
(
&
id2
,
hash
));
cl_git_pass
(
git_oid_fromstr
(
&
id1
,
bye_id
));
cl_git_pass
(
git_oid_fromstr
(
&
id1
,
bye_id
));
cl_assert
(
git_oid_cmp
(
&
id1
,
&
id2
)
==
0
);
cl_assert
(
git_oid_cmp
(
&
id1
,
&
id2
)
==
0
);
...
@@ -47,9 +50,11 @@ void test_object_raw_hash__hash_by_blocks(void)
...
@@ -47,9 +50,11 @@ void test_object_raw_hash__hash_by_blocks(void)
void
test_object_raw_hash__hash_buffer_in_single_call
(
void
)
void
test_object_raw_hash__hash_buffer_in_single_call
(
void
)
{
{
git_oid
id1
,
id2
;
git_oid
id1
,
id2
;
unsigned
char
hash
[
GIT_HASH_SHA1_SIZE
];
cl_git_pass
(
git_oid_fromstr
(
&
id1
,
hello_id
));
cl_git_pass
(
git_oid_fromstr
(
&
id1
,
hello_id
));
git_hash_buf
(
id2
.
id
,
hello_text
,
strlen
(
hello_text
),
GIT_HASH_ALGORITHM_SHA1
);
cl_git_pass
(
git_hash_buf
(
hash
,
hello_text
,
strlen
(
hello_text
),
GIT_HASH_ALGORITHM_SHA1
));
cl_git_pass
(
git_oid_fromraw
(
&
id2
,
hash
));
cl_assert
(
git_oid_cmp
(
&
id1
,
&
id2
)
==
0
);
cl_assert
(
git_oid_cmp
(
&
id1
,
&
id2
)
==
0
);
}
}
...
...
tests/libgit2/object/raw/short.c
View file @
3b52e5f5
...
@@ -28,12 +28,15 @@ static int insert_sequential_oids(
...
@@ -28,12 +28,15 @@ static int insert_sequential_oids(
int
i
,
min_len
=
0
;
int
i
,
min_len
=
0
;
char
numbuf
[
16
];
char
numbuf
[
16
];
git_oid
oid
;
git_oid
oid
;
unsigned
char
hashbuf
[
GIT_HASH_SHA1_SIZE
];
char
**
oids
=
git__calloc
(
n
,
sizeof
(
char
*
));
char
**
oids
=
git__calloc
(
n
,
sizeof
(
char
*
));
cl_assert
(
oids
!=
NULL
);
cl_assert
(
oids
!=
NULL
);
for
(
i
=
0
;
i
<
n
;
++
i
)
{
for
(
i
=
0
;
i
<
n
;
++
i
)
{
p_snprintf
(
numbuf
,
sizeof
(
numbuf
),
"%u"
,
(
unsigned
int
)
i
);
p_snprintf
(
numbuf
,
sizeof
(
numbuf
),
"%u"
,
(
unsigned
int
)
i
);
git_hash_buf
(
oid
.
id
,
numbuf
,
strlen
(
numbuf
),
GIT_HASH_ALGORITHM_SHA1
);
git_hash_buf
(
hashbuf
,
numbuf
,
strlen
(
numbuf
),
GIT_HASH_ALGORITHM_SHA1
);
git_oid_fromraw
(
&
oid
,
hashbuf
);
oids
[
i
]
=
git__malloc
(
GIT_OID_HEXSZ
+
1
);
oids
[
i
]
=
git__malloc
(
GIT_OID_HEXSZ
+
1
);
cl_assert
(
oids
[
i
]);
cl_assert
(
oids
[
i
]);
...
...
tests/libgit2/object/tree/parse.c
View file @
3b52e5f5
...
@@ -40,7 +40,7 @@ static void assert_tree_parses(const char *data, size_t datalen,
...
@@ -40,7 +40,7 @@ static void assert_tree_parses(const char *data, size_t datalen,
cl_assert
(
entry
=
git_tree_entry_byname
(
tree
,
expected
->
filename
));
cl_assert
(
entry
=
git_tree_entry_byname
(
tree
,
expected
->
filename
));
cl_assert_equal_s
(
expected
->
filename
,
entry
->
filename
);
cl_assert_equal_s
(
expected
->
filename
,
entry
->
filename
);
cl_assert_equal_i
(
expected
->
attr
,
entry
->
attr
);
cl_assert_equal_i
(
expected
->
attr
,
entry
->
attr
);
cl_assert_equal_oid
(
&
oid
,
entry
->
oid
);
cl_assert_equal_oid
(
&
oid
,
&
entry
->
oid
);
}
}
git_object_free
(
&
tree
->
object
);
git_object_free
(
&
tree
->
object
);
...
...
tests/libgit2/pack/packbuilder.c
View file @
3b52e5f5
...
@@ -68,7 +68,7 @@ static void seed_packbuilder(void)
...
@@ -68,7 +68,7 @@ static void seed_packbuilder(void)
cl_git_pass
(
git_revwalk_push_ref
(
_revwalker
,
"HEAD"
));
cl_git_pass
(
git_revwalk_push_ref
(
_revwalker
,
"HEAD"
));
while
(
git_revwalk_next
(
&
oid
,
_revwalker
)
==
0
)
{
while
(
git_revwalk_next
(
&
oid
,
_revwalker
)
==
0
)
{
o
=
git__malloc
(
GIT_OID_RAWSZ
);
o
=
git__malloc
(
sizeof
(
git_oid
)
);
cl_assert
(
o
!=
NULL
);
cl_assert
(
o
!=
NULL
);
git_oid_cpy
(
o
,
&
oid
);
git_oid_cpy
(
o
,
&
oid
);
cl_git_pass
(
git_vector_insert
(
&
_commits
,
o
));
cl_git_pass
(
git_vector_insert
(
&
_commits
,
o
));
...
...
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