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
3c17f229
Commit
3c17f229
authored
Oct 10, 2019
by
Etienne Samson
Committed by
Patrick Steinhardt
Jun 27, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
repo: load shallow roots
parent
919501a9
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
93 additions
and
0 deletions
+93
-0
include/git2/repository.h
+12
-0
src/repository.c
+75
-0
src/repository.h
+6
-0
No files found.
include/git2/repository.h
View file @
3c17f229
...
...
@@ -11,6 +11,7 @@
#include "types.h"
#include "oid.h"
#include "buffer.h"
#include "oidarray.h"
/**
* @file git2/repository.h
...
...
@@ -875,6 +876,17 @@ GIT_EXTERN(const char *) git_repository_get_namespace(git_repository *repo);
GIT_EXTERN
(
int
)
git_repository_is_shallow
(
git_repository
*
repo
);
/**
* Determine the shallow roots of the repository
*
* This oidarray is owned by the library. Do not free it.
*
* @param out An array of shallow oids.
* @param repo The repository
* @return 0 on success, an error otherwise.
*/
GIT_EXTERN
(
int
)
git_repository_shallow_roots
(
git_oidarray
*
out
,
git_repository
*
repo
);
/**
* Retrieve the configured identity to use for reflogs
*
* The memory is owned by the repository and must not be freed by the
...
...
src/repository.c
View file @
3c17f229
...
...
@@ -151,6 +151,8 @@ int git_repository__cleanup(git_repository *repo)
git__graft_clear
(
repo
->
grafts
);
git_oidmap_free
(
repo
->
grafts
);
git_array_clear
(
repo
->
shallow_oids
);
set_config
(
repo
,
NULL
);
set_index
(
repo
,
NULL
);
set_odb
(
repo
,
NULL
);
...
...
@@ -2978,6 +2980,79 @@ int git_repository_state_cleanup(git_repository *repo)
return
git_repository__cleanup_files
(
repo
,
state_files
,
ARRAY_SIZE
(
state_files
));
}
int
git_repository__shallow_roots
(
git_array_oid_t
*
out
,
git_repository
*
repo
)
{
git_buf
path
=
GIT_BUF_INIT
;
git_buf
contents
=
GIT_BUF_INIT
;
int
error
,
updated
,
line_num
=
1
;
char
*
line
;
char
*
buffer
;
assert
(
out
&&
repo
);
if
((
error
=
git_buf_joinpath
(
&
path
,
repo
->
gitdir
,
"shallow"
))
<
0
)
return
error
;
error
=
git_futils_readbuffer_updated
(
&
contents
,
git_buf_cstr
(
&
path
),
&
repo
->
shallow_checksum
,
&
updated
);
git_buf_dispose
(
&
path
);
if
(
error
<
0
&&
error
!=
GIT_ENOTFOUND
)
return
error
;
/* cancel out GIT_ENOTFOUND */
git_error_clear
();
error
=
0
;
if
(
!
updated
)
{
*
out
=
repo
->
shallow_oids
;
goto
cleanup
;
}
git_array_clear
(
repo
->
shallow_oids
);
buffer
=
contents
.
ptr
;
while
((
line
=
git__strsep
(
&
buffer
,
"
\n
"
))
!=
NULL
)
{
git_oid
*
oid
=
git_array_alloc
(
repo
->
shallow_oids
);
error
=
git_oid_fromstr
(
oid
,
line
);
if
(
error
<
0
)
{
git_error_set
(
GIT_ERROR_REPOSITORY
,
"Invalid OID at line %d"
,
line_num
);
git_array_clear
(
repo
->
shallow_oids
);
error
=
-
1
;
goto
cleanup
;
}
++
line_num
;
}
if
(
*
buffer
)
{
git_error_set
(
GIT_ERROR_REPOSITORY
,
"No EOL at line %d"
,
line_num
);
git_array_clear
(
repo
->
shallow_oids
);
error
=
-
1
;
goto
cleanup
;
}
*
out
=
repo
->
shallow_oids
;
cleanup:
git_buf_dispose
(
&
contents
);
return
error
;
}
int
git_repository_shallow_roots
(
git_oidarray
*
out
,
git_repository
*
repo
)
{
int
ret
;
git_array_oid_t
array
=
GIT_ARRAY_INIT
;
assert
(
out
);
ret
=
git_repository__shallow_roots
(
&
array
,
repo
);
git_oidarray__from_array
(
out
,
&
array
);
return
ret
;
}
int
git_repository_is_shallow
(
git_repository
*
repo
)
{
git_buf
path
=
GIT_BUF_INIT
;
...
...
src/repository.h
View file @
3c17f229
...
...
@@ -25,6 +25,7 @@
#include "submodule.h"
#include "diff_driver.h"
#include "graft.h"
#include "oidarray.h"
#define DOT_GIT ".git"
#define GIT_DIR DOT_GIT "/"
...
...
@@ -156,6 +157,9 @@ struct git_repository {
git_graftmap
*
grafts
;
git_oid
graft_checksum
;
git_oid
shallow_checksum
;
git_array_oid_t
shallow_oids
;
git_atomic
attr_session_key
;
git_configmap_value
configmap_cache
[
GIT_CONFIGMAP_CACHE_MAX
];
...
...
@@ -259,4 +263,6 @@ extern size_t git_repository__reserved_names_posix_len;
bool
git_repository__reserved_names
(
git_buf
**
out
,
size_t
*
outlen
,
git_repository
*
repo
,
bool
include_ntfs
);
int
git_repository__shallow_roots
(
git_array_oid_t
*
out
,
git_repository
*
repo
);
#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