From 00fb3d214cbb867f45de0084e6b844445e076dce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Scharfe?= Date: Sat, 13 Mar 2010 11:25:12 +0100 Subject: [PATCH 1/4] blame: fix indent of line numbers Correct the calculation of the number of digits for line counts of the form 10^n-1 (9, 99, ...) in lineno_width(). This makes blame stop printing an extra space before the line numbers of files with that many total lines. Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- builtin-blame.c | 2 +- t/t8003-blame.sh | 20 +++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/builtin-blame.c b/builtin-blame.c index 10f7eacf6e..fc1586350f 100644 --- a/builtin-blame.c +++ b/builtin-blame.c @@ -1772,7 +1772,7 @@ static int lineno_width(int lines) { int i, width; - for (width = 1, i = 10; i <= lines + 1; width++) + for (width = 1, i = 10; i <= lines; width++) i *= 10; return width; } diff --git a/t/t8003-blame.sh b/t/t8003-blame.sh index 3bbddd03cb..230143cf31 100755 --- a/t/t8003-blame.sh +++ b/t/t8003-blame.sh @@ -11,7 +11,15 @@ test_expect_success setup ' echo B B B B B >two && echo C C C C C >tres && echo ABC >mouse && - git add one two tres mouse && + for i in 1 2 3 4 5 6 7 8 9 + do + echo $i + done >nine_lines && + for i in 1 2 3 4 5 6 7 8 9 a + do + echo $i + done >ten_lines && + git add one two tres mouse nine_lines ten_lines && test_tick && GIT_AUTHOR_NAME=Initial git commit -m Initial && @@ -167,4 +175,14 @@ test_expect_success 'blame -L with invalid end' ' grep "has only 2 lines" errors ' +test_expect_success 'indent of line numbers, nine lines' ' + git blame nine_lines >actual && + test $(grep -c " " actual) = 0 +' + +test_expect_success 'indent of line numbers, ten lines' ' + git blame ten_lines >actual && + test $(grep -c " " actual) = 9 +' + test_done From 34b383e7cd57692fd3996c1e8c9e738dab53ac48 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sat, 13 Mar 2010 12:41:20 -0800 Subject: [PATCH 2/4] t/Makefile: remove test artifacts upon "make clean" Signed-off-by: Junio C Hamano --- t/Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/t/Makefile b/t/Makefile index bd09390d32..25c559bb49 100644 --- a/t/Makefile +++ b/t/Makefile @@ -27,6 +27,8 @@ pre-clean: clean: $(RM) -r 'trash directory'.* test-results + $(RM) t????/cvsroot/CVSROOT/?* + $(RM) -r valgrind/bin aggregate-results-and-cleanup: $(T) $(MAKE) aggregate-results From 8ca788035644f2aaf7a951272ae16a7bd319554c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Scharfe?= Date: Sat, 13 Mar 2010 18:37:50 +0100 Subject: [PATCH 3/4] for_each_recent_reflog_ent(): use strbuf, fix offset handling As Vladimir reported, "git log -g refs/stash" surprisingly showed the reflog of HEAD if the message in the reflog file was too long. To fix this, convert for_each_recent_reflog_ent() to use strbuf_getwholeline() instead of fgets(), for safety and to avoid any size limits for reflog entries. Also reverse the logic of the part of the function that only looks at file tails. It used to close the file if fgets() succeeded. The following fgets() call in the while loop was likely to fail in this case, too, so passing an offset to for_each_recent_reflog_ent() never worked. Change it to error out if strbuf_getwholeline() fails instead. Reported-by: Vladimir Panteleev Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- refs.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/refs.c b/refs.c index f3fcbe023a..63e30d74a7 100644 --- a/refs.c +++ b/refs.c @@ -1574,7 +1574,7 @@ int for_each_recent_reflog_ent(const char *ref, each_reflog_ent_fn fn, long ofs, { const char *logfile; FILE *logfp; - char buf[1024]; + struct strbuf sb = STRBUF_INIT; int ret = 0; logfile = git_path("logs/%s", ref); @@ -1587,24 +1587,24 @@ int for_each_recent_reflog_ent(const char *ref, each_reflog_ent_fn fn, long ofs, if (fstat(fileno(logfp), &statbuf) || statbuf.st_size < ofs || fseek(logfp, -ofs, SEEK_END) || - fgets(buf, sizeof(buf), logfp)) { + strbuf_getwholeline(&sb, logfp, '\n')) { fclose(logfp); + strbuf_release(&sb); return -1; } } - while (fgets(buf, sizeof(buf), logfp)) { + while (!strbuf_getwholeline(&sb, logfp, '\n')) { unsigned char osha1[20], nsha1[20]; char *email_end, *message; unsigned long timestamp; - int len, tz; + int tz; /* old SP new SP name SP time TAB msg LF */ - len = strlen(buf); - if (len < 83 || buf[len-1] != '\n' || - get_sha1_hex(buf, osha1) || buf[40] != ' ' || - get_sha1_hex(buf + 41, nsha1) || buf[81] != ' ' || - !(email_end = strchr(buf + 82, '>')) || + if (sb.len < 83 || sb.buf[sb.len - 1] != '\n' || + get_sha1_hex(sb.buf, osha1) || sb.buf[40] != ' ' || + get_sha1_hex(sb.buf + 41, nsha1) || sb.buf[81] != ' ' || + !(email_end = strchr(sb.buf + 82, '>')) || email_end[1] != ' ' || !(timestamp = strtoul(email_end + 2, &message, 10)) || !message || message[0] != ' ' || @@ -1618,11 +1618,13 @@ int for_each_recent_reflog_ent(const char *ref, each_reflog_ent_fn fn, long ofs, message += 6; else message += 7; - ret = fn(osha1, nsha1, buf+82, timestamp, tz, message, cb_data); + ret = fn(osha1, nsha1, sb.buf + 82, timestamp, tz, message, + cb_data); if (ret) break; } fclose(logfp); + strbuf_release(&sb); return ret; } From 8fcaca3ff29a193f50a44bb3d5734a503e0539a6 Mon Sep 17 00:00:00 2001 From: Dave Olszewski Date: Sat, 13 Mar 2010 14:47:05 -0800 Subject: [PATCH 4/4] don't use default revision if a rev was specified MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If a revision is specified, it happens not to have any commits, don't use the default revision. By doing so, surprising and undesired behavior can happen, such as showing the reflog for HEAD when a branch was specified. [jc: squashed a test from René] Signed-off-by: Dave Olszewski Signed-off-by: Junio C Hamano --- revision.c | 6 ++++-- t/t1411-reflog-show.sh | 9 +++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/revision.c b/revision.c index 29721ecf84..490b484084 100644 --- a/revision.c +++ b/revision.c @@ -1334,7 +1334,7 @@ static void append_prune_data(const char ***prune_data, const char **av) */ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const char *def) { - int i, flags, left, seen_dashdash, read_from_stdin; + int i, flags, left, seen_dashdash, read_from_stdin, got_rev_arg = 0; const char **prune_data = NULL; /* First, search for "--" */ @@ -1460,6 +1460,8 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch append_prune_data(&prune_data, argv + i); break; } + else + got_rev_arg = 1; } if (prune_data) @@ -1469,7 +1471,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch revs->def = def; if (revs->show_merge) prepare_show_merge(revs); - if (revs->def && !revs->pending.nr) { + if (revs->def && !revs->pending.nr && !got_rev_arg) { unsigned char sha1[20]; struct object *object; unsigned mode; diff --git a/t/t1411-reflog-show.sh b/t/t1411-reflog-show.sh index c18ed8edf9..ba25ff354d 100755 --- a/t/t1411-reflog-show.sh +++ b/t/t1411-reflog-show.sh @@ -64,4 +64,13 @@ test_expect_success 'using --date= shows reflog date (oneline)' ' test_cmp expect actual ' +: >expect +test_expect_success 'empty reflog file' ' + git branch empty && + : >.git/logs/refs/heads/empty && + + git log -g empty >actual && + test_cmp expect actual +' + test_done