-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Shallow support v2 #5254
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
Shallow support v2 #5254
Changes from 1 commit
0668384
919501a
3c17f22
a8b1d51
a35cc40
d54c008
22f201b
14a309a
05e286f
a11026e
70867f7
fd2398b
a4803c3
79af067
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
The refresh logic for both "normal" and shallow grafts are currently part of the repository code and implemented twice. Unify them into the grafts code by introducing two new functions to create grafts from a file and to refresh a grafts structure.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -7,12 +7,17 @@ | |||||||||
|
||||||||||
#include "grafts.h" | ||||||||||
|
||||||||||
#include "futils.h" | ||||||||||
#include "oidarray.h" | ||||||||||
#include "parse.h" | ||||||||||
|
||||||||||
struct git_grafts { | ||||||||||
/* Map of `git_commit_graft`s */ | ||||||||||
git_oidmap *commits; | ||||||||||
|
||||||||||
/* File backing the graft. NULL if it's an in-memory graft */ | ||||||||||
char *path; | ||||||||||
git_oid path_checksum; | ||||||||||
}; | ||||||||||
|
||||||||||
int git_grafts_new(git_grafts **out) | ||||||||||
|
@@ -31,10 +36,32 @@ int git_grafts_new(git_grafts **out) | |||||||||
return 0; | ||||||||||
} | ||||||||||
|
||||||||||
int git_grafts_from_file(git_grafts **out, const char *path) | ||||||||||
{ | ||||||||||
git_grafts *grafts = NULL; | ||||||||||
int error; | ||||||||||
|
||||||||||
if ((error = git_grafts_new(&grafts)) < 0) | ||||||||||
goto error; | ||||||||||
|
||||||||||
grafts->path = git__strdup(path); | ||||||||||
GIT_ERROR_CHECK_ALLOC(grafts->path); | ||||||||||
|
||||||||||
if ((error = git_grafts_refresh(grafts)) < 0) | ||||||||||
goto error; | ||||||||||
|
||||||||||
*out = grafts; | ||||||||||
error: | ||||||||||
if (error < 0) | ||||||||||
git_grafts_free(grafts); | ||||||||||
return error; | ||||||||||
} | ||||||||||
|
||||||||||
void git_grafts_free(git_grafts *grafts) | ||||||||||
{ | ||||||||||
if (!grafts) | ||||||||||
return; | ||||||||||
git__free(grafts->path); | ||||||||||
git_grafts_clear(grafts); | ||||||||||
git_oidmap_free(grafts->commits); | ||||||||||
git__free(grafts); | ||||||||||
|
@@ -54,6 +81,34 @@ void git_grafts_clear(git_grafts *grafts) | |||||||||
git_oidmap_clear(grafts->commits); | ||||||||||
} | ||||||||||
|
||||||||||
int git_grafts_refresh(git_grafts *grafts) | ||||||||||
{ | ||||||||||
git_buf contents = GIT_BUF_INIT; | ||||||||||
int error, updated = 0; | ||||||||||
|
||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
assert(grafts); | ||||||||||
|
||||||||||
if (!grafts->path) | ||||||||||
return 0; | ||||||||||
|
||||||||||
error = git_futils_readbuffer_updated(&contents, grafts->path, | ||||||||||
&grafts->path_checksum, &updated); | ||||||||||
if (error < 0 || error == GIT_ENOTFOUND || !updated) { | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the kind of thing where I'm wondering "how would it work after I add the write-side of it" (ie. the actual part where the grafts are updated from the server's view). Swallowing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If it's removed then it would return |
||||||||||
if (error == GIT_ENOTFOUND) { | ||||||||||
git_grafts_clear(grafts); | ||||||||||
error = 0; | ||||||||||
} | ||||||||||
goto cleanup; | ||||||||||
} | ||||||||||
|
||||||||||
if ((error = git_grafts_parse(grafts, contents.ptr, contents.size)) < 0) | ||||||||||
goto cleanup; | ||||||||||
|
||||||||||
cleanup: | ||||||||||
git_buf_dispose(&contents); | ||||||||||
return error; | ||||||||||
} | ||||||||||
|
||||||||||
int git_grafts_parse(git_grafts *grafts, const char *content, size_t contentlen) | ||||||||||
{ | ||||||||||
git_array_oid_t parents = GIT_ARRAY_INIT; | ||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.