зеркало из https://github.com/microsoft/git.git
link_alt_odb_entries(): use string_list_split_in_place()
Change link_alt_odb_entry() to take a NUL-terminated string instead of (char *, len). Use string_list_split_in_place() rather than inline code in link_alt_odb_entries(). This approach saves some code and also avoids the (probably harmless) error of passing a non-NUL-terminated string to is_absolute_path(). Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Jeff King <peff@peff.net>
This commit is contained in:
Родитель
f07e5551a8
Коммит
6eac50d827
38
sha1_file.c
38
sha1_file.c
|
@ -7,6 +7,7 @@
|
|||
* creation etc.
|
||||
*/
|
||||
#include "cache.h"
|
||||
#include "string-list.h"
|
||||
#include "delta.h"
|
||||
#include "pack.h"
|
||||
#include "blob.h"
|
||||
|
@ -246,7 +247,7 @@ static int git_open_noatime(const char *name);
|
|||
* SHA1, an extra slash for the first level indirection, and the
|
||||
* terminating NUL.
|
||||
*/
|
||||
static int link_alt_odb_entry(const char * entry, int len, const char * relative_base, int depth)
|
||||
static int link_alt_odb_entry(const char *entry, const char *relative_base, int depth)
|
||||
{
|
||||
const char *objdir = get_object_directory();
|
||||
struct alternate_object_database *ent;
|
||||
|
@ -258,7 +259,7 @@ static int link_alt_odb_entry(const char * entry, int len, const char * relative
|
|||
strbuf_addstr(&pathbuf, real_path(relative_base));
|
||||
strbuf_addch(&pathbuf, '/');
|
||||
}
|
||||
strbuf_add(&pathbuf, entry, len);
|
||||
strbuf_addstr(&pathbuf, entry);
|
||||
|
||||
normalize_path_copy(pathbuf.buf, pathbuf.buf);
|
||||
|
||||
|
@ -319,7 +320,9 @@ static int link_alt_odb_entry(const char * entry, int len, const char * relative
|
|||
static void link_alt_odb_entries(const char *alt, const char *ep, int sep,
|
||||
const char *relative_base, int depth)
|
||||
{
|
||||
const char *cp, *last;
|
||||
struct string_list entries = STRING_LIST_INIT_NODUP;
|
||||
char *alt_copy;
|
||||
int i;
|
||||
|
||||
if (depth > 5) {
|
||||
error("%s: ignoring alternate object stores, nesting too deep.",
|
||||
|
@ -327,30 +330,21 @@ static void link_alt_odb_entries(const char *alt, const char *ep, int sep,
|
|||
return;
|
||||
}
|
||||
|
||||
last = alt;
|
||||
while (last < ep) {
|
||||
cp = last;
|
||||
if (cp < ep && *cp == '#') {
|
||||
while (cp < ep && *cp != sep)
|
||||
cp++;
|
||||
last = cp + 1;
|
||||
alt_copy = xmemdupz(alt, ep - alt);
|
||||
string_list_split_in_place(&entries, alt_copy, sep, -1);
|
||||
for (i = 0; i < entries.nr; i++) {
|
||||
const char *entry = entries.items[i].string;
|
||||
if (entry[0] == '\0' || entry[0] == '#')
|
||||
continue;
|
||||
}
|
||||
while (cp < ep && *cp != sep)
|
||||
cp++;
|
||||
if (last != cp) {
|
||||
if (!is_absolute_path(last) && depth) {
|
||||
if (!is_absolute_path(entry) && depth) {
|
||||
error("%s: ignoring relative alternate object store %s",
|
||||
relative_base, last);
|
||||
relative_base, entry);
|
||||
} else {
|
||||
link_alt_odb_entry(last, cp - last,
|
||||
relative_base, depth);
|
||||
link_alt_odb_entry(entry, relative_base, depth);
|
||||
}
|
||||
}
|
||||
while (cp < ep && *cp == sep)
|
||||
cp++;
|
||||
last = cp;
|
||||
}
|
||||
string_list_clear(&entries, 0);
|
||||
free(alt_copy);
|
||||
}
|
||||
|
||||
void read_info_alternates(const char * relative_base, int depth)
|
||||
|
|
Загрузка…
Ссылка в новой задаче