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
This commit is contained in:
Junio C Hamano 2010-03-13 21:31:42 -08:00
commit 3a27f415df
6 changed files with 47 additions and 14 deletions

View file

@ -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;
}

22
refs.c
View file

@ -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 <email> 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;
}

View file

@ -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;

View file

@ -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

View file

@ -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

View file

@ -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