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
9de27ad0
Commit
9de27ad0
authored
Feb 25, 2011
by
Sakari Jokinen
Committed by
Vicent Marti
Mar 05, 2011
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Check for valid range of attributes for tree entry
parent
3490188b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
5 deletions
+19
-5
include/git2/tree.h
+1
-1
src/tree.c
+18
-4
No files found.
include/git2/tree.h
View file @
9de27ad0
...
...
@@ -215,7 +215,7 @@ GIT_EXTERN(void) git_tree_entry_set_name(git_tree_entry *entry, const char *name
* @param entry Entry object which will be modified
* @param oid new attributes for the entry
*/
GIT_EXTERN
(
void
)
git_tree_entry_set_attributes
(
git_tree_entry
*
entry
,
int
attr
);
GIT_EXTERN
(
int
)
git_tree_entry_set_attributes
(
git_tree_entry
*
entry
,
int
attr
);
/** @} */
GIT_END_DECL
...
...
src/tree.c
View file @
9de27ad0
...
...
@@ -31,6 +31,8 @@
#include "git2/object.h"
#define DEFAULT_TREE_SIZE 16
#define MAX_FILEMODE 0777777
#define MAX_FILEMODE_BYTES 6
int
entry_search_cmp
(
const
void
*
key
,
const
void
*
array_member
)
{
...
...
@@ -40,6 +42,10 @@ int entry_search_cmp(const void *key, const void *array_member)
return
strcmp
(
filename
,
entry
->
filename
);
}
static
int
valid_attributes
(
const
int
attributes
)
{
return
attributes
>=
0
&&
attributes
<=
MAX_FILEMODE
;
}
int
entry_sort_cmp
(
const
void
*
a
,
const
void
*
b
)
{
const
git_tree_entry
*
entry_a
=
*
(
const
git_tree_entry
**
)(
a
);
...
...
@@ -101,12 +107,17 @@ const git_oid *git_tree_id(git_tree *c)
return
git_object_id
((
git_object
*
)
c
);
}
void
git_tree_entry_set_attributes
(
git_tree_entry
*
entry
,
int
attr
)
int
git_tree_entry_set_attributes
(
git_tree_entry
*
entry
,
int
attr
)
{
assert
(
entry
&&
entry
->
owner
);
if
(
!
valid_attributes
(
attr
))
{
return
GIT_ERROR
;
}
entry
->
attr
=
attr
;
entry
->
owner
->
object
.
modified
=
1
;
return
GIT_SUCCESS
;
}
void
git_tree_entry_set_name
(
git_tree_entry
*
entry
,
const
char
*
name
)
...
...
@@ -190,6 +201,9 @@ int git_tree_add_entry(git_tree_entry **entry_out, git_tree *tree, const git_oid
git_tree_entry
*
entry
;
assert
(
tree
&&
id
&&
filename
);
if
(
!
valid_attributes
(
attributes
))
{
return
GIT_ERROR
;
}
if
((
entry
=
git__malloc
(
sizeof
(
git_tree_entry
)))
==
NULL
)
return
GIT_ENOMEM
;
...
...
@@ -249,7 +263,7 @@ int git_tree_remove_entry_byname(git_tree *tree, const char *filename)
int
git_tree__writeback
(
git_tree
*
tree
,
git_odb_source
*
src
)
{
size_t
i
;
char
filemode
[
8
];
char
filemode
[
MAX_FILEMODE_BYTES
+
1
+
1
];
assert
(
tree
&&
src
);
...
...
@@ -263,8 +277,8 @@ int git_tree__writeback(git_tree *tree, git_odb_source *src)
entry
=
git_vector_get
(
&
tree
->
entries
,
i
);
s
printf
(
filemode
,
"%o "
,
entry
->
attr
);
s
nprintf
(
filemode
,
sizeof
(
filemode
)
,
"%o "
,
entry
->
attr
);
git__source_write
(
src
,
filemode
,
strlen
(
filemode
));
git__source_write
(
src
,
entry
->
filename
,
strlen
(
entry
->
filename
)
+
1
);
git__source_write
(
src
,
entry
->
oid
.
id
,
GIT_OID_RAWSZ
);
...
...
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