Andrew's git
/
gitweb.git
/ diff
summary
|
log
|
commit
| diff |
tree
commit
grep
author
committer
pickaxe
?
re
builtin-branch: use strbuf in fill_tracking_info()
author
Miklos Vajna
<vmiklos@frugalware.org>
Mon, 17 Nov 2008 20:48:36 +0000
(21:48 +0100)
committer
Junio C Hamano
<gitster@pobox.com>
Tue, 18 Nov 2008 23:41:30 +0000
(15:41 -0800)
This is just about using the API, though in case of ~ 10^100 commits,
this would fix the problem of writing to unallocated memory as well. ;-)
Signed-off-by: Miklos Vajna <vmiklos@frugalware.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin-branch.c
patch
|
blob
|
history
raw
|
patch
|
inline
| side by side (parent:
3c59c50
)
diff --git
a/builtin-branch.c
b/builtin-branch.c
index b9149b78f406e950295e1df31d686e1d74bfebd6..c8a8e2a2f4696ebb1bcb28de9cd813fbee9fefd0 100644
(file)
--- a/
builtin-branch.c
+++ b/
builtin-branch.c
@@
-279,7
+279,7
@@
static int ref_cmp(const void *r1, const void *r2)
return strcmp(c1->name, c2->name);
}
return strcmp(c1->name, c2->name);
}
-static void fill_tracking_info(
char
*stat, const char *branch_name)
+static void fill_tracking_info(
struct strbuf
*stat, const char *branch_name)
{
int ours, theirs;
struct branch *branch = branch_get(branch_name);
{
int ours, theirs;
struct branch *branch = branch_get(branch_name);
@@
-287,11
+287,11
@@
static void fill_tracking_info(char *stat, const char *branch_name)
if (!stat_tracking_info(branch, &ours, &theirs) || (!ours && !theirs))
return;
if (!ours)
if (!stat_tracking_info(branch, &ours, &theirs) || (!ours && !theirs))
return;
if (!ours)
- s
print
f(stat, "[behind %d] ", theirs);
+ s
trbuf_add
f(stat, "[behind %d] ", theirs);
else if (!theirs)
else if (!theirs)
- s
print
f(stat, "[ahead %d] ", ours);
+ s
trbuf_add
f(stat, "[ahead %d] ", ours);
else
else
- s
print
f(stat, "[ahead %d, behind %d] ", ours, theirs);
+ s
trbuf_add
f(stat, "[ahead %d, behind %d] ", ours, theirs);
}
static int matches_merge_filter(struct commit *commit)
}
static int matches_merge_filter(struct commit *commit)
@@
-334,11
+334,8
@@
static void print_ref_item(struct ref_item *item, int maxwidth, int verbose,
}
if (verbose) {
}
if (verbose) {
- struct strbuf subject = STRBUF_INIT;
+ struct strbuf subject = STRBUF_INIT
, stat = STRBUF_INIT
;
const char *sub = " **** invalid ref ****";
const char *sub = " **** invalid ref ****";
- char stat[128];
-
- stat[0] = '\0';
commit = item->commit;
if (commit && !parse_commit(commit)) {
commit = item->commit;
if (commit && !parse_commit(commit)) {
@@
-348,13
+345,14
@@
static void print_ref_item(struct ref_item *item, int maxwidth, int verbose,
}
if (item->kind == REF_LOCAL_BRANCH)
}
if (item->kind == REF_LOCAL_BRANCH)
- fill_tracking_info(stat, item->name);
+ fill_tracking_info(
&
stat, item->name);
printf("%c %s%-*s%s %s %s%s\n", c, branch_get_color(color),
maxwidth, item->name,
branch_get_color(COLOR_BRANCH_RESET),
find_unique_abbrev(item->commit->object.sha1, abbrev),
printf("%c %s%-*s%s %s %s%s\n", c, branch_get_color(color),
maxwidth, item->name,
branch_get_color(COLOR_BRANCH_RESET),
find_unique_abbrev(item->commit->object.sha1, abbrev),
- stat, sub);
+ stat.buf, sub);
+ strbuf_release(&stat);
strbuf_release(&subject);
} else {
printf("%c %s%s%s\n", c, branch_get_color(color), item->name,
strbuf_release(&subject);
} else {
printf("%c %s%s%s\n", c, branch_get_color(color), item->name,