Skip to content

Commit 4d9e079

Browse files
committed
Merge branch 'zj/decimal-width'
* zj/decimal-width: make lineno_width() from blame reusable for others Conflicts: cache.h pager.c
2 parents 583c389 + ec7ff5b commit 4d9e079

File tree

3 files changed

+16
-15
lines changed

3 files changed

+16
-15
lines changed

builtin/blame.c

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1828,18 +1828,6 @@ static int read_ancestry(const char *graft_file)
18281828
return 0;
18291829
}
18301830

1831-
/*
1832-
* How many columns do we need to show line numbers in decimal?
1833-
*/
1834-
static int lineno_width(int lines)
1835-
{
1836-
int i, width;
1837-
1838-
for (width = 1, i = 10; i <= lines; width++)
1839-
i *= 10;
1840-
return width;
1841-
}
1842-
18431831
/*
18441832
* How many columns do we need to show line numbers, authors,
18451833
* and filenames?
@@ -1880,9 +1868,9 @@ static void find_alignment(struct scoreboard *sb, int *option)
18801868
if (largest_score < ent_score(sb, e))
18811869
largest_score = ent_score(sb, e);
18821870
}
1883-
max_orig_digits = lineno_width(longest_src_lines);
1884-
max_digits = lineno_width(longest_dst_lines);
1885-
max_score_digits = lineno_width(largest_score);
1871+
max_orig_digits = decimal_width(longest_src_lines);
1872+
max_digits = decimal_width(longest_dst_lines);
1873+
max_score_digits = decimal_width(largest_score);
18861874
}
18871875

18881876
/*

cache.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,6 +1178,7 @@ extern const char *pager_program;
11781178
extern int pager_in_use(void);
11791179
extern int pager_use_color;
11801180
extern int term_columns(void);
1181+
extern int decimal_width(int);
11811182

11821183
extern const char *editor_program;
11831184
extern const char *askpass_program;

pager.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,3 +147,15 @@ int term_columns(void)
147147

148148
return term_columns_at_startup;
149149
}
150+
151+
/*
152+
* How many columns do we need to show this number in decimal?
153+
*/
154+
int decimal_width(int number)
155+
{
156+
int i, width;
157+
158+
for (width = 1, i = 10; i <= number; width++)
159+
i *= 10;
160+
return width;
161+
}

0 commit comments

Comments
 (0)