Skip to content

Commit

Permalink
Merge branch 'zj/decimal-width'
Browse files Browse the repository at this point in the history
* zj/decimal-width:
  make lineno_width() from blame reusable for others

Conflicts:
	cache.h
	pager.c
  • Loading branch information
Junio C Hamano committed Feb 20, 2012
2 parents 583c389 + ec7ff5b commit 4d9e079
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
18 changes: 3 additions & 15 deletions builtin/blame.c
Original file line number Diff line number Diff line change
Expand Up @@ -1828,18 +1828,6 @@ static int read_ancestry(const char *graft_file)
return 0;
}

/*
* How many columns do we need to show line numbers in decimal?
*/
static int lineno_width(int lines)
{
int i, width;

for (width = 1, i = 10; i <= lines; width++)
i *= 10;
return width;
}

/*
* How many columns do we need to show line numbers, authors,
* and filenames?
Expand Down Expand Up @@ -1880,9 +1868,9 @@ static void find_alignment(struct scoreboard *sb, int *option)
if (largest_score < ent_score(sb, e))
largest_score = ent_score(sb, e);
}
max_orig_digits = lineno_width(longest_src_lines);
max_digits = lineno_width(longest_dst_lines);
max_score_digits = lineno_width(largest_score);
max_orig_digits = decimal_width(longest_src_lines);
max_digits = decimal_width(longest_dst_lines);
max_score_digits = decimal_width(largest_score);
}

/*
Expand Down
1 change: 1 addition & 0 deletions cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -1178,6 +1178,7 @@ extern const char *pager_program;
extern int pager_in_use(void);
extern int pager_use_color;
extern int term_columns(void);
extern int decimal_width(int);

extern const char *editor_program;
extern const char *askpass_program;
Expand Down
12 changes: 12 additions & 0 deletions pager.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,15 @@ int term_columns(void)

return term_columns_at_startup;
}

/*
* How many columns do we need to show this number in decimal?
*/
int decimal_width(int number)
{
int i, width;

for (width = 1, i = 10; i <= number; width++)
i *= 10;
return width;
}

0 comments on commit 4d9e079

Please sign in to comment.