static int pickaxe_opts = 0;
static int diff_break_opt = -1;
static const char *orderfile = NULL;
+static const char *diff_filter = NULL;
/* A file entry went away or appeared */
static void show_file(const char *prefix, struct cache_entry *ce, unsigned char *sha1, unsigned int mode)
pickaxe = arg + 2;
continue;
}
+ if (!strncmp(arg, "--diff-filter=", 14)) {
+ diff_filter = arg + 14;
+ continue;
+ }
if (!strncmp(arg, "-O", 2)) {
orderfile = arg + 2;
continue;
detect_rename, diff_score_opt,
pickaxe, pickaxe_opts,
diff_break_opt,
- orderfile);
- diff_flush(diff_output_format, 1);
+ orderfile, diff_filter);
+ diff_flush(diff_output_format);
return ret;
}
static int pickaxe_opts = 0;
static int diff_break_opt = -1;
static const char *orderfile = NULL;
+static const char *diff_filter = NULL;
static int silent = 0;
static void show_unmerge(const char *path)
pickaxe = argv[1] + 2;
else if (!strncmp(argv[1], "-O", 2))
orderfile = argv[1] + 2;
+ else if (!strncmp(argv[1], "--diff-filter=", 14))
+ diff_filter = argv[1] + 14;
else if (!strcmp(argv[1], "--pickaxe-all"))
pickaxe_opts = DIFF_PICKAXE_ALL;
else if (!strncmp(argv[1], "-B", 2)) {
detect_rename, diff_score_opt,
pickaxe, pickaxe_opts,
diff_break_opt,
- orderfile);
- diff_flush(diff_output_format, 1);
+ orderfile, diff_filter);
+ diff_flush(diff_output_format);
return 0;
}
static const char *pickaxe = NULL;
static int pickaxe_opts = 0;
static const char *orderfile = NULL;
+static const char *diff_filter = NULL;
static int line_termination = '\n';
static int inter_name_termination = '\t';
static void flush_them(int ac, const char **av)
{
- diffcore_std(av + 1,
- 0, 0, /* no renames */
- pickaxe, pickaxe_opts,
- -1, /* no breaks */
- orderfile);
- diff_flush(DIFF_FORMAT_PATCH, 0);
+ diffcore_std_no_resolve(av + 1,
+ pickaxe, pickaxe_opts,
+ orderfile, diff_filter);
+ diff_flush(DIFF_FORMAT_PATCH);
}
static const char *diff_helper_usage =
}
else if (!strcmp(av[1], "--pickaxe-all"))
pickaxe_opts = DIFF_PICKAXE_ALL;
+ else if (!strncmp(av[1], "--diff-filter=", 14))
+ diff_filter = av[1] + 14;
+ else if (!strncmp(av[1], "-O", 2))
+ orderfile = av[1] + 2;
else
usage(diff_helper_usage);
ac--; av++;
static int pickaxe_opts = 0;
static int diff_break_opt = -1;
static const char *orderfile = NULL;
+static const char *diff_filter = NULL;
static char *diff_stages_usage =
"git-diff-stages [-p] [-r] [-z] [-M] [-C] [-R] [-S<string>] [-O<orderfile>] <stage1> <stage2> [<path>...]";
pickaxe = arg + 2;
else if (!strncmp(arg, "-O", 2))
orderfile = arg + 2;
+ else if (!strncmp(arg, "--diff-filter=", 14))
+ diff_filter = arg + 14;
else if (!strcmp(arg, "--pickaxe-all"))
pickaxe_opts = DIFF_PICKAXE_ALL;
else
detect_rename, diff_score_opt,
pickaxe, pickaxe_opts,
diff_break_opt,
- orderfile);
- diff_flush(diff_output_format, 1);
+ orderfile,
+ diff_filter);
+ diff_flush(diff_output_format);
return 0;
}
static int pickaxe_opts = 0;
static int diff_break_opt = -1;
static const char *orderfile = NULL;
+static const char *diff_filter = NULL;
static const char *header = NULL;
static const char *header_prefix = "";
static enum cmit_fmt commit_format = CMIT_FMT_RAW;
detect_rename, diff_score_opt,
pickaxe, pickaxe_opts,
diff_break_opt,
- orderfile);
+ orderfile,
+ diff_filter);
if (diff_queue_is_empty()) {
- diff_flush(DIFF_FORMAT_NO_OUTPUT, 0);
+ diff_flush(DIFF_FORMAT_NO_OUTPUT);
return 0;
}
if (header) {
printf(fmt, header, 0);
header = NULL;
}
- diff_flush(diff_output_format, 1);
+ diff_flush(diff_output_format);
return 1;
}
orderfile = arg + 2;
continue;
}
+ if (!strncmp(arg, "--diff-filter=", 14)) {
+ diff_filter = arg + 14;
+ continue;
+ }
if (!strcmp(arg, "--pickaxe-all")) {
pickaxe_opts = DIFF_PICKAXE_ALL;
continue;
diff_debug_queue("resolve-rename-copy done", q);
}
-void diff_flush(int diff_output_style, int resolve_rename_copy)
+void diff_flush(int diff_output_style)
{
struct diff_queue_struct *q = &diff_queued_diff;
int i;
if (diff_output_style == DIFF_FORMAT_MACHINE)
line_termination = inter_name_termination = 0;
- if (resolve_rename_copy)
- diff_resolve_rename_copy();
for (i = 0; i < q->nr; i++) {
struct diff_filepair *p = q->queue[i];
q->nr = q->alloc = 0;
}
+static void diffcore_apply_filter(const char *filter)
+{
+ int i;
+ struct diff_queue_struct *q = &diff_queued_diff;
+ struct diff_queue_struct outq;
+ outq.queue = NULL;
+ outq.nr = outq.alloc = 0;
+
+ if (!filter)
+ return;
+
+ if (strchr(filter, 'A')) {
+ /* All-or-none */
+ int found;
+ for (i = found = 0; !found && i < q->nr; i++) {
+ struct diff_filepair *p = q->queue[i];
+ if ((p->broken_pair && strchr(filter, 'B')) ||
+ (!p->broken_pair && strchr(filter, p->status)))
+ found++;
+ }
+ if (found)
+ return;
+
+ /* otherwise we will clear the whole queue
+ * by copying the empty outq at the end of this
+ * function, but first clear the current entries
+ * in the queue.
+ */
+ for (i = 0; i < q->nr; i++)
+ diff_free_filepair(q->queue[i]);
+ }
+ else {
+ /* Only the matching ones */
+ for (i = 0; i < q->nr; i++) {
+ struct diff_filepair *p = q->queue[i];
+ if ((p->broken_pair && strchr(filter, 'B')) ||
+ (!p->broken_pair && strchr(filter, p->status)))
+ diff_q(&outq, p);
+ else
+ diff_free_filepair(p);
+ }
+ }
+ free(q->queue);
+ *q = outq;
+}
+
void diffcore_std(const char **paths,
int detect_rename, int rename_score,
const char *pickaxe, int pickaxe_opts,
int break_opt,
- const char *orderfile)
+ const char *orderfile,
+ const char *filter)
{
if (paths && paths[0])
diffcore_pathspec(paths);
diffcore_pickaxe(pickaxe, pickaxe_opts);
if (orderfile)
diffcore_order(orderfile);
+ diff_resolve_rename_copy();
+ diffcore_apply_filter(filter);
+}
+
+
+void diffcore_std_no_resolve(const char **paths,
+ const char *pickaxe, int pickaxe_opts,
+ const char *orderfile,
+ const char *filter)
+{
+ if (paths && paths[0])
+ diffcore_pathspec(paths);
+ if (pickaxe)
+ diffcore_pickaxe(pickaxe, pickaxe_opts);
+ if (orderfile)
+ diffcore_order(orderfile);
+ diffcore_apply_filter(filter);
}
void diff_addremove(int addremove, unsigned mode,
int detect_rename, int rename_score,
const char *pickaxe, int pickaxe_opts,
int break_opt,
- const char *orderfile);
+ const char *orderfile, const char *filter);
+
+extern void diffcore_std_no_resolve(const char **paths,
+ const char *pickaxe, int pickaxe_opts,
+ const char *orderfile, const char *filter);
extern int diff_queue_is_empty(void);
#define DIFF_FORMAT_PATCH 2
#define DIFF_FORMAT_NO_OUTPUT 3
-extern void diff_flush(int output_style, int resolve_rename_copy);
+extern void diff_flush(int output_style);
#endif /* DIFF_H */