Skip to content

Commit

Permalink
Merge branch 'ei/oneline+add-empty'
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Junio C Hamano committed Jun 23, 2007
2 parents 55f22ff + 25fd2f7 commit 9bee7aa
Show file tree
Hide file tree
Showing 13 changed files with 410 additions and 239 deletions.
69 changes: 21 additions & 48 deletions builtin-add.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,42 +40,29 @@ static void prune_directory(struct dir_struct *dir, const char **pathspec, int p
dir->nr = dst - dir->entries;

for (i = 0; i < specs; i++) {
struct stat st;
const char *match;
if (seen[i])
continue;

match = pathspec[i];
if (!match[0])
continue;

/* Existing file? We must have ignored it */
if (!lstat(match, &st)) {
struct dir_entry *ent;

ent = dir_add_name(dir, match, strlen(match));
ent->ignored = 1;
if (S_ISDIR(st.st_mode))
ent->ignored_dir = 1;
continue;
}
die("pathspec '%s' did not match any files", match);
if (!seen[i] && !file_exists(pathspec[i]))
die("pathspec '%s' did not match any files",
pathspec[i]);
}
}

static void fill_directory(struct dir_struct *dir, const char **pathspec)
static void fill_directory(struct dir_struct *dir, const char **pathspec,
int ignored_too)
{
const char *path, *base;
int baselen;

/* Set up the default git porcelain excludes */
memset(dir, 0, sizeof(*dir));
dir->exclude_per_dir = ".gitignore";
path = git_path("info/exclude");
if (!access(path, R_OK))
add_excludes_from_file(dir, path);
if (!access(excludes_file, R_OK))
add_excludes_from_file(dir, excludes_file);
if (!ignored_too) {
dir->collect_ignored = 1;
dir->exclude_per_dir = ".gitignore";
path = git_path("info/exclude");
if (!access(path, R_OK))
add_excludes_from_file(dir, path);
if (!access(excludes_file, R_OK))
add_excludes_from_file(dir, excludes_file);
}

/*
* Calculate common prefix for the pathspec, and
Expand Down Expand Up @@ -219,13 +206,11 @@ int cmd_add(int argc, const char **argv, const char *prefix)
}
pathspec = get_pathspec(prefix, argv + i);

fill_directory(&dir, pathspec);
fill_directory(&dir, pathspec, ignored_too);

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

if (!ignored_too) {
int has_ignored = 0;
for (i = 0; i < dir.nr; i++)
if (dir.entries[i]->ignored)
has_ignored = 1;
if (has_ignored) {
fprintf(stderr, ignore_warning);
for (i = 0; i < dir.nr; i++) {
if (!dir.entries[i]->ignored)
continue;
fprintf(stderr, "%s", dir.entries[i]->name);
if (dir.entries[i]->ignored_dir)
fprintf(stderr, " (directory)");
fputc('\n', stderr);
}
fprintf(stderr,
"Use -f if you really want to add them.\n");
exit(1);
if (dir.ignored_nr) {
fprintf(stderr, ignore_warning);
for (i = 0; i < dir.ignored_nr; i++) {
fprintf(stderr, "%s\n", dir.ignored[i]->name);
}
fprintf(stderr, "Use -f if you really want to add them.\n");
exit(1);
}

for (i = 0; i < dir.nr; i++)
Expand Down
17 changes: 11 additions & 6 deletions builtin-branch.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,6 @@ static void print_ref_item(struct ref_item *item, int maxwidth, int verbose,
char c;
int color;
struct commit *commit;
char subject[256];

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

if (verbose) {
char *subject = NULL;
unsigned long subject_len = 0;
const char *sub = " **** invalid ref ****";

commit = lookup_commit(item->sha1);
if (commit && !parse_commit(commit))
if (commit && !parse_commit(commit)) {
pretty_print_commit(CMIT_FMT_ONELINE, commit, ~0,
subject, sizeof(subject), 0,
&subject, &subject_len, 0,
NULL, NULL, 0);
else
strcpy(subject, " **** invalid ref ****");
sub = subject;
}
printf("%c %s%-*s%s %s %s\n", c, branch_get_color(color),
maxwidth, item->name,
branch_get_color(COLOR_BRANCH_RESET),
find_unique_abbrev(item->sha1, abbrev), subject);
find_unique_abbrev(item->sha1, abbrev), sub);
if (subject)
free(subject);
} else {
printf("%c %s%s%s\n", c, branch_get_color(color), item->name,
branch_get_color(COLOR_BRANCH_RESET));
Expand Down
6 changes: 4 additions & 2 deletions builtin-log.c
Original file line number Diff line number Diff line change
Expand Up @@ -742,11 +742,13 @@ int cmd_cherry(int argc, const char **argv, const char *prefix)
sign = '-';

if (verbose) {
static char buf[16384];
char *buf = NULL;
unsigned long buflen = 0;
pretty_print_commit(CMIT_FMT_ONELINE, commit, ~0,
buf, sizeof(buf), 0, NULL, NULL, 0);
&buf, &buflen, 0, NULL, NULL, 0);
printf("%c %s %s\n", sign,
sha1_to_hex(commit->object.sha1), buf);
free(buf);
}
else {
printf("%c %s\n", sign,
Expand Down
8 changes: 5 additions & 3 deletions builtin-rev-list.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,13 @@ static void show_commit(struct commit *commit)
putchar('\n');

if (revs.verbose_header) {
static char pretty_header[16384];
char *buf = NULL;
unsigned long buflen = 0;
pretty_print_commit(revs.commit_format, commit, ~0,
pretty_header, sizeof(pretty_header),
&buf, &buflen,
revs.abbrev, NULL, NULL, revs.date_mode);
printf("%s%c", pretty_header, hdr_termination);
printf("%s%c", buf, hdr_termination);
free(buf);
}
fflush(stdout);
if (commit->parents) {
Expand Down
23 changes: 13 additions & 10 deletions builtin-show-branch.c
Original file line number Diff line number Diff line change
Expand Up @@ -259,17 +259,19 @@ static void join_revs(struct commit_list **list_p,

static void show_one_commit(struct commit *commit, int no_name)
{
char pretty[256], *cp;
char *pretty = NULL;
const char *pretty_str = "(unavailable)";
unsigned long pretty_len = 0;
struct commit_name *name = commit->util;
if (commit->object.parsed)

if (commit->object.parsed) {
pretty_print_commit(CMIT_FMT_ONELINE, commit, ~0,
pretty, sizeof(pretty), 0, NULL, NULL, 0);
else
strcpy(pretty, "(unavailable)");
if (!prefixcmp(pretty, "[PATCH] "))
cp = pretty + 8;
else
cp = pretty;
&pretty, &pretty_len,
0, NULL, NULL, 0);
pretty_str = pretty;
}
if (!prefixcmp(pretty_str, "[PATCH] "))
pretty_str += 8;

if (!no_name) {
if (name && name->head_name) {
Expand All @@ -286,7 +288,8 @@ static void show_one_commit(struct commit *commit, int no_name)
printf("[%s] ",
find_unique_abbrev(commit->object.sha1, 7));
}
puts(cp);
puts(pretty_str);
free(pretty);
}

static char *ref_name[MAX_REVS + 1];
Expand Down
7 changes: 5 additions & 2 deletions cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,11 @@ extern void verify_non_filename(const char *prefix, const char *name);
*/
#define ALLOC_GROW(x, nr, alloc) \
do { \
if ((nr) >= alloc) { \
alloc = alloc_nr(alloc); \
if ((nr) > alloc) { \
if (alloc_nr(alloc) < (nr)) \
alloc = (nr); \
else \
alloc = alloc_nr(alloc); \
x = xrealloc((x), alloc * sizeof(*(x))); \
} \
} while(0)
Expand Down
Loading

0 comments on commit 9bee7aa

Please sign in to comment.