Skip to content

Commit bc99009

Browse files
theiostreamdscho
authored andcommitted
diff: export diffstat interface
Make the diffstat interface (namely, the diffstat_t struct and compute_diffstat) no longer be internal to diff.c and allow it to be used by other parts of git. This is helpful for code that may want to easily extract information from files using the diff machinery, while flushing it differently from how the show_* functions used by diff_flush() do it. One example is the builtin implementation of git-add--interactive's status. Signed-off-by: Daniel Ferreira <[email protected]> Signed-off-by: Slavica Djukic <[email protected]> Signed-off-by: Johannes Schindelin <[email protected]>
1 parent ed53346 commit bc99009

File tree

2 files changed

+34
-22
lines changed

2 files changed

+34
-22
lines changed

diff.c

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2489,22 +2489,6 @@ static void pprint_rename(struct strbuf *name, const char *a, const char *b)
24892489
}
24902490
}
24912491

2492-
struct diffstat_t {
2493-
int nr;
2494-
int alloc;
2495-
struct diffstat_file {
2496-
char *from_name;
2497-
char *name;
2498-
char *print_name;
2499-
const char *comments;
2500-
unsigned is_unmerged:1;
2501-
unsigned is_binary:1;
2502-
unsigned is_renamed:1;
2503-
unsigned is_interesting:1;
2504-
uintmax_t added, deleted;
2505-
} **files;
2506-
};
2507-
25082492
static struct diffstat_file *diffstat_add(struct diffstat_t *diffstat,
25092493
const char *name_a,
25102494
const char *name_b)
@@ -6001,12 +5985,7 @@ void diff_flush(struct diff_options *options)
60015985
dirstat_by_line) {
60025986
struct diffstat_t diffstat;
60035987

6004-
memset(&diffstat, 0, sizeof(struct diffstat_t));
6005-
for (i = 0; i < q->nr; i++) {
6006-
struct diff_filepair *p = q->queue[i];
6007-
if (check_pair_status(p))
6008-
diff_flush_stat(p, options, &diffstat);
6009-
}
5988+
compute_diffstat(options, &diffstat, q);
60105989
if (output_format & DIFF_FORMAT_NUMSTAT)
60115990
show_numstat(&diffstat, options);
60125991
if (output_format & DIFF_FORMAT_DIFFSTAT)
@@ -6306,6 +6285,20 @@ static int is_submodule_ignored(const char *path, struct diff_options *options)
63066285
return ignored;
63076286
}
63086287

6288+
void compute_diffstat(struct diff_options *options,
6289+
struct diffstat_t *diffstat,
6290+
struct diff_queue_struct *q)
6291+
{
6292+
int i;
6293+
6294+
memset(diffstat, 0, sizeof(struct diffstat_t));
6295+
for (i = 0; i < q->nr; i++) {
6296+
struct diff_filepair *p = q->queue[i];
6297+
if (check_pair_status(p))
6298+
diff_flush_stat(p, options, diffstat);
6299+
}
6300+
}
6301+
63096302
void diff_addremove(struct diff_options *options,
63106303
int addremove, unsigned mode,
63116304
const struct object_id *oid,

diff.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,22 @@ void diff_emit_submodule_error(struct diff_options *o, const char *err);
240240
void diff_emit_submodule_pipethrough(struct diff_options *o,
241241
const char *line, int len);
242242

243+
struct diffstat_t {
244+
int nr;
245+
int alloc;
246+
struct diffstat_file {
247+
char *from_name;
248+
char *name;
249+
char *print_name;
250+
const char *comments;
251+
unsigned is_unmerged:1;
252+
unsigned is_binary:1;
253+
unsigned is_renamed:1;
254+
unsigned is_interesting:1;
255+
uintmax_t added, deleted;
256+
} **files;
257+
};
258+
243259
enum color_diff {
244260
DIFF_RESET = 0,
245261
DIFF_CONTEXT = 1,
@@ -328,6 +344,9 @@ void diff_change(struct diff_options *,
328344

329345
struct diff_filepair *diff_unmerge(struct diff_options *, const char *path);
330346

347+
void compute_diffstat(struct diff_options *options, struct diffstat_t *diffstat,
348+
struct diff_queue_struct *q);
349+
331350
#define DIFF_SETUP_REVERSE 1
332351
#define DIFF_SETUP_USE_SIZE_CACHE 4
333352

0 commit comments

Comments
 (0)