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
97e57e87
Commit
97e57e87
authored
Aug 08, 2016
by
Carlos Martín Nieto
Committed by
GitHub
Aug 08, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3887 from libgit2/ethomson/empty_blob
odb: only provide the empty tree
parents
b47e79e2
9bc8c80f
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
49 additions
and
51 deletions
+49
-51
src/odb.c
+0
-5
tests/index/collision.c
+29
-31
tests/odb/emptyobjects.c
+15
-14
tests/reset/hard.c
+5
-1
No files found.
src/odb.c
View file @
97e57e87
...
...
@@ -54,14 +54,9 @@ static int load_alternates(git_odb *odb, const char *objects_dir, int alternate_
static
git_otype
odb_hardcoded_type
(
const
git_oid
*
id
)
{
static
git_oid
empty_blob
=
{{
0xe6
,
0x9d
,
0xe2
,
0x9b
,
0xb2
,
0xd1
,
0xd6
,
0x43
,
0x4b
,
0x8b
,
0x29
,
0xae
,
0x77
,
0x5a
,
0xd8
,
0xc2
,
0xe4
,
0x8c
,
0x53
,
0x91
}};
static
git_oid
empty_tree
=
{{
0x4b
,
0x82
,
0x5d
,
0xc6
,
0x42
,
0xcb
,
0x6e
,
0xb9
,
0xa0
,
0x60
,
0xe5
,
0x4b
,
0xf8
,
0xd6
,
0x92
,
0x88
,
0xfb
,
0xee
,
0x49
,
0x04
}};
if
(
!
git_oid_cmp
(
id
,
&
empty_blob
))
return
GIT_OBJ_BLOB
;
if
(
!
git_oid_cmp
(
id
,
&
empty_tree
))
return
GIT_OBJ_TREE
;
...
...
tests/index/collision.c
View file @
97e57e87
...
...
@@ -2,105 +2,103 @@
#include "git2/repository.h"
#include "git2/index.h"
git_repository
*
repo
=
NULL
;
static
git_repository
*
g_repo
;
static
git_odb
*
g_odb
;
static
git_index
*
g_index
;
static
git_oid
g_empty_id
;
void
test_index_collision__initialize
(
void
)
{
g_repo
=
cl_git_sandbox_init
(
"empty_standard_repo"
);
cl_git_pass
(
git_repository_odb
(
&
g_odb
,
g_repo
));
cl_git_pass
(
git_repository_index
(
&
g_index
,
g_repo
));
cl_git_pass
(
git_odb_write
(
&
g_empty_id
,
g_odb
,
""
,
0
,
GIT_OBJ_BLOB
));
}
void
test_index_collision__cleanup
(
void
)
{
git_index_free
(
g_index
);
git_odb_free
(
g_odb
);
cl_git_sandbox_cleanup
();
repo
=
NULL
;
}
void
test_index_collision__add
(
void
)
{
git_index
*
index
;
git_index_entry
entry
;
git_oid
tree_id
;
git_tree
*
tree
;
repo
=
cl_git_sandbox_init
(
"empty_standard_repo"
);
cl_git_pass
(
git_repository_index
(
&
index
,
repo
));
memset
(
&
entry
,
0
,
sizeof
(
entry
));
entry
.
ctime
.
seconds
=
12346789
;
entry
.
mtime
.
seconds
=
12346789
;
entry
.
mode
=
0100644
;
entry
.
file_size
=
0
;
git_oid_
fromstr
(
&
entry
.
id
,
"e69de29bb2d1d6434b8b29ae775ad8c2e48c5391"
);
git_oid_
cpy
(
&
entry
.
id
,
&
g_empty_id
);
entry
.
path
=
"a/b"
;
cl_git_pass
(
git_index_add
(
index
,
&
entry
));
cl_git_pass
(
git_index_add
(
g_
index
,
&
entry
));
/* create a tree/blob collision */
entry
.
path
=
"a/b/c"
;
cl_git_fail
(
git_index_add
(
index
,
&
entry
));
cl_git_fail
(
git_index_add
(
g_
index
,
&
entry
));
cl_git_pass
(
git_index_write_tree
(
&
tree_id
,
index
));
cl_git_pass
(
git_tree_lookup
(
&
tree
,
repo
,
&
tree_id
));
cl_git_pass
(
git_index_write_tree
(
&
tree_id
,
g_
index
));
cl_git_pass
(
git_tree_lookup
(
&
tree
,
g_
repo
,
&
tree_id
));
git_tree_free
(
tree
);
git_index_free
(
index
);
}
void
test_index_collision__add_with_highstage_1
(
void
)
{
git_index
*
index
;
git_index_entry
entry
;
repo
=
cl_git_sandbox_init
(
"empty_standard_repo"
);
cl_git_pass
(
git_repository_index
(
&
index
,
repo
));
memset
(
&
entry
,
0
,
sizeof
(
entry
));
entry
.
ctime
.
seconds
=
12346789
;
entry
.
mtime
.
seconds
=
12346789
;
entry
.
mode
=
0100644
;
entry
.
file_size
=
0
;
git_oid_
fromstr
(
&
entry
.
id
,
"e69de29bb2d1d6434b8b29ae775ad8c2e48c5391"
);
git_oid_
cpy
(
&
entry
.
id
,
&
g_empty_id
);
entry
.
path
=
"a/b"
;
GIT_IDXENTRY_STAGE_SET
(
&
entry
,
2
);
cl_git_pass
(
git_index_add
(
index
,
&
entry
));
cl_git_pass
(
git_index_add
(
g_
index
,
&
entry
));
/* create a blob beneath the previous tree entry */
entry
.
path
=
"a/b/c"
;
entry
.
flags
=
0
;
cl_git_pass
(
git_index_add
(
index
,
&
entry
));
cl_git_pass
(
git_index_add
(
g_
index
,
&
entry
));
/* create another tree entry above the blob */
entry
.
path
=
"a/b"
;
GIT_IDXENTRY_STAGE_SET
(
&
entry
,
1
);
cl_git_pass
(
git_index_add
(
index
,
&
entry
));
git_index_free
(
index
);
cl_git_pass
(
git_index_add
(
g_index
,
&
entry
));
}
void
test_index_collision__add_with_highstage_2
(
void
)
{
git_index
*
index
;
git_index_entry
entry
;
repo
=
cl_git_sandbox_init
(
"empty_standard_repo"
);
cl_git_pass
(
git_repository_index
(
&
index
,
repo
));
cl_git_pass
(
git_repository_index
(
&
g_index
,
g_repo
));
memset
(
&
entry
,
0
,
sizeof
(
entry
));
entry
.
ctime
.
seconds
=
12346789
;
entry
.
mtime
.
seconds
=
12346789
;
entry
.
mode
=
0100644
;
entry
.
file_size
=
0
;
git_oid_
fromstr
(
&
entry
.
id
,
"e69de29bb2d1d6434b8b29ae775ad8c2e48c5391"
);
git_oid_
cpy
(
&
entry
.
id
,
&
g_empty_id
);
entry
.
path
=
"a/b/c"
;
GIT_IDXENTRY_STAGE_SET
(
&
entry
,
1
);
cl_git_pass
(
git_index_add
(
index
,
&
entry
));
cl_git_pass
(
git_index_add
(
g_
index
,
&
entry
));
/* create a blob beneath the previous tree entry */
entry
.
path
=
"a/b/c"
;
GIT_IDXENTRY_STAGE_SET
(
&
entry
,
2
);
cl_git_pass
(
git_index_add
(
index
,
&
entry
));
cl_git_pass
(
git_index_add
(
g_
index
,
&
entry
));
/* create another tree entry above the blob */
entry
.
path
=
"a/b"
;
GIT_IDXENTRY_STAGE_SET
(
&
entry
,
3
);
cl_git_pass
(
git_index_add
(
index
,
&
entry
));
git_index_free
(
index
);
cl_git_pass
(
git_index_add
(
g_index
,
&
entry
));
}
tests/odb/emptyobjects.c
View file @
97e57e87
...
...
@@ -2,29 +2,33 @@
#include "odb.h"
#include "filebuf.h"
#define TEST_REPO_PATH "redundant.git"
git_repository
*
g_repo
;
git_odb
*
g_odb
;
void
test_odb_emptyobjects__initialize
(
void
)
{
cl_git_pass
(
git_repository_open
(
&
g_repo
,
cl_fixture
(
"testrepo.git"
)));
g_repo
=
cl_git_sandbox_init
(
TEST_REPO_PATH
);
cl_git_pass
(
git_repository_odb
(
&
g_odb
,
g_repo
));
}
void
test_odb_emptyobjects__cleanup
(
void
)
{
git_repository_free
(
g_repo
);
git_odb_free
(
g_odb
);
cl_git_sandbox_cleanup
();
}
void
test_odb_emptyobjects__
rea
d
(
void
)
void
test_odb_emptyobjects__
blob_notfoun
d
(
void
)
{
git_oid
id
;
git_oid
id
,
written_id
;
git_blob
*
blob
;
cl_git_pass
(
git_oid_fromstr
(
&
id
,
"e69de29bb2d1d6434b8b29ae775ad8c2e48c5391"
));
cl_git_pass
(
git_blob_lookup
(
&
blob
,
g_repo
,
&
id
));
cl_assert_equal_i
(
GIT_OBJ_BLOB
,
git_object_type
((
git_object
*
)
blob
));
cl_assert
(
git_blob_rawcontent
(
blob
));
cl_assert_equal_s
(
""
,
git_blob_rawcontent
(
blob
));
cl_assert_equal_i
(
0
,
git_blob_rawsize
(
blob
));
git_blob_free
(
blob
);
cl_git_fail_with
(
GIT_ENOTFOUND
,
git_blob_lookup
(
&
blob
,
g_repo
,
&
id
));
cl_git_pass
(
git_odb_write
(
&
written_id
,
g_odb
,
""
,
0
,
GIT_OBJ_BLOB
));
cl_assert
(
git_path_exists
(
TEST_REPO_PATH
"/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391"
));
}
void
test_odb_emptyobjects__read_tree
(
void
)
...
...
@@ -43,15 +47,12 @@ void test_odb_emptyobjects__read_tree(void)
void
test_odb_emptyobjects__read_tree_odb
(
void
)
{
git_oid
id
;
git_odb
*
odb
;
git_odb_object
*
tree_odb
;
cl_git_pass
(
git_oid_fromstr
(
&
id
,
"4b825dc642cb6eb9a060e54bf8d69288fbee4904"
));
cl_git_pass
(
git_repository_odb
(
&
odb
,
g_repo
));
cl_git_pass
(
git_odb_read
(
&
tree_odb
,
odb
,
&
id
));
cl_git_pass
(
git_odb_read
(
&
tree_odb
,
g_odb
,
&
id
));
cl_assert
(
git_odb_object_data
(
tree_odb
));
cl_assert_equal_s
(
""
,
git_odb_object_data
(
tree_odb
));
cl_assert_equal_i
(
0
,
git_odb_object_size
(
tree_odb
));
git_odb_object_free
(
tree_odb
);
git_odb_free
(
odb
);
}
tests/reset/hard.c
View file @
97e57e87
...
...
@@ -240,14 +240,18 @@ void test_reset_hard__switch_file_to_dir(void)
{
git_index_entry
entry
=
{{
0
}};
git_index
*
idx
;
git_odb
*
odb
;
git_object
*
commit
;
git_tree
*
tree
;
git_signature
*
sig
;
git_oid
src_tree_id
,
tgt_tree_id
;
git_oid
src_id
,
tgt_id
;
cl_git_pass
(
git_repository_odb
(
&
odb
,
repo
));
cl_git_pass
(
git_odb_write
(
&
entry
.
id
,
odb
,
""
,
0
,
GIT_OBJ_BLOB
));
git_odb_free
(
odb
);
entry
.
mode
=
GIT_FILEMODE_BLOB
;
cl_git_pass
(
git_oid_fromstr
(
&
entry
.
id
,
"e69de29bb2d1d6434b8b29ae775ad8c2e48c5391"
));
cl_git_pass
(
git_index_new
(
&
idx
));
cl_git_pass
(
git_signature_now
(
&
sig
,
"foo"
,
"bar"
));
...
...
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