Skip to content

Commit 9bee7aa

Browse files
committed
Merge branch 'ei/oneline+add-empty'
* ei/oneline+add-empty: Fix ALLOC_GROW calls with obsolete semantics Fix ALLOC_GROW off-by-one builtin-add: simplify (and increase accuracy of) exclude handling dir_struct: add collect_ignored option Extend --pretty=oneline to cover the first paragraph, Lift 16kB limit of log message output
2 parents 55f22ff + 25fd2f7 commit 9bee7aa

13 files changed

+410
-239
lines changed

builtin-add.c

Lines changed: 21 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -40,42 +40,29 @@ static void prune_directory(struct dir_struct *dir, const char **pathspec, int p
4040
dir->nr = dst - dir->entries;
4141

4242
for (i = 0; i < specs; i++) {
43-
struct stat st;
44-
const char *match;
45-
if (seen[i])
46-
continue;
47-
48-
match = pathspec[i];
49-
if (!match[0])
50-
continue;
51-
52-
/* Existing file? We must have ignored it */
53-
if (!lstat(match, &st)) {
54-
struct dir_entry *ent;
55-
56-
ent = dir_add_name(dir, match, strlen(match));
57-
ent->ignored = 1;
58-
if (S_ISDIR(st.st_mode))
59-
ent->ignored_dir = 1;
60-
continue;
61-
}
62-
die("pathspec '%s' did not match any files", match);
43+
if (!seen[i] && !file_exists(pathspec[i]))
44+
die("pathspec '%s' did not match any files",
45+
pathspec[i]);
6346
}
6447
}
6548

66-
static void fill_directory(struct dir_struct *dir, const char **pathspec)
49+
static void fill_directory(struct dir_struct *dir, const char **pathspec,
50+
int ignored_too)
6751
{
6852
const char *path, *base;
6953
int baselen;
7054

7155
/* Set up the default git porcelain excludes */
7256
memset(dir, 0, sizeof(*dir));
73-
dir->exclude_per_dir = ".gitignore";
74-
path = git_path("info/exclude");
75-
if (!access(path, R_OK))
76-
add_excludes_from_file(dir, path);
77-
if (!access(excludes_file, R_OK))
78-
add_excludes_from_file(dir, excludes_file);
57+
if (!ignored_too) {
58+
dir->collect_ignored = 1;
59+
dir->exclude_per_dir = ".gitignore";
60+
path = git_path("info/exclude");
61+
if (!access(path, R_OK))
62+
add_excludes_from_file(dir, path);
63+
if (!access(excludes_file, R_OK))
64+
add_excludes_from_file(dir, excludes_file);
65+
}
7966

8067
/*
8168
* Calculate common prefix for the pathspec, and
@@ -219,13 +206,11 @@ int cmd_add(int argc, const char **argv, const char *prefix)
219206
}
220207
pathspec = get_pathspec(prefix, argv + i);
221208

222-
fill_directory(&dir, pathspec);
209+
fill_directory(&dir, pathspec, ignored_too);
223210

224211
if (show_only) {
225212
const char *sep = "", *eof = "";
226213
for (i = 0; i < dir.nr; i++) {
227-
if (!ignored_too && dir.entries[i]->ignored)
228-
continue;
229214
printf("%s%s", sep, dir.entries[i]->name);
230215
sep = " ";
231216
eof = "\n";
@@ -237,25 +222,13 @@ int cmd_add(int argc, const char **argv, const char *prefix)
237222
if (read_cache() < 0)
238223
die("index file corrupt");
239224

240-
if (!ignored_too) {
241-
int has_ignored = 0;
242-
for (i = 0; i < dir.nr; i++)
243-
if (dir.entries[i]->ignored)
244-
has_ignored = 1;
245-
if (has_ignored) {
246-
fprintf(stderr, ignore_warning);
247-
for (i = 0; i < dir.nr; i++) {
248-
if (!dir.entries[i]->ignored)
249-
continue;
250-
fprintf(stderr, "%s", dir.entries[i]->name);
251-
if (dir.entries[i]->ignored_dir)
252-
fprintf(stderr, " (directory)");
253-
fputc('\n', stderr);
254-
}
255-
fprintf(stderr,
256-
"Use -f if you really want to add them.\n");
257-
exit(1);
225+
if (dir.ignored_nr) {
226+
fprintf(stderr, ignore_warning);
227+
for (i = 0; i < dir.ignored_nr; i++) {
228+
fprintf(stderr, "%s\n", dir.ignored[i]->name);
258229
}
230+
fprintf(stderr, "Use -f if you really want to add them.\n");
231+
exit(1);
259232
}
260233

261234
for (i = 0; i < dir.nr; i++)

builtin-branch.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,6 @@ static void print_ref_item(struct ref_item *item, int maxwidth, int verbose,
247247
char c;
248248
int color;
249249
struct commit *commit;
250-
char subject[256];
251250

252251
switch (item->kind) {
253252
case REF_LOCAL_BRANCH:
@@ -268,17 +267,23 @@ static void print_ref_item(struct ref_item *item, int maxwidth, int verbose,
268267
}
269268

270269
if (verbose) {
270+
char *subject = NULL;
271+
unsigned long subject_len = 0;
272+
const char *sub = " **** invalid ref ****";
273+
271274
commit = lookup_commit(item->sha1);
272-
if (commit && !parse_commit(commit))
275+
if (commit && !parse_commit(commit)) {
273276
pretty_print_commit(CMIT_FMT_ONELINE, commit, ~0,
274-
subject, sizeof(subject), 0,
277+
&subject, &subject_len, 0,
275278
NULL, NULL, 0);
276-
else
277-
strcpy(subject, " **** invalid ref ****");
279+
sub = subject;
280+
}
278281
printf("%c %s%-*s%s %s %s\n", c, branch_get_color(color),
279282
maxwidth, item->name,
280283
branch_get_color(COLOR_BRANCH_RESET),
281-
find_unique_abbrev(item->sha1, abbrev), subject);
284+
find_unique_abbrev(item->sha1, abbrev), sub);
285+
if (subject)
286+
free(subject);
282287
} else {
283288
printf("%c %s%s%s\n", c, branch_get_color(color), item->name,
284289
branch_get_color(COLOR_BRANCH_RESET));

builtin-log.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -742,11 +742,13 @@ int cmd_cherry(int argc, const char **argv, const char *prefix)
742742
sign = '-';
743743

744744
if (verbose) {
745-
static char buf[16384];
745+
char *buf = NULL;
746+
unsigned long buflen = 0;
746747
pretty_print_commit(CMIT_FMT_ONELINE, commit, ~0,
747-
buf, sizeof(buf), 0, NULL, NULL, 0);
748+
&buf, &buflen, 0, NULL, NULL, 0);
748749
printf("%c %s %s\n", sign,
749750
sha1_to_hex(commit->object.sha1), buf);
751+
free(buf);
750752
}
751753
else {
752754
printf("%c %s\n", sign,

builtin-rev-list.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,13 @@ static void show_commit(struct commit *commit)
9292
putchar('\n');
9393

9494
if (revs.verbose_header) {
95-
static char pretty_header[16384];
95+
char *buf = NULL;
96+
unsigned long buflen = 0;
9697
pretty_print_commit(revs.commit_format, commit, ~0,
97-
pretty_header, sizeof(pretty_header),
98+
&buf, &buflen,
9899
revs.abbrev, NULL, NULL, revs.date_mode);
99-
printf("%s%c", pretty_header, hdr_termination);
100+
printf("%s%c", buf, hdr_termination);
101+
free(buf);
100102
}
101103
fflush(stdout);
102104
if (commit->parents) {

builtin-show-branch.c

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -259,17 +259,19 @@ static void join_revs(struct commit_list **list_p,
259259

260260
static void show_one_commit(struct commit *commit, int no_name)
261261
{
262-
char pretty[256], *cp;
262+
char *pretty = NULL;
263+
const char *pretty_str = "(unavailable)";
264+
unsigned long pretty_len = 0;
263265
struct commit_name *name = commit->util;
264-
if (commit->object.parsed)
266+
267+
if (commit->object.parsed) {
265268
pretty_print_commit(CMIT_FMT_ONELINE, commit, ~0,
266-
pretty, sizeof(pretty), 0, NULL, NULL, 0);
267-
else
268-
strcpy(pretty, "(unavailable)");
269-
if (!prefixcmp(pretty, "[PATCH] "))
270-
cp = pretty + 8;
271-
else
272-
cp = pretty;
269+
&pretty, &pretty_len,
270+
0, NULL, NULL, 0);
271+
pretty_str = pretty;
272+
}
273+
if (!prefixcmp(pretty_str, "[PATCH] "))
274+
pretty_str += 8;
273275

274276
if (!no_name) {
275277
if (name && name->head_name) {
@@ -286,7 +288,8 @@ static void show_one_commit(struct commit *commit, int no_name)
286288
printf("[%s] ",
287289
find_unique_abbrev(commit->object.sha1, 7));
288290
}
289-
puts(cp);
291+
puts(pretty_str);
292+
free(pretty);
290293
}
291294

292295
static char *ref_name[MAX_REVS + 1];

cache.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,11 @@ extern void verify_non_filename(const char *prefix, const char *name);
234234
*/
235235
#define ALLOC_GROW(x, nr, alloc) \
236236
do { \
237-
if ((nr) >= alloc) { \
238-
alloc = alloc_nr(alloc); \
237+
if ((nr) > alloc) { \
238+
if (alloc_nr(alloc) < (nr)) \
239+
alloc = (nr); \
240+
else \
241+
alloc = alloc_nr(alloc); \
239242
x = xrealloc((x), alloc * sizeof(*(x))); \
240243
} \
241244
} while(0)

0 commit comments

Comments
 (0)