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
25992373
Commit
25992373
authored
Dec 07, 2012
by
Vicent Martí
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1123 from carlosmn/lax-tree
tree: relax the filemode parser
parents
fac43c54
f1c75b94
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
48 additions
and
36 deletions
+48
-36
src/tree.c
+26
-19
tests-clar/object/tree/attributes.c
+22
-17
tests-clar/resources/deprecated-mode.git/objects/08/10fb7818088ff5ac41ee49199b51473b1bd6c7
+0
-0
No files found.
src/tree.c
View file @
25992373
...
...
@@ -18,12 +18,33 @@ static bool valid_filemode(const int filemode)
{
return
(
filemode
==
GIT_FILEMODE_TREE
||
filemode
==
GIT_FILEMODE_BLOB
||
filemode
==
GIT_FILEMODE_BLOB_GROUP_WRITABLE
||
filemode
==
GIT_FILEMODE_BLOB_EXECUTABLE
||
filemode
==
GIT_FILEMODE_LINK
||
filemode
==
GIT_FILEMODE_COMMIT
);
}
GIT_INLINE
(
git_filemode_t
)
normalize_filemode
(
git_filemode_t
filemode
)
{
/* Tree bits set, but it's not a commit */
if
(
filemode
&
GIT_FILEMODE_TREE
&&
!
(
filemode
&
0100000
))
return
GIT_FILEMODE_TREE
;
/* If any of the x bits is set */
if
(
filemode
&
0111
)
return
GIT_FILEMODE_BLOB_EXECUTABLE
;
/* 16XXXX means commit */
if
((
filemode
&
GIT_FILEMODE_COMMIT
)
==
GIT_FILEMODE_COMMIT
)
return
GIT_FILEMODE_COMMIT
;
/* 12XXXX means commit */
if
((
filemode
&
GIT_FILEMODE_LINK
)
==
GIT_FILEMODE_LINK
)
return
GIT_FILEMODE_LINK
;
/* Otherwise, return a blob */
return
GIT_FILEMODE_BLOB
;
}
static
int
valid_entry_name
(
const
char
*
filename
)
{
return
*
filename
!=
'\0'
&&
...
...
@@ -320,10 +341,11 @@ static int tree_parse_buffer(git_tree *tree, const char *buffer, const char *buf
git_tree_entry
*
entry
;
int
attr
;
if
(
git__strtol32
(
&
attr
,
buffer
,
&
buffer
,
8
)
<
0
||
!
buffer
||
!
valid_filemode
(
attr
))
if
(
git__strtol32
(
&
attr
,
buffer
,
&
buffer
,
8
)
<
0
||
!
buffer
)
return
tree_error
(
"Failed to parse tree. Can't parse filemode"
,
NULL
);
attr
=
normalize_filemode
(
attr
);
/* make sure to normalize the filemode */
if
(
*
buffer
++
!=
' '
)
return
tree_error
(
"Failed to parse tree. Object is corrupted"
,
NULL
);
...
...
@@ -529,19 +551,6 @@ static void sort_entries(git_treebuilder *bld)
git_vector_sort
(
&
bld
->
entries
);
}
GIT_INLINE
(
git_filemode_t
)
normalize_filemode
(
git_filemode_t
filemode
)
{
/* 100664 mode is an early design mistake. Tree entries may bear
* this mode in some old git repositories, but it's now deprecated.
* We silently normalize while inserting new entries in a tree
* being built.
*/
if
(
filemode
==
GIT_FILEMODE_BLOB_GROUP_WRITABLE
)
return
GIT_FILEMODE_BLOB
;
return
filemode
;
}
int
git_treebuilder_create
(
git_treebuilder
**
builder_p
,
const
git_tree
*
source
)
{
git_treebuilder
*
bld
;
...
...
@@ -565,7 +574,7 @@ int git_treebuilder_create(git_treebuilder **builder_p, const git_tree *source)
if
(
append_entry
(
bld
,
entry_src
->
filename
,
&
entry_src
->
oid
,
normalize_filemode
((
git_filemode_t
)
entry_src
->
attr
)
)
<
0
)
entry_src
->
attr
)
<
0
)
goto
on_error
;
}
}
...
...
@@ -593,8 +602,6 @@ int git_treebuilder_insert(
if
(
!
valid_filemode
(
filemode
))
return
tree_error
(
"Failed to insert entry. Invalid filemode for file"
,
filename
);
filemode
=
normalize_filemode
(
filemode
);
if
(
!
valid_entry_name
(
filename
))
return
tree_error
(
"Failed to insert entry. Invalid name for a tree entry"
,
filename
);
...
...
tests-clar/object/tree/attributes.c
View file @
25992373
...
...
@@ -34,14 +34,14 @@ void test_object_tree_attributes__group_writable_tree_entries_created_with_an_an
entry
=
git_tree_entry_byname
(
tree
,
"old_mode.txt"
);
cl_assert_equal_i
(
GIT_FILEMODE_BLOB
_GROUP_WRITABLE
,
GIT_FILEMODE_BLOB
,
git_tree_entry_filemode
(
entry
));
git_tree_free
(
tree
);
git_repository_free
(
repo
);
}
void
test_object_tree_attributes__
normalize_attributes_when_inserting_in_a_new_tre
e
(
void
)
void
test_object_tree_attributes__
treebuilder_reject_invalid_filemod
e
(
void
)
{
git_repository
*
repo
;
git_treebuilder
*
builder
;
...
...
@@ -55,28 +55,14 @@ void test_object_tree_attributes__normalize_attributes_when_inserting_in_a_new_t
cl_git_pass
(
git_treebuilder_create
(
&
builder
,
NULL
));
cl_git_
pass
(
git_treebuilder_insert
(
cl_git_
fail
(
git_treebuilder_insert
(
&
entry
,
builder
,
"normalized.txt"
,
&
bid
,
GIT_FILEMODE_BLOB_GROUP_WRITABLE
));
cl_assert_equal_i
(
GIT_FILEMODE_BLOB
,
git_tree_entry_filemode
(
entry
));
cl_git_pass
(
git_treebuilder_write
(
&
tid
,
repo
,
builder
));
git_treebuilder_free
(
builder
);
cl_git_pass
(
git_tree_lookup
(
&
tree
,
repo
,
&
tid
));
entry
=
git_tree_entry_byname
(
tree
,
"normalized.txt"
);
cl_assert_equal_i
(
GIT_FILEMODE_BLOB
,
git_tree_entry_filemode
(
entry
));
git_tree_free
(
tree
);
cl_git_sandbox_cleanup
();
}
...
...
@@ -113,3 +99,22 @@ void test_object_tree_attributes__normalize_attributes_when_creating_a_tree_from
git_tree_free
(
tree
);
cl_git_sandbox_cleanup
();
}
void
test_object_tree_attributes__normalize_600
(
void
)
{
git_oid
id
;
git_tree
*
tree
;
git_repository
*
repo
;
const
git_tree_entry
*
entry
;
repo
=
cl_git_sandbox_init
(
"deprecated-mode.git"
);
git_oid_fromstr
(
&
id
,
"0810fb7818088ff5ac41ee49199b51473b1bd6c7"
);
cl_git_pass
(
git_tree_lookup
(
&
tree
,
repo
,
&
id
));
entry
=
git_tree_entry_byname
(
tree
,
"ListaTeste.xml"
);
cl_assert_equal_i
(
entry
->
attr
,
GIT_FILEMODE_BLOB
);
git_tree_free
(
tree
);
cl_git_sandbox_cleanup
();
}
tests-clar/resources/deprecated-mode.git/objects/08/10fb7818088ff5ac41ee49199b51473b1bd6c7
0 → 100644
View file @
25992373
File added
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