mirror of
https://git.proxmox.com/git/libgit2
synced 2025-06-23 12:05:21 +00:00
odb: Fix loading ODB alternates
Fixed an issue with the `strtokz implementation and added support for comments and relative paths in the alternates file.
This commit is contained in:
parent
1e9b7a09ff
commit
0291b5b76b
20
src/odb.c
20
src/odb.c
@ -321,8 +321,7 @@ static int add_default_backends(git_odb *db, const char *objects_dir, int as_alt
|
|||||||
static int load_alternates(git_odb *odb, const char *objects_dir)
|
static int load_alternates(git_odb *odb, const char *objects_dir)
|
||||||
{
|
{
|
||||||
char alternates_path[GIT_PATH_MAX];
|
char alternates_path[GIT_PATH_MAX];
|
||||||
char alternate[GIT_PATH_MAX];
|
char *buffer, *alternate;
|
||||||
char *buffer;
|
|
||||||
|
|
||||||
gitfo_buf alternates_buf = GITFO_BUF_INIT;
|
gitfo_buf alternates_buf = GITFO_BUF_INIT;
|
||||||
int error;
|
int error;
|
||||||
@ -339,8 +338,21 @@ static int load_alternates(git_odb *odb, const char *objects_dir)
|
|||||||
error = GIT_SUCCESS;
|
error = GIT_SUCCESS;
|
||||||
|
|
||||||
/* add each alternate as a new backend; one alternate per line */
|
/* add each alternate as a new backend; one alternate per line */
|
||||||
while ((error == GIT_SUCCESS) && (buffer = git__strtok(alternate, buffer, "\r\n")) != NULL)
|
while ((alternate = git__strtok(&buffer, "\r\n")) != NULL) {
|
||||||
error = add_default_backends(odb, alternate, 1);
|
char full_path[GIT_PATH_MAX];
|
||||||
|
|
||||||
|
if (*alternate == '\0' || *alternate == '#')
|
||||||
|
continue;
|
||||||
|
|
||||||
|
/* relative path: build based on the current `objects` folder */
|
||||||
|
if (*alternate == '.') {
|
||||||
|
git__joinpath(full_path, objects_dir, alternate);
|
||||||
|
alternate = full_path;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((error = add_default_backends(odb, alternate, 1)) < GIT_SUCCESS)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
gitfo_free_buf(&alternates_buf);
|
gitfo_free_buf(&alternates_buf);
|
||||||
if (error < GIT_SUCCESS)
|
if (error < GIT_SUCCESS)
|
||||||
|
34
src/util.c
34
src/util.c
@ -337,27 +337,29 @@ void git__joinpath_n(char *buffer_out, int count, ...)
|
|||||||
*buffer_out = '\0';
|
*buffer_out = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *strtok_raw(char *output, char *src, char *delimit, int keep)
|
char *git__strtok(char **end, const char *sep)
|
||||||
{
|
{
|
||||||
while (*src && strchr(delimit, *src) == NULL)
|
char *ptr = *end;
|
||||||
*output++ = *src++;
|
|
||||||
|
|
||||||
*output = 0;
|
while (*ptr && strchr(sep, *ptr))
|
||||||
|
++ptr;
|
||||||
|
|
||||||
if (keep)
|
if (*ptr) {
|
||||||
return src;
|
char *start = ptr;
|
||||||
else
|
*end = start + 1;
|
||||||
return *src ? src+1 : src;
|
|
||||||
}
|
|
||||||
|
|
||||||
char *git__strtok(char *output, char *src, char *delimit)
|
while (**end && !strchr(sep, **end))
|
||||||
{
|
++*end;
|
||||||
return strtok_raw(output, src, delimit, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
char *git__strtok_keep(char *output, char *src, char *delimit)
|
if (**end) {
|
||||||
{
|
**end = '\0';
|
||||||
return strtok_raw(output, src, delimit, 1);
|
++*end;
|
||||||
|
}
|
||||||
|
|
||||||
|
return start;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void git__hexdump(const char *buffer, size_t len)
|
void git__hexdump(const char *buffer, size_t len)
|
||||||
|
@ -139,8 +139,7 @@ GIT_INLINE(int) git__is_sizet(git_off_t p)
|
|||||||
# define git__rotl(v, s) (uint32_t)(((uint32_t)(v) << (s)) | ((uint32_t)(v) >> (32 - (s))))
|
# define git__rotl(v, s) (uint32_t)(((uint32_t)(v) << (s)) | ((uint32_t)(v) >> (32 - (s))))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern char *git__strtok(char *output, char *src, char *delimit);
|
extern char *git__strtok(char **end, const char *sep);
|
||||||
extern char *git__strtok_keep(char *output, char *src, char *delimit);
|
|
||||||
|
|
||||||
extern void git__strntolower(char *str, int len);
|
extern void git__strntolower(char *str, int len);
|
||||||
extern void git__strtolower(char *str);
|
extern void git__strtolower(char *str);
|
||||||
|
Loading…
Reference in New Issue
Block a user