Skip to content

Commit 34a9489

Browse files
committed
diff: refactor common tail part of dirstat computation
This will become useful when we plug leaks in these two functions. Signed-off-by: Junio C Hamano <[email protected]>
1 parent ec58344 commit 34a9489

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

diff.c

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2971,6 +2971,19 @@ static int dirstat_compare(const void *_a, const void *_b)
29712971
return strcmp(a->name, b->name);
29722972
}
29732973

2974+
static void conclude_dirstat(struct diff_options *options,
2975+
struct dirstat_dir *dir,
2976+
unsigned long changed)
2977+
{
2978+
/* This can happen even with many files, if everything was renames */
2979+
if (!changed)
2980+
return;
2981+
2982+
/* Show all directories with more than x% of the changes */
2983+
QSORT(dir->files, dir->nr, dirstat_compare);
2984+
gather_dirstat(options, dir, changed, "", 0);
2985+
}
2986+
29742987
static void show_dirstat(struct diff_options *options)
29752988
{
29762989
int i;
@@ -3060,13 +3073,7 @@ static void show_dirstat(struct diff_options *options)
30603073
dir.nr++;
30613074
}
30623075

3063-
/* This can happen even with many files, if everything was renames */
3064-
if (!changed)
3065-
return;
3066-
3067-
/* Show all directories with more than x% of the changes */
3068-
QSORT(dir.files, dir.nr, dirstat_compare);
3069-
gather_dirstat(options, &dir, changed, "", 0);
3076+
conclude_dirstat(options, &dir, changed);
30703077
}
30713078

30723079
static void show_dirstat_by_line(struct diffstat_t *data, struct diff_options *options)
@@ -3104,13 +3111,7 @@ static void show_dirstat_by_line(struct diffstat_t *data, struct diff_options *o
31043111
dir.nr++;
31053112
}
31063113

3107-
/* This can happen even with many files, if everything was renames */
3108-
if (!changed)
3109-
return;
3110-
3111-
/* Show all directories with more than x% of the changes */
3112-
QSORT(dir.files, dir.nr, dirstat_compare);
3113-
gather_dirstat(options, &dir, changed, "", 0);
3114+
conclude_dirstat(options, &dir, changed);
31143115
}
31153116

31163117
static void free_diffstat_file(struct diffstat_file *f)

0 commit comments

Comments
 (0)