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
d091a9db
Commit
d091a9db
authored
Jul 10, 2014
by
Carlos Martín Nieto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tree-cache: extract the allocation
parent
a6ed1fcb
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
12 deletions
+23
-12
src/tree-cache.c
+22
-12
src/tree-cache.h
+1
-0
No files found.
src/tree-cache.c
View file @
d091a9db
...
...
@@ -74,7 +74,6 @@ static int read_tree_internal(git_tree_cache **out,
git_tree_cache
*
tree
=
NULL
;
const
char
*
name_start
,
*
buffer
;
int
count
;
size_t
name_len
;
buffer
=
name_start
=
*
buffer_in
;
...
...
@@ -84,17 +83,8 @@ static int read_tree_internal(git_tree_cache **out,
if
(
++
buffer
>=
buffer_end
)
goto
corrupted
;
name_len
=
strlen
(
name_start
);
tree
=
git__malloc
(
sizeof
(
git_tree_cache
)
+
name_len
+
1
);
GITERR_CHECK_ALLOC
(
tree
);
memset
(
tree
,
0x0
,
sizeof
(
git_tree_cache
));
tree
->
parent
=
parent
;
/* NUL-terminated tree name */
tree
->
namelen
=
name_len
;
memcpy
(
tree
->
name
,
name_start
,
name_len
);
tree
->
name
[
name_len
]
=
'\0'
;
if
(
git_tree_cache_new
(
&
tree
,
name_start
,
parent
)
<
0
)
return
-
1
;
/* Blank-terminated ASCII decimal number of entries in this tree */
if
(
git__strtol32
(
&
count
,
buffer
,
&
buffer
,
10
)
<
0
)
...
...
@@ -164,6 +154,26 @@ int git_tree_cache_read(git_tree_cache **tree, const char *buffer, size_t buffer
return
0
;
}
int
git_tree_cache_new
(
git_tree_cache
**
out
,
const
char
*
name
,
git_tree_cache
*
parent
)
{
size_t
name_len
;
git_tree_cache
*
tree
;
name_len
=
strlen
(
name
);
tree
=
git__malloc
(
sizeof
(
git_tree_cache
)
+
name_len
+
1
);
GITERR_CHECK_ALLOC
(
tree
);
memset
(
tree
,
0x0
,
sizeof
(
git_tree_cache
));
tree
->
parent
=
parent
;
/* NUL-terminated tree name */
tree
->
namelen
=
name_len
;
memcpy
(
tree
->
name
,
name
,
name_len
);
tree
->
name
[
name_len
]
=
'\0'
;
*
out
=
tree
;
return
0
;
}
void
git_tree_cache_free
(
git_tree_cache
*
tree
)
{
unsigned
int
i
;
...
...
src/tree-cache.h
View file @
d091a9db
...
...
@@ -25,6 +25,7 @@ typedef struct {
int
git_tree_cache_read
(
git_tree_cache
**
tree
,
const
char
*
buffer
,
size_t
buffer_size
);
void
git_tree_cache_invalidate_path
(
git_tree_cache
*
tree
,
const
char
*
path
);
const
git_tree_cache
*
git_tree_cache_get
(
const
git_tree_cache
*
tree
,
const
char
*
path
);
int
git_tree_cache_new
(
git_tree_cache
**
out
,
const
char
*
name
,
git_tree_cache
*
parent
);
void
git_tree_cache_free
(
git_tree_cache
*
tree
);
#endif
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