8000 Shallow Clone Support by lya001 · Pull Request #6396 · libgit2/libgit2 · GitHub
[go: up one dir, main page]

Skip to content

Shallow Clone Support #6396

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 81 commits into from
May 9, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
0668384
repo: basic graft API
tiennou Aug 2, 2018
919501a
repo: load grafts on open
tiennou Aug 2, 2018
3c17f22
repo: load shallow roots
tiennou Oct 10, 2019
a8b1d51
repo: graft shallow roots on open
tiennou Aug 2, 2018
a35cc40
commit: apply grafts when parsing
tiennou Aug 2, 2018
d54c008
tests: graft commits
tiennou Aug 2, 2018
22f201b
grafts: make the structure self-contained and opaque
pks-t Oct 3, 2019
14a309a
repository: convert grafts parsing to use parse context
pks-t Oct 3, 2019
05e286f
grafts: move parsing into grafts module
pks-t May 12, 2020
a11026e
repository: reuse grafts for shallow roots
pks-t Oct 24, 2019
70867f7
repository: disentangle shallow and normal grafts
pks-t Oct 3, 2019
fd2398b
grafts: move refresh logic into grafts code
pks-t Oct 3, 2019
a4803c3
grafts: fix memory leak if replacing pre-existing graft
pks-t Oct 10, 2019
79af067
repository: do not expose grafting mechanism
pks-t Oct 24, 2019
e07aa9c
Merge branch 'main' into pr/pks-t/5254
lya001 Jun 24, 2022
13bd14d
add feature flag for shallow clone support
Jun 27, 2022
7a93625
add test for shallow feature flag
Jun 27, 2022
89494f6
add shallow.h
Jun 27, 2022
562246b
move declaration of feature flag to graft.h/graft.c
Jun 27, 2022
6bab22f
move feature flag tests to tests/grafts/shallow.c
Jun 27, 2022
ad56355
use shallow feature flag in shallow clone support source code
Jun 27, 2022
c4cd9a5
correct naming of feature flag
Jun 27, 2022
5918975
disable shallow clone support by default
Jun 28, 2022
397753f
enable shallow clone support in tests when necessary
Jun 28, 2022
9d1507d
correct use of feature flag
Jun 28, 2022
06eacb9
fix graft assertion
Jun 28, 2022
70a332a
disable shallow clone feature flag in test cleanup
Jun 28, 2022
afa79ca
Merge branch 'pr/tiennou/4747' into transportPR
Jul 4, 2022
10e2573
attempt to build
Jul 5, 2022
3e64f15
rewrite shallow_root
Jul 7, 2022
c652f3d
enable cloning of shallow repo
Jul 19, 2022
f19ffc8
add test for shallow repo depth 1
Jul 19, 2022
7f46bfa
unset GIT_RAND_GETENTROPY to avoid linux GLIBC issues (#3)
lya001 Jul 26, 2022
52ba17f
Merge branch 'pr/pks-t/5254' into shallow-clone-local
Jul 26, 2022
83f71b1
fix build errors
Jul 26, 2022
cfc2ae6
eliminate build warnings
Jul 27, 2022
c01b784
improve error handling
Jul 28, 2022
14d2a60
fix load_grafts
Jul 28, 2022
62cc77a
refactor commit parent assignment with graft
Jul 28, 2022
a544a91
rename function assign_parents_from_graft
Jul 28, 2022
3d7a609
Merge pull request #4 from lya001/shallow-clone-local
lya001 Jul 29, 2022
09acf69
Merge branch 'mw_dev' into shallow-clone-local
lya001 Jul 29, 2022
a491917
Merge pull request #5 from mathworks/shallow-clone-local
lya001 Jul 29, 2022
68bbcef
Merge branch 'transportPR' into shallow-clone-network
Jul 29, 2022
73d25f0
remove build errors
Jul 29, 2022
598ec30
eliminate build warnings
Jul 29, 2022
179aac7
fix clone::shallow test behaviour
Jul 29, 2022
e7294e8
fix memory leaks about packets
Aug 1, 2022
2d33fe7
refactor git_fetch_option.depth and usage
Aug 2, 2022
4536477
fix memory leak
Aug 2, 2022
e93d081
attempt to fix nego.shallowarray memory leak
Aug 2, 2022
da04d3f
fix grafts and shallowarray memory leaks
Aug 2, 2022
8ef492f
fix build warning
Aug 2, 2022
829555a
edit tests for shallow clones
Aug 2, 2022
09b3d33
fix memory leak
Aug 9, 2022
df5eb32
support fetch unshallow option on shallow repos
Aug 9, 2022
49e641b
remove unused api
Aug 11, 2022
8b521f0
document unshallow behaviour in fetch.c
Aug 11, 2022
7c2b1f4
Merge pull request #6 from lya001/shallow-clone-network
lya001 Aug 11, 2022
a3bfd28
Use GIT_OID_SHA1_HEXSIZE
lya001 Aug 31, 2022
01cb90b
restore GIT_RAND_GETENTROPY
lya001 Aug 31, 2022
b20f013
restore getentropy
lya001 Aug 31, 2022
f1f9b45
fix test failures
lya001 Aug 31, 2022
6c46b58
include oid.h in grafts.c
lya001 Aug 31, 2022
4cf19ad
refactor smart_pkt
lya001 Aug 31, 2022
d0eba8a
fix shallowarray test
lya001 Aug 31, 2022
89c1b01
fix free error
lya001 Aug 31, 2022
34de5c8
fix seg faults
lya001 Sep 5, 2022
7122fcd
fix depth initialisation
lya001 Sep 5, 2022
47f36a9
fix error handling
lya001 Sep 5, 2022
d23a790
remove unused statements
lya001 Sep 5, 2022
4f2f91a
fix shallow array search
lya001 Sep 6, 2022
a9793ac
refactor grafts tests
lya001 Sep 6, 2022
570ef74
Merge commit 'd066d0d95c43e97df6624292f3f527f9372ca8fe'
lrm29 Mar 10, 2023
1cc2979
Fix merge error
lrm29 Mar 10, 2023
2da3e8c
Remove stray comma
lrm29 Mar 10, 2023
d935773
Remove unused git_transport_flags_t
lrm29 Mar 10, 2023
79ed94e
Apply suggestions from code review
lrm29 Mar 10, 2023
e3bf6db
Merge branch 'shallow-clone-network' of https://github.com/mathworks/…
lrm29 Mar 10, 2023
5b71133
Update src/libgit2/fetch.c
lrm29 Mar 10, 2023
e288f87
Remove unnecessary include.
lrm29 Mar 13, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
repository: convert grafts parsing to use parse context
Instead of using the newly introduced `git_buf_foreach_line`, which
modifies the buffer itself, we should try to use our existing parsing
infrastructure in "parse.h".

Convert the grafts parsing code to make use of `git_parse_ctx`. Remove
the `git_buf_foreach_line` macro, as grafts have been its sole user.
  • Loading branch information
pks-t committed Jun 27, 2020
commit 14a309ab384a8732f692e468ac56c0d1831fce2f
5 changes: 0 additions & 5 deletions src/buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,4 @@ int git_buf_splice(
const char *data,
size_t nb_to_insert);

/* warning: this will wreck your buf contents */
#define git_buf_foreach_line(line_start, line_end, line_num, buf) \
while (((line_start) = git__strsep(&(buf)->ptr, "\n")) != NULL && \
((line_end) = (line_start) + strlen((line_start))) != NULL && ++(line_num))

#endif
68 changes: 32 additions & 36 deletions src/repository.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "annotated_commit.h"
#include "submodule.h"
#include "worktree.h"
#include "parse.h"

#include "strmap.h"

Expand Down Expand Up @@ -581,14 +582,11 @@ static int find_repo(

static int load_grafts(git_repository *repo)
{
git_array_oid_t parents = GIT_ARRAY_INIT;
git_buf graft_path = GIT_BUF_INIT;
git_buf contents = GIT_BUF_INIT;
git_buf dup_contents;
const char *line_start;
const char *line_end;
int line_num = 0;
git_parse_ctx parser;
int error, updated;
git_array_oid_t parents = GIT_ARRAY_INIT;

if ((error = git_repository_item_path(&graft_path, repo, GIT_REPOSITORY_ITEM_INFO)) < 0)
return error;
Expand All @@ -598,54 +596,52 @@ static int load_grafts(git_repository *repo)
return error;
}

error = git_futils_readbuffer_updated(&contents, git_buf_cstr(&graft_path), &repo->graft_checksum, &updated);
git_buf_dispose(&graft_path);
error = git_futils_readbuffer_updated(&contents, git_buf_cstr(&graft_path),
&repo->graft_checksum, &updated);
if (error < 0 || error == GIT_ENOTFOUND || !updated) {
if (error == GIT_ENOTFOUND)
error = 0;
goto cleanup;
}

if (error == GIT_ENOTFOUND || !updated)
return 0;
git_grafts_clear(repo->grafts);

if (error < 0)
if ((error = git_parse_ctx_init(&parser, contents.ptr, contents.size)) < 0)
goto cleanup;

if (updated)
git_grafts_clear(repo->grafts);

dup_contents.ptr = contents.ptr;
git_buf_foreach_line(line_start, line_end, line_num, &dup_contents) {
git_oid graft_oid, parent_oid;
for (; parser.remain_len; git_parse_advance_line(&parser)) {
const char *line_start = parser.line, *line_end = parser.line + parser.line_len;
git_oid graft_oid;

error = git_oid_fromstrn(&graft_oid, line_start, GIT_OID_HEXSZ);
if (error < 0) {
git_error_set(GIT_ERROR_REPOSITORY, "Invalid OID at line %d", line_num);
error = -1;
}
if (git_oid_fromstrn(&graft_oid, line_start, GIT_OID_HEXSZ) < 0)
goto invalid_oid;
line_start += GIT_OID_HEXSZ;

if (*(line_start++) == ' ') {
while (git_oid_fromstrn(&parent_oid, line_start, GIT_OID_HEXSZ) == 0) {
git_oid *id = git_array_alloc(parents);
while (line_start < line_end && *line_start == ' ') {
git_oid *id = git_array_alloc(parents);
GIT_ERROR_CHECK_ALLOC(id);

git_oid_cpy(id, &parent_oid);
line_start += GIT_OID_HEXSZ;
if (line_start >= line_end) {
break;
}
line_start += 1;
}
if (git_oid_fromstrn(id, ++line_start, GIT_OID_HEXSZ) < 0)
goto invalid_oid;
line_start += GIT_OID_HEXSZ;
}

if (git_grafts_add(repo->grafts, &graft_oid, parents) < 0) {
git_error_set(GIT_ERROR_REPOSITORY, "Invalid graft at line %d", line_num);
error = -1;
if ((error = git_grafts_add(repo->grafts, &graft_oid, parents)) < 0)
goto cleanup;
}

git_array_clear(parents);
line_num++;
continue;

invalid_oid:
git_error_set(GIT_ERROR_REPOSITORY, "invalid OID at line %" PRIuZ, parser.line_num);
error = -1;
goto cleanup;
}

cleanup:
git_array_clear(parents);
git_buf_dispose(&contents);
git_buf_dispose(&graft_path);

return error;
}
Expand Down
0