зеркало из https://github.com/microsoft/git.git
tag: fix output of "tag -n" when errors occur
When "git tag" is instructed to print lines from annotated tags via "-n", it first prints the tag name, then attempts to parse and print the lines of the tag object, and then finally adds a trailing newline. If an error occurs, we return early from the function and never print the newline, screwing up the output for the next tag. Let's factor the line-printing into its own function so we can manage the early returns better, and make sure that we always terminate the line. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Родитель
f174a2583c
Коммит
ca51699961
|
@ -84,18 +84,45 @@ static int contains(struct commit *candidate, const struct commit_list *want)
|
|||
return contains_recurse(candidate, want);
|
||||
}
|
||||
|
||||
static void show_tag_lines(const unsigned char *sha1, int lines)
|
||||
{
|
||||
int i;
|
||||
unsigned long size;
|
||||
enum object_type type;
|
||||
char *buf, *sp, *eol;
|
||||
size_t len;
|
||||
|
||||
buf = read_sha1_file(sha1, &type, &size);
|
||||
if (!buf || !size)
|
||||
return;
|
||||
|
||||
/* skip header */
|
||||
sp = strstr(buf, "\n\n");
|
||||
if (!sp) {
|
||||
free(buf);
|
||||
return;
|
||||
}
|
||||
/* only take up to "lines" lines, and strip the signature */
|
||||
size = parse_signature(buf, size);
|
||||
for (i = 0, sp += 2; i < lines && sp < buf + size; i++) {
|
||||
if (i)
|
||||
printf("\n ");
|
||||
eol = memchr(sp, '\n', size - (sp - buf));
|
||||
len = eol ? eol - sp : size - (sp - buf);
|
||||
fwrite(sp, len, 1, stdout);
|
||||
if (!eol)
|
||||
break;
|
||||
sp = eol + 1;
|
||||
}
|
||||
free(buf);
|
||||
}
|
||||
|
||||
static int show_reference(const char *refname, const unsigned char *sha1,
|
||||
int flag, void *cb_data)
|
||||
{
|
||||
struct tag_filter *filter = cb_data;
|
||||
|
||||
if (match_pattern(filter->patterns, refname)) {
|
||||
int i;
|
||||
unsigned long size;
|
||||
enum object_type type;
|
||||
char *buf, *sp, *eol;
|
||||
size_t len;
|
||||
|
||||
if (filter->with_commit) {
|
||||
struct commit *commit;
|
||||
|
||||
|
@ -111,33 +138,8 @@ static int show_reference(const char *refname, const unsigned char *sha1,
|
|||
return 0;
|
||||
}
|
||||
printf("%-15s ", refname);
|
||||
|
||||
buf = read_sha1_file(sha1, &type, &size);
|
||||
if (!buf || !size)
|
||||
return 0;
|
||||
|
||||
/* skip header */
|
||||
sp = strstr(buf, "\n\n");
|
||||
if (!sp) {
|
||||
free(buf);
|
||||
return 0;
|
||||
}
|
||||
/* only take up to "lines" lines, and strip the signature */
|
||||
size = parse_signature(buf, size);
|
||||
for (i = 0, sp += 2;
|
||||
i < filter->lines && sp < buf + size;
|
||||
i++) {
|
||||
if (i)
|
||||
printf("\n ");
|
||||
eol = memchr(sp, '\n', size - (sp - buf));
|
||||
len = eol ? eol - sp : size - (sp - buf);
|
||||
fwrite(sp, len, 1, stdout);
|
||||
if (!eol)
|
||||
break;
|
||||
sp = eol + 1;
|
||||
}
|
||||
show_tag_lines(sha1, filter->lines);
|
||||
putchar('\n');
|
||||
free(buf);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
Загрузка…
Ссылка в новой задаче