Skip to content

Commit 3a27f41

Browse files
committed
Merge branch 'maint'
* maint: don't use default revision if a rev was specified for_each_recent_reflog_ent(): use strbuf, fix offset handling t/Makefile: remove test artifacts upon "make clean" blame: fix indent of line numbers
2 parents 19a6477 + 8fcaca3 commit 3a27f41

File tree

6 files changed

+47
-14
lines changed

6 files changed

+47
-14
lines changed

builtin/blame.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1772,7 +1772,7 @@ static int lineno_width(int lines)
17721772
{
17731773
int i, width;
17741774

1775-
for (width = 1, i = 10; i <= lines + 1; width++)
1775+
for (width = 1, i = 10; i <= lines; width++)
17761776
i *= 10;
17771777
return width;
17781778
}

refs.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1574,7 +1574,7 @@ int for_each_recent_reflog_ent(const char *ref, each_reflog_ent_fn fn, long ofs,
15741574
{
15751575
const char *logfile;
15761576
FILE *logfp;
1577-
char buf[1024];
1577+
struct strbuf sb = STRBUF_INIT;
15781578
int ret = 0;
15791579

15801580
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,
15871587
if (fstat(fileno(logfp), &statbuf) ||
15881588
statbuf.st_size < ofs ||
15891589
fseek(logfp, -ofs, SEEK_END) ||
1590-
fgets(buf, sizeof(buf), logfp)) {
1590+
strbuf_getwholeline(&sb, logfp, '\n')) {
15911591
fclose(logfp);
1592+
strbuf_release(&sb);
15921593
return -1;
15931594
}
15941595
}
15951596

1596-
while (fgets(buf, sizeof(buf), logfp)) {
1597+
while (!strbuf_getwholeline(&sb, logfp, '\n')) {
15971598
unsigned char osha1[20], nsha1[20];
15981599
char *email_end, *message;
15991600
unsigned long timestamp;
1600-
int len, tz;
1601+
int tz;
16011602

16021603
/* old SP new SP name <email> SP time TAB msg LF */
1603-
len = strlen(buf);
1604-
if (len < 83 || buf[len-1] != '\n' ||
1605-
get_sha1_hex(buf, osha1) || buf[40] != ' ' ||
1606-
get_sha1_hex(buf + 41, nsha1) || buf[81] != ' ' ||
1607-
!(email_end = strchr(buf + 82, '>')) ||
1604+
if (sb.len < 83 || sb.buf[sb.len - 1] != '\n' ||
1605+
get_sha1_hex(sb.buf, osha1) || sb.buf[40] != ' ' ||
1606+
get_sha1_hex(sb.buf + 41, nsha1) || sb.buf[81] != ' ' ||
1607+
!(email_end = strchr(sb.buf + 82, '>')) ||
16081608
email_end[1] != ' ' ||
16091609
!(timestamp = strtoul(email_end + 2, &message, 10)) ||
16101610
!message || message[0] != ' ' ||
@@ -1618,11 +1618,13 @@ int for_each_recent_reflog_ent(const char *ref, each_reflog_ent_fn fn, long ofs,
16181618
message += 6;
16191619
else
16201620
message += 7;
1621-
ret = fn(osha1, nsha1, buf+82, timestamp, tz, message, cb_data);
1621+
ret = fn(osha1, nsha1, sb.buf + 82, timestamp, tz, message,
1622+
cb_data);
16221623
if (ret)
16231624
break;
16241625
}
16251626
fclose(logfp);
1627+
strbuf_release(&sb);
16261628
return ret;
16271629
}
16281630

revision.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1334,7 +1334,7 @@ static void append_prune_data(const char ***prune_data, const char **av)
13341334
*/
13351335
int setup_revisions(int argc, const char **argv, struct rev_info *revs, const char *def)
13361336
{
1337-
int i, flags, left, seen_dashdash, read_from_stdin;
1337+
int i, flags, left, seen_dashdash, read_from_stdin, got_rev_arg = 0;
13381338
const char **prune_data = NULL;
13391339

13401340
/* First, search for "--" */
@@ -1460,6 +1460,8 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch
14601460
append_prune_data(&prune_data, argv + i);
14611461
break;
14621462
}
1463+
else
1464+
got_rev_arg = 1;
14631465
}
14641466

14651467
if (prune_data)
@@ -1469,7 +1471,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch
14691471
revs->def = def;
14701472
if (revs->show_merge)
14711473
prepare_show_merge(revs);
1472-
if (revs->def && !revs->pending.nr) {
1474+
if (revs->def && !revs->pending.nr && !got_rev_arg) {
14731475
unsigned char sha1[20];
14741476
struct object *object;
14751477
unsigned mode;

t/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ pre-clean:
2727

2828
clean:
2929
$(RM) -r 'trash directory'.* test-results
30+
$(RM) t????/cvsroot/CVSROOT/?*
31+
$(RM) -r valgrind/bin
3032

3133
aggregate-results-and-cleanup: $(T)
3234
$(MAKE) aggregate-results

t/t1411-reflog-show.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,13 @@ test_expect_success 'using --date= shows reflog date (oneline)' '
6464
test_cmp expect actual
6565
'
6666

67+
: >expect
68+
test_expect_success 'empty reflog file' '
69+
git branch empty &&
70+
: >.git/logs/refs/heads/empty &&
71+
72+
git log -g empty >actual &&
73+
test_cmp expect actual
74+
'
75+
6776
test_done

t/t8003-blame.sh

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,15 @@ test_expect_success setup '
1111
echo B B B B B >two &&
1212
echo C C C C C >tres &&
1313
echo ABC >mouse &&
14-
git add one two tres mouse &&
14+
for i in 1 2 3 4 5 6 7 8 9
15+
do
16+
echo $i
17+
done >nine_lines &&
18+
for i in 1 2 3 4 5 6 7 8 9 a
19+
do
20+
echo $i
21+
done >ten_lines &&
22+
git add one two tres mouse nine_lines ten_lines &&
1523
test_tick &&
1624
GIT_AUTHOR_NAME=Initial git commit -m Initial &&
1725
@@ -167,4 +175,14 @@ test_expect_success 'blame -L with invalid end' '
167175
grep "has only 2 lines" errors
168176
'
169177

178+
test_expect_success 'indent of line numbers, nine lines' '
179+
git blame nine_lines >actual &&
180+
test $(grep -c " " actual) = 0
181+
'
182+
183+
test_expect_success 'indent of line numbers, ten lines' '
184+
git blame ten_lines >actual &&
185+
test $(grep -c " " actual) = 9
186+
'
187+
170188
test_done

0 commit comments

Comments
 (0)