Skip to content

Commit befe863

Browse files
Junio C HamanoLinus Torvalds
authored andcommitted
[PATCH] diff: consolidate various calls into diffcore.
The three diff-* brothers had a sequence of calls into diffcore that were almost identical. Introduce a new diffcore_std() function that takes all the necessary arguments to consolidate it. This will make later enhancements and changing the order of diffcore application simpler. Signed-off-by: Junio C Hamano <junkio@cox.net> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
1 parent ddafa7e commit befe863

File tree

5 files changed

+25
-16
lines changed

5 files changed

+25
-16
lines changed

diff-cache.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -240,12 +240,9 @@ int main(int argc, const char **argv)
240240
die("unable to read tree object %s", tree_name);
241241

242242
ret = diff_cache(active_cache, active_nr);
243-
if (pathspec)
244-
diffcore_pathspec(pathspec);
245-
if (detect_rename)
246-
diffcore_rename(detect_rename, diff_score_opt);
247-
if (pickaxe)
248-
diffcore_pickaxe(pickaxe, pickaxe_opts);
243+
diffcore_std(pathspec,
244+
detect_rename, diff_score_opt,
245+
pickaxe, pickaxe_opts);
249246
diff_flush(diff_output_format, 1);
250247
return ret;
251248
}

diff-files.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,9 @@ int main(int argc, const char **argv)
116116
show_modified(oldmode, mode, ce->sha1, null_sha1,
117117
ce->name);
118118
}
119-
if (1 < argc)
120-
diffcore_pathspec(argv + 1);
121-
if (detect_rename)
122-
diffcore_rename(detect_rename, diff_score_opt);
123-
if (pickaxe)
124-
diffcore_pickaxe(pickaxe, pickaxe_opts);
119+
diffcore_std(argv + 1,
120+
detect_rename, diff_score_opt,
121+
pickaxe, pickaxe_opts);
125122
diff_flush(diff_output_format, 1);
126123
return 0;
127124
}

diff-tree.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -261,10 +261,9 @@ static void call_diff_setup(void)
261261

262262
static int call_diff_flush(void)
263263
{
264-
if (detect_rename)
265-
diffcore_rename(detect_rename, diff_score_opt);
266-
if (pickaxe)
267-
diffcore_pickaxe(pickaxe, pickaxe_opts);
264+
diffcore_std(0,
265+
detect_rename, diff_score_opt,
266+
pickaxe, pickaxe_opts);
268267
if (diff_queue_is_empty()) {
269268
diff_flush(DIFF_FORMAT_NO_OUTPUT, 0);
270269
return 0;

diff.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -887,6 +887,18 @@ void diff_flush(int diff_output_style, int resolve_rename_copy)
887887
q->nr = q->alloc = 0;
888888
}
889889

890+
void diffcore_std(const char **paths,
891+
int detect_rename, int rename_score,
892+
const char *pickaxe, int pickaxe_opts)
893+
{
894+
if (paths && paths[0])
895+
diffcore_pathspec(paths);
896+
if (detect_rename)
897+
diffcore_rename(detect_rename, rename_score);
898+
if (pickaxe)
899+
diffcore_pickaxe(pickaxe, pickaxe_opts);
900+
}
901+
890902
void diff_addremove(int addremove, unsigned mode,
891903
const unsigned char *sha1,
892904
const char *base, const char *path)

diff.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ extern void diffcore_pickaxe(const char *needle, int opts);
4343

4444
extern void diffcore_pathspec(const char **pathspec);
4545

46+
extern void diffcore_std(const char **paths,
47+
int detect_rename, int rename_score,
48+
const char *pickaxe, int pickaxe_opts);
49+
4650
extern int diff_queue_is_empty(void);
4751

4852
#define DIFF_FORMAT_HUMAN 0

0 commit comments

Comments
 (0)