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
7b083d3c
Unverified
Commit
7b083d3c
authored
Mar 02, 2019
by
Edward Thomson
Committed by
GitHub
Mar 02, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #5005 from libgit2/ethomson/odb_backend_allocations
odb: provide a free function for custom backends
parents
c7e5eca6
459ac856
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
58 additions
and
3 deletions
+58
-3
include/git2/sys/odb_backend.h
+46
-2
src/odb.c
+12
-1
No files found.
include/git2/sys/odb_backend.h
View file @
7b083d3c
...
...
@@ -30,8 +30,8 @@ struct git_odb_backend {
/* read and read_prefix each return to libgit2 a buffer which
* will be freed later. The buffer should be allocated using
* the function git_odb_backend_
malloc to ensure that it can
*
be safely freed
later. */
* the function git_odb_backend_
data_alloc to ensure that libgit2
*
can safely free it
later. */
int
GIT_CALLBACK
(
read
)(
void
**
,
size_t
*
,
git_object_t
*
,
git_odb_backend
*
,
const
git_oid
*
);
...
...
@@ -117,8 +117,52 @@ GIT_EXTERN(int) git_odb_init_backend(
git_odb_backend
*
backend
,
unsigned
int
version
);
/**
* Allocate data for an ODB object. Custom ODB backends may use this
* to provide data back to the ODB from their read function. This
* memory should not be freed once it is returned to libgit2. If a
* custom ODB uses this function but encounters an error and does not
* return this data to libgit2, then they should use the corresponding
* git_odb_backend_data_free function.
*
* @param backend the ODB backend that is allocating this memory
* @param len the number of bytes to allocate
* @return the allocated buffer on success or NULL if out of memory
*/
GIT_EXTERN
(
void
*
)
git_odb_backend_data_alloc
(
git_odb_backend
*
backend
,
size_t
len
);
/**
* Frees custom allocated ODB data. This should only be called when
* memory allocated using git_odb_backend_data_alloc is not returned
* to libgit2 because the backend encountered an error in the read
* function after allocation and did not return this data to libgit2.
*
* @param backend the ODB backend that is freeing this memory
* @param data the buffer to free
*/
GIT_EXTERN
(
void
)
git_odb_backend_data_free
(
git_odb_backend
*
backend
,
void
*
data
);
/*
* Users can avoid deprecated functions by defining `GIT_DEPRECATE_HARD`.
*/
#ifndef GIT_DEPRECATE_HARD
/**
* Allocate memory for an ODB object from a custom backend. This is
* an alias of `git_odb_backend_data_alloc` and is preserved for
* backward compatibility.
*
* This function is deprecated, but there is no plan to remove this
* function at this time.
*
* @deprecated git_odb_backend_data_alloc
* @see git_odb_backend_data_alloc
*/
GIT_EXTERN
(
void
*
)
git_odb_backend_malloc
(
git_odb_backend
*
backend
,
size_t
len
);
#endif
GIT_END_DECL
#endif
src/odb.c
View file @
7b083d3c
...
...
@@ -1497,12 +1497,23 @@ int git_odb_write_pack(struct git_odb_writepack **out, git_odb *db, git_indexer_
return
error
;
}
void
*
git_odb_backend_
m
alloc
(
git_odb_backend
*
backend
,
size_t
len
)
void
*
git_odb_backend_
data_
alloc
(
git_odb_backend
*
backend
,
size_t
len
)
{
GIT_UNUSED
(
backend
);
return
git__malloc
(
len
);
}
void
*
git_odb_backend_malloc
(
git_odb_backend
*
backend
,
size_t
len
)
{
return
git_odb_backend_data_alloc
(
backend
,
len
);
}
void
git_odb_backend_data_free
(
git_odb_backend
*
backend
,
void
*
data
)
{
GIT_UNUSED
(
backend
);
git__free
(
data
);
}
int
git_odb_refresh
(
struct
git_odb
*
db
)
{
size_t
i
;
...
...
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