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
cf97799e
Commit
cf97799e
authored
Apr 20, 2013
by
Vicent Martí
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1491 from ethomson/backends_dont_refdb
alloc doesn't take a refdb
parents
4a38143c
4e4eab52
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
38 additions
and
37 deletions
+38
-37
include/git2/refdb.h
+0
-2
include/git2/refdb_backend.h
+1
-2
src/refdb.c
+13
-2
src/refdb_fs.c
+4
-7
src/refs.c
+12
-13
tests-clar/refdb/inmemory.c
+3
-2
tests-clar/refdb/testdb.c
+2
-9
tests-clar/refs/delete.c
+1
-0
tests-clar/refs/pack.c
+1
-0
tests-clar/refs/rename.c
+1
-0
No files found.
include/git2/refdb.h
View file @
cf97799e
...
@@ -32,13 +32,11 @@ GIT_BEGIN_DECL
...
@@ -32,13 +32,11 @@ GIT_BEGIN_DECL
* @return the created git_reference or NULL on error
* @return the created git_reference or NULL on error
*/
*/
GIT_EXTERN
(
git_reference
*
)
git_reference__alloc
(
GIT_EXTERN
(
git_reference
*
)
git_reference__alloc
(
git_refdb
*
refdb
,
const
char
*
name
,
const
char
*
name
,
const
git_oid
*
oid
,
const
git_oid
*
oid
,
const
git_oid
*
peel
);
const
git_oid
*
peel
);
GIT_EXTERN
(
git_reference
*
)
git_reference__alloc_symbolic
(
GIT_EXTERN
(
git_reference
*
)
git_reference__alloc_symbolic
(
git_refdb
*
refdb
,
const
char
*
name
,
const
char
*
name
,
const
char
*
target
);
const
char
*
target
);
...
...
include/git2/refdb_backend.h
View file @
cf97799e
...
@@ -101,8 +101,7 @@ struct git_refdb_backend {
...
@@ -101,8 +101,7 @@ struct git_refdb_backend {
*/
*/
GIT_EXTERN
(
int
)
git_refdb_backend_fs
(
GIT_EXTERN
(
int
)
git_refdb_backend_fs
(
struct
git_refdb_backend
**
backend_out
,
struct
git_refdb_backend
**
backend_out
,
git_repository
*
repo
,
git_repository
*
repo
);
git_refdb
*
refdb
);
GIT_END_DECL
GIT_END_DECL
...
...
src/refdb.c
View file @
cf97799e
...
@@ -45,7 +45,7 @@ int git_refdb_open(git_refdb **out, git_repository *repo)
...
@@ -45,7 +45,7 @@ int git_refdb_open(git_refdb **out, git_repository *repo)
return
-
1
;
return
-
1
;
/* Add the default (filesystem) backend */
/* Add the default (filesystem) backend */
if
(
git_refdb_backend_fs
(
&
dir
,
repo
,
db
)
<
0
)
{
if
(
git_refdb_backend_fs
(
&
dir
,
repo
)
<
0
)
{
git_refdb_free
(
db
);
git_refdb_free
(
db
);
return
-
1
;
return
-
1
;
}
}
...
@@ -111,9 +111,20 @@ int git_refdb_exists(int *exists, git_refdb *refdb, const char *ref_name)
...
@@ -111,9 +111,20 @@ int git_refdb_exists(int *exists, git_refdb *refdb, const char *ref_name)
int
git_refdb_lookup
(
git_reference
**
out
,
git_refdb
*
db
,
const
char
*
ref_name
)
int
git_refdb_lookup
(
git_reference
**
out
,
git_refdb
*
db
,
const
char
*
ref_name
)
{
{
git_reference
*
ref
;
int
error
;
assert
(
db
&&
db
->
backend
&&
ref_name
);
assert
(
db
&&
db
->
backend
&&
ref_name
);
return
db
->
backend
->
lookup
(
out
,
db
->
backend
,
ref_name
);
*
out
=
NULL
;
if
((
error
=
db
->
backend
->
lookup
(
&
ref
,
db
->
backend
,
ref_name
))
==
0
)
{
ref
->
db
=
db
;
*
out
=
ref
;
}
return
error
;
}
}
int
git_refdb_foreach
(
int
git_refdb_foreach
(
...
...
src/refdb_fs.c
View file @
cf97799e
...
@@ -42,7 +42,6 @@ typedef struct refdb_fs_backend {
...
@@ -42,7 +42,6 @@ typedef struct refdb_fs_backend {
git_repository
*
repo
;
git_repository
*
repo
;
const
char
*
path
;
const
char
*
path
;
git_refdb
*
refdb
;
git_refcache
refcache
;
git_refcache
refcache
;
}
refdb_fs_backend
;
}
refdb_fs_backend
;
...
@@ -430,12 +429,12 @@ static int loose_lookup(
...
@@ -430,12 +429,12 @@ static int loose_lookup(
goto
done
;
goto
done
;
}
}
*
out
=
git_reference__alloc_symbolic
(
backend
->
refdb
,
ref_name
,
target
);
*
out
=
git_reference__alloc_symbolic
(
ref_name
,
target
);
}
else
{
}
else
{
if
((
error
=
loose_parse_oid
(
&
oid
,
&
ref_file
))
<
0
)
if
((
error
=
loose_parse_oid
(
&
oid
,
&
ref_file
))
<
0
)
goto
done
;
goto
done
;
*
out
=
git_reference__alloc
(
backend
->
refdb
,
ref_name
,
&
oid
,
NULL
);
*
out
=
git_reference__alloc
(
ref_name
,
&
oid
,
NULL
);
}
}
if
(
*
out
==
NULL
)
if
(
*
out
==
NULL
)
...
@@ -484,7 +483,7 @@ static int packed_lookup(
...
@@ -484,7 +483,7 @@ static int packed_lookup(
if
((
error
=
packed_map_entry
(
&
entry
,
&
pos
,
backend
,
ref_name
))
<
0
)
if
((
error
=
packed_map_entry
(
&
entry
,
&
pos
,
backend
,
ref_name
))
<
0
)
return
error
;
return
error
;
if
((
*
out
=
git_reference__alloc
(
backend
->
refdb
,
ref_name
,
if
((
*
out
=
git_reference__alloc
(
ref_name
,
&
entry
->
oid
,
&
entry
->
peel
))
==
NULL
)
&
entry
->
oid
,
&
entry
->
peel
))
==
NULL
)
return
-
1
;
return
-
1
;
...
@@ -999,8 +998,7 @@ static void refdb_fs_backend__free(git_refdb_backend *_backend)
...
@@ -999,8 +998,7 @@ static void refdb_fs_backend__free(git_refdb_backend *_backend)
int
git_refdb_backend_fs
(
int
git_refdb_backend_fs
(
git_refdb_backend
**
backend_out
,
git_refdb_backend
**
backend_out
,
git_repository
*
repository
,
git_repository
*
repository
)
git_refdb
*
refdb
)
{
{
refdb_fs_backend
*
backend
;
refdb_fs_backend
*
backend
;
...
@@ -1009,7 +1007,6 @@ int git_refdb_backend_fs(
...
@@ -1009,7 +1007,6 @@ int git_refdb_backend_fs(
backend
->
repo
=
repository
;
backend
->
repo
=
repository
;
backend
->
path
=
repository
->
path_repository
;
backend
->
path
=
repository
->
path_repository
;
backend
->
refdb
=
refdb
;
backend
->
parent
.
exists
=
&
refdb_fs_backend__exists
;
backend
->
parent
.
exists
=
&
refdb_fs_backend__exists
;
backend
->
parent
.
lookup
=
&
refdb_fs_backend__lookup
;
backend
->
parent
.
lookup
=
&
refdb_fs_backend__lookup
;
...
...
src/refs.c
View file @
cf97799e
...
@@ -31,7 +31,7 @@ enum {
...
@@ -31,7 +31,7 @@ enum {
GIT_PACKREF_WAS_LOOSE
=
2
GIT_PACKREF_WAS_LOOSE
=
2
};
};
static
git_reference
*
alloc_ref
(
git_refdb
*
refdb
,
const
char
*
name
)
static
git_reference
*
alloc_ref
(
const
char
*
name
)
{
{
git_reference
*
ref
;
git_reference
*
ref
;
size_t
namelen
=
strlen
(
name
);
size_t
namelen
=
strlen
(
name
);
...
@@ -39,22 +39,20 @@ static git_reference *alloc_ref(git_refdb *refdb, const char *name)
...
@@ -39,22 +39,20 @@ static git_reference *alloc_ref(git_refdb *refdb, const char *name)
if
((
ref
=
git__calloc
(
1
,
sizeof
(
git_reference
)
+
namelen
+
1
))
==
NULL
)
if
((
ref
=
git__calloc
(
1
,
sizeof
(
git_reference
)
+
namelen
+
1
))
==
NULL
)
return
NULL
;
return
NULL
;
ref
->
db
=
refdb
;
memcpy
(
ref
->
name
,
name
,
namelen
+
1
);
memcpy
(
ref
->
name
,
name
,
namelen
+
1
);
return
ref
;
return
ref
;
}
}
git_reference
*
git_reference__alloc_symbolic
(
git_reference
*
git_reference__alloc_symbolic
(
git_refdb
*
refdb
,
const
char
*
name
,
const
char
*
name
,
const
char
*
target
)
const
char
*
target
)
{
{
git_reference
*
ref
;
git_reference
*
ref
;
assert
(
refdb
&&
name
&&
target
);
assert
(
name
&&
target
);
ref
=
alloc_ref
(
refdb
,
name
);
ref
=
alloc_ref
(
name
);
if
(
!
ref
)
if
(
!
ref
)
return
NULL
;
return
NULL
;
...
@@ -69,16 +67,15 @@ git_reference *git_reference__alloc_symbolic(
...
@@ -69,16 +67,15 @@ git_reference *git_reference__alloc_symbolic(
}
}
git_reference
*
git_reference__alloc
(
git_reference
*
git_reference__alloc
(
git_refdb
*
refdb
,
const
char
*
name
,
const
char
*
name
,
const
git_oid
*
oid
,
const
git_oid
*
oid
,
const
git_oid
*
peel
)
const
git_oid
*
peel
)
{
{
git_reference
*
ref
;
git_reference
*
ref
;
assert
(
refdb
&&
name
&&
oid
);
assert
(
name
&&
oid
);
ref
=
alloc_ref
(
refdb
,
name
);
ref
=
alloc_ref
(
name
);
if
(
!
ref
)
if
(
!
ref
)
return
NULL
;
return
NULL
;
...
@@ -368,12 +365,13 @@ static int reference__create(
...
@@ -368,12 +365,13 @@ static int reference__create(
if
(
oid
!=
NULL
)
{
if
(
oid
!=
NULL
)
{
assert
(
symbolic
==
NULL
);
assert
(
symbolic
==
NULL
);
ref
=
git_reference__alloc
(
refdb
,
name
,
oid
,
NULL
);
ref
=
git_reference__alloc
(
name
,
oid
,
NULL
);
}
else
{
}
else
{
ref
=
git_reference__alloc_symbolic
(
refdb
,
name
,
symbolic
);
ref
=
git_reference__alloc_symbolic
(
name
,
symbolic
);
}
}
GITERR_CHECK_ALLOC
(
ref
);
GITERR_CHECK_ALLOC
(
ref
);
ref
->
db
=
refdb
;
if
((
error
=
git_refdb_write
(
refdb
,
ref
))
<
0
)
{
if
((
error
=
git_refdb_write
(
refdb
,
ref
))
<
0
)
{
git_reference_free
(
ref
);
git_reference_free
(
ref
);
...
@@ -490,10 +488,9 @@ int git_reference_rename(
...
@@ -490,10 +488,9 @@ int git_reference_rename(
* Create the new reference.
* Create the new reference.
*/
*/
if
(
ref
->
type
==
GIT_REF_OID
)
{
if
(
ref
->
type
==
GIT_REF_OID
)
{
result
=
git_reference__alloc
(
ref
->
db
,
new_name
,
result
=
git_reference__alloc
(
new_name
,
&
ref
->
target
.
oid
,
&
ref
->
peel
);
&
ref
->
target
.
oid
,
&
ref
->
peel
);
}
else
if
(
ref
->
type
==
GIT_REF_SYMBOLIC
)
{
}
else
if
(
ref
->
type
==
GIT_REF_SYMBOLIC
)
{
result
=
git_reference__alloc_symbolic
(
ref
->
db
,
new_name
,
ref
->
target
.
symbolic
);
result
=
git_reference__alloc_symbolic
(
new_name
,
ref
->
target
.
symbolic
);
}
else
{
}
else
{
assert
(
0
);
assert
(
0
);
}
}
...
@@ -501,6 +498,8 @@ int git_reference_rename(
...
@@ -501,6 +498,8 @@ int git_reference_rename(
if
(
result
==
NULL
)
if
(
result
==
NULL
)
return
-
1
;
return
-
1
;
result
->
db
=
ref
->
db
;
/* Check if we have to update HEAD. */
/* Check if we have to update HEAD. */
if
((
error
=
git_branch_is_head
(
ref
))
<
0
)
if
((
error
=
git_branch_is_head
(
ref
))
<
0
)
goto
on_error
;
goto
on_error
;
...
...
tests-clar/refdb/inmemory.c
View file @
cf97799e
...
@@ -6,7 +6,6 @@
...
@@ -6,7 +6,6 @@
#define TEST_REPO_PATH "testrepo"
#define TEST_REPO_PATH "testrepo"
static
git_repository
*
repo
;
static
git_repository
*
repo
;
static
git_refdb
*
refdb
;
static
git_refdb_backend
*
refdb_backend
;
static
git_refdb_backend
*
refdb_backend
;
int
unlink_ref
(
void
*
payload
,
git_buf
*
file
)
int
unlink_ref
(
void
*
payload
,
git_buf
*
file
)
...
@@ -52,6 +51,8 @@ int ref_file_foreach(git_repository *repo, int (* cb)(void *payload, git_buf *fi
...
@@ -52,6 +51,8 @@ int ref_file_foreach(git_repository *repo, int (* cb)(void *payload, git_buf *fi
void
test_refdb_inmemory__initialize
(
void
)
void
test_refdb_inmemory__initialize
(
void
)
{
{
git_refdb
*
refdb
;
git_buf
repo_refs_dir
=
GIT_BUF_INIT
;
git_buf
repo_refs_dir
=
GIT_BUF_INIT
;
repo
=
cl_git_sandbox_init
(
TEST_REPO_PATH
);
repo
=
cl_git_sandbox_init
(
TEST_REPO_PATH
);
...
@@ -60,10 +61,10 @@ void test_refdb_inmemory__initialize(void)
...
@@ -60,10 +61,10 @@ void test_refdb_inmemory__initialize(void)
cl_git_pass
(
refdb_backend_test
(
&
refdb_backend
,
repo
));
cl_git_pass
(
refdb_backend_test
(
&
refdb_backend
,
repo
));
cl_git_pass
(
git_refdb_set_backend
(
refdb
,
refdb_backend
));
cl_git_pass
(
git_refdb_set_backend
(
refdb
,
refdb_backend
));
ref_file_foreach
(
repo
,
unlink_ref
);
ref_file_foreach
(
repo
,
unlink_ref
);
git_buf_free
(
&
repo_refs_dir
);
git_buf_free
(
&
repo_refs_dir
);
git_refdb_free
(
refdb
);
}
}
void
test_refdb_inmemory__cleanup
(
void
)
void
test_refdb_inmemory__cleanup
(
void
)
...
...
tests-clar/refdb/testdb.c
View file @
cf97799e
...
@@ -10,7 +10,6 @@ typedef struct refdb_test_backend {
...
@@ -10,7 +10,6 @@ typedef struct refdb_test_backend {
git_refdb_backend
parent
;
git_refdb_backend
parent
;
git_repository
*
repo
;
git_repository
*
repo
;
git_refdb
*
refdb
;
git_vector
refs
;
git_vector
refs
;
}
refdb_test_backend
;
}
refdb_test_backend
;
...
@@ -100,10 +99,10 @@ static int refdb_test_backend__lookup(
...
@@ -100,10 +99,10 @@ static int refdb_test_backend__lookup(
if
(
strcmp
(
entry
->
name
,
ref_name
)
==
0
)
{
if
(
strcmp
(
entry
->
name
,
ref_name
)
==
0
)
{
if
(
entry
->
type
==
GIT_REF_OID
)
{
if
(
entry
->
type
==
GIT_REF_OID
)
{
*
out
=
git_reference__alloc
(
backend
->
refdb
,
ref_name
,
*
out
=
git_reference__alloc
(
ref_name
,
&
entry
->
target
.
oid
,
NULL
);
&
entry
->
target
.
oid
,
NULL
);
}
else
if
(
entry
->
type
==
GIT_REF_SYMBOLIC
)
{
}
else
if
(
entry
->
type
==
GIT_REF_SYMBOLIC
)
{
*
out
=
git_reference__alloc_symbolic
(
backend
->
refdb
,
ref_name
,
*
out
=
git_reference__alloc_symbolic
(
ref_name
,
entry
->
target
.
symbolic
);
entry
->
target
.
symbolic
);
}
}
...
@@ -195,11 +194,6 @@ int refdb_backend_test(
...
@@ -195,11 +194,6 @@ int refdb_backend_test(
git_repository
*
repo
)
git_repository
*
repo
)
{
{
refdb_test_backend
*
backend
;
refdb_test_backend
*
backend
;
git_refdb
*
refdb
;
int
error
=
0
;
if
((
error
=
git_repository_refdb
(
&
refdb
,
repo
))
<
0
)
return
error
;
backend
=
git__calloc
(
1
,
sizeof
(
refdb_test_backend
));
backend
=
git__calloc
(
1
,
sizeof
(
refdb_test_backend
));
GITERR_CHECK_ALLOC
(
backend
);
GITERR_CHECK_ALLOC
(
backend
);
...
@@ -207,7 +201,6 @@ int refdb_backend_test(
...
@@ -207,7 +201,6 @@ int refdb_backend_test(
git_vector_init
(
&
backend
->
refs
,
0
,
ref_name_cmp
);
git_vector_init
(
&
backend
->
refs
,
0
,
ref_name_cmp
);
backend
->
repo
=
repo
;
backend
->
repo
=
repo
;
backend
->
refdb
=
refdb
;
backend
->
parent
.
exists
=
&
refdb_test_backend__exists
;
backend
->
parent
.
exists
=
&
refdb_test_backend__exists
;
backend
->
parent
.
lookup
=
&
refdb_test_backend__lookup
;
backend
->
parent
.
lookup
=
&
refdb_test_backend__lookup
;
...
...
tests-clar/refs/delete.c
View file @
cf97799e
...
@@ -88,4 +88,5 @@ void test_refs_delete__packed_only(void)
...
@@ -88,4 +88,5 @@ void test_refs_delete__packed_only(void)
/* This should pass */
/* This should pass */
cl_git_pass
(
git_reference_delete
(
ref
));
cl_git_pass
(
git_reference_delete
(
ref
));
git_reference_free
(
ref
);
git_reference_free
(
ref
);
git_refdb_free
(
refdb
);
}
}
tests-clar/refs/pack.c
View file @
cf97799e
...
@@ -25,6 +25,7 @@ static void packall(void)
...
@@ -25,6 +25,7 @@ static void packall(void)
cl_git_pass
(
git_repository_refdb
(
&
refdb
,
g_repo
));
cl_git_pass
(
git_repository_refdb
(
&
refdb
,
g_repo
));
cl_git_pass
(
git_refdb_compress
(
refdb
));
cl_git_pass
(
git_refdb_compress
(
refdb
));
git_refdb_free
(
refdb
);
}
}
void
test_refs_pack__empty
(
void
)
void
test_refs_pack__empty
(
void
)
...
...
tests-clar/refs/rename.c
View file @
cf97799e
...
@@ -284,6 +284,7 @@ void test_refs_rename__overwrite(void)
...
@@ -284,6 +284,7 @@ void test_refs_rename__overwrite(void)
git_reference_free
(
ref_one
);
git_reference_free
(
ref_one
);
git_reference_free
(
ref_one_new
);
git_reference_free
(
ref_one_new
);
git_reference_free
(
ref_two
);
git_reference_free
(
ref_two
);
git_refdb_free
(
refdb
);
}
}
...
...
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