Skip to content

Commit f54cb05

Browse files
committed
Merge branch 'jk/long-paths' into maint-2.2
2 parents fdf96a2 + 78f23bd commit f54cb05

File tree

4 files changed

+27
-24
lines changed

4 files changed

+27
-24
lines changed

builtin/show-branch.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,6 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
720720

721721
if (reflog) {
722722
unsigned char sha1[20];
723-
char nth_desc[256];
724723
char *ref;
725724
int base = 0;
726725
unsigned int flags = 0;
@@ -759,6 +758,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
759758

760759
for (i = 0; i < reflog; i++) {
761760
char *logmsg;
761+
char *nth_desc;
762762
const char *msg;
763763
unsigned long timestamp;
764764
int tz;
@@ -777,8 +777,10 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
777777
show_date(timestamp, tz, 1),
778778
msg);
779779
free(logmsg);
780-
sprintf(nth_desc, "%s@{%d}", *av, base+i);
780+
781+
nth_desc = xstrfmt("%s@{%d}", *av, base+i);
781782
append_ref(nth_desc, sha1, 1);
783+
free(nth_desc);
782784
}
783785
free(ref);
784786
}

notes.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -362,13 +362,14 @@ static int non_note_cmp(const struct non_note *a, const struct non_note *b)
362362
return strcmp(a->path, b->path);
363363
}
364364

365-
static void add_non_note(struct notes_tree *t, const char *path,
365+
/* note: takes ownership of path string */
366+
static void add_non_note(struct notes_tree *t, char *path,
366367
unsigned int mode, const unsigned char *sha1)
367368
{
368369
struct non_note *p = t->prev_non_note, *n;
369370
n = (struct non_note *) xmalloc(sizeof(struct non_note));
370371
n->next = NULL;
371-
n->path = xstrdup(path);
372+
n->path = path;
372373
n->mode = mode;
373374
hashcpy(n->sha1, sha1);
374375
t->prev_non_note = n;
@@ -482,17 +483,17 @@ static void load_subtree(struct notes_tree *t, struct leaf_node *subtree,
482483
* component.
483484
*/
484485
{
485-
char non_note_path[PATH_MAX];
486-
char *p = non_note_path;
486+
struct strbuf non_note_path = STRBUF_INIT;
487487
const char *q = sha1_to_hex(subtree->key_sha1);
488488
int i;
489489
for (i = 0; i < prefix_len; i++) {
490-
*p++ = *q++;
491-
*p++ = *q++;
492-
*p++ = '/';
490+
strbuf_addch(&non_note_path, *q++);
491+
strbuf_addch(&non_note_path, *q++);
492+
strbuf_addch(&non_note_path, '/');
493493
}
494-
strcpy(p, entry.path);
495-
add_non_note(t, non_note_path, entry.mode, entry.sha1);
494+
strbuf_addstr(&non_note_path, entry.path);
495+
add_non_note(t, strbuf_detach(&non_note_path, NULL),
496+
entry.mode, entry.sha1);
496497
}
497498
}
498499
free(buf);

sha1_file.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -377,15 +377,12 @@ void read_info_alternates(const char * relative_base, int depth)
377377
char *map;
378378
size_t mapsz;
379379
struct stat st;
380-
const char alt_file_name[] = "info/alternates";
381-
/* Given that relative_base is no longer than PATH_MAX,
382-
ensure that "path" has enough space to append "/", the
383-
file name, "info/alternates", and a trailing NUL. */
384-
char path[PATH_MAX + 1 + sizeof alt_file_name];
380+
char *path;
385381
int fd;
386382

387-
sprintf(path, "%s/%s", relative_base, alt_file_name);
383+
path = xstrfmt("%s/info/alternates", relative_base);
388384
fd = git_open_noatime(path);
385+
free(path);
389386
if (fd < 0)
390387
return;
391388
if (fstat(fd, &st) || (st.st_size == 0)) {

unpack-trees.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1432,15 +1432,18 @@ static int verify_absent_1(const struct cache_entry *ce,
14321432
if (!len)
14331433
return 0;
14341434
else if (len > 0) {
1435-
char path[PATH_MAX + 1];
1436-
memcpy(path, ce->name, len);
1437-
path[len] = 0;
1435+
char *path;
1436+
int ret;
1437+
1438+
path = xmemdupz(ce->name, len);
14381439
if (lstat(path, &st))
1439-
return error("cannot stat '%s': %s", path,
1440+
ret = error("cannot stat '%s': %s", path,
14401441
strerror(errno));
1441-
1442-
return check_ok_to_remove(path, len, DT_UNKNOWN, NULL, &st,
1443-
error_type, o);
1442+
else
1443+
ret = check_ok_to_remove(path, len, DT_UNKNOWN, NULL,
1444+
&st, error_type, o);
1445+
free(path);
1446+
return ret;
14441447
} else if (lstat(ce->name, &st)) {
14451448
if (errno != ENOENT)
14461449
return error("cannot stat '%s': %s", ce->name,

0 commit comments

Comments
 (0)