make lineno_width() from blame reusable for others
builtin/blame.c has a helper function to compute how many columns we need to show a line-number, whose implementation is reusable as a more generic helper function to count the number of columns necessary to show any cardinal number. Rename it to decimal_width(), move it to pager.c and export it for use by future callers. Signed-off-by: Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> Signed-off-by: Junio C Hamano <gitster@pobox.com>maint
							parent
							
								
									58d4203aa6
								
							
						
					
					
						commit
						ec7ff5ba27
					
				|  | @ -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? | ||||
|  | @ -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); | ||||
| } | ||||
|  | ||||
| /* | ||||
|  |  | |||
							
								
								
									
										1
									
								
								cache.h
								
								
								
								
							
							
						
						
									
										1
									
								
								cache.h
								
								
								
								
							|  | @ -1176,6 +1176,7 @@ extern void setup_pager(void); | |||
| extern const char *pager_program; | ||||
| extern int pager_in_use(void); | ||||
| extern int pager_use_color; | ||||
| extern int decimal_width(int); | ||||
|  | ||||
| extern const char *editor_program; | ||||
| extern const char *askpass_program; | ||||
|  |  | |||
							
								
								
									
										12
									
								
								pager.c
								
								
								
								
							
							
						
						
									
										12
									
								
								pager.c
								
								
								
								
							|  | @ -110,3 +110,15 @@ int pager_in_use(void) | |||
| 	env = getenv("GIT_PAGER_IN_USE"); | ||||
| 	return env ? git_config_bool("GIT_PAGER_IN_USE", env) : 0; | ||||
| } | ||||
|  | ||||
| /* | ||||
|  * 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; | ||||
| } | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	 Zbigniew Jędrzejewski-Szmek
						Zbigniew Jędrzejewski-Szmek