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>
Michael Haggerty committed
Nov 5, 2012 at 09:41 UTC
6eac50d8274ef0acbbaec4f79e2876405ba8dcee
1 file changed
+18
-24
sha1_file.c
+18
-24
@@ -7,6 +7,7 @@
7
* creation etc.
8
*/
9
#include "cache.h"
10
+#include "string-list.h"
11
#include "delta.h"
12
#include "pack.h"
13
#include "blob.h"
@@ -246,7 +247,7 @@ static int git_open_noatime(const char *name);
247
* SHA1, an extra slash for the first level indirection, and the
248
* terminating NUL.
249
*/
249
-static int link_alt_odb_entry(const char * entry, int len, const char * relative_base, int depth)
250
+static int link_alt_odb_entry(const char *entry, const char *relative_base, int depth)
251
{
252
const char *objdir = get_object_directory();
253
struct alternate_object_database *ent;
@@ -258,7 +259,7 @@ static int link_alt_odb_entry(const char * entry, int len, const char * relative
259
strbuf_addstr(&pathbuf, real_path(relative_base));
260
strbuf_addch(&pathbuf, '/');
261
}
261
- strbuf_add(&pathbuf, entry, len);
262
+ strbuf_addstr(&pathbuf, entry);
263
264
normalize_path_copy(pathbuf.buf, pathbuf.buf);
265
@@ -319,7 +320,9 @@ static int link_alt_odb_entry(const char * entry, int len, const char * relative
320
static void link_alt_odb_entries(const char *alt, const char *ep, int sep,
321
const char *relative_base, int depth)
322
{
322
- const char *cp, *last;
323
+ struct string_list entries = STRING_LIST_INIT_NODUP;
324
+ char *alt_copy;
325
+ int i;
326
327
if (depth > 5) {
328
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,
330
return;
331
}
332
330
- last = alt;
331
- while (last < ep) {
332
- cp = last;
333
- if (cp < ep && *cp == '#') {
334
- while (cp < ep && *cp != sep)
335
- cp++;
336
- last = cp + 1;
333
+ alt_copy = xmemdupz(alt, ep - alt);
334
+ string_list_split_in_place(&entries, alt_copy, sep, -1);
335
+ for (i = 0; i < entries.nr; i++) {
336
+ const char *entry = entries.items[i].string;
337
+ if (entry[0] == '\0' || entry[0] == '#')
338
continue;
339
+ if (!is_absolute_path(entry) && depth) {
340
+ error("%s: ignoring relative alternate object store %s",
341
+ relative_base, entry);
342
+ } else {
343
+ link_alt_odb_entry(entry, relative_base, depth);
344
}
339
- while (cp < ep && *cp != sep)
340
- cp++;
341
- if (last != cp) {
342
- if (!is_absolute_path(last) && depth) {
343
- error("%s: ignoring relative alternate object store %s",
344
- relative_base, last);
345
- } else {
346
- link_alt_odb_entry(last, cp - last,
347
- relative_base, depth);
348
- }
349
- }
350
- while (cp < ep && *cp == sep)
351
- cp++;
352
- last = cp;
345
}
346
+ string_list_clear(&entries, 0);
347
+ free(alt_copy);
348
}
349
350
void read_info_alternates(const char * relative_base, int depth)