Skip to content

Commit 6799aad

Browse files
peffgitster
authored andcommitted
diff: factor out src/dst prefix setup
We directly manipulate diffopt's a_prefix and b_prefix to set up either the default "a/foo" prefix or the "--no-prefix" variant. Although this is only a few lines, it's worth pulling these into their own functions. That lets us avoid one repetition already in this patch, but will also give us a cleaner interface for callers which want to tweak this setting. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 725f570 commit 6799aad

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

diff.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3374,6 +3374,17 @@ void diff_set_mnemonic_prefix(struct diff_options *options, const char *a, const
33743374
options->b_prefix = b;
33753375
}
33763376

3377+
void diff_set_noprefix(struct diff_options *options)
3378+
{
3379+
options->a_prefix = options->b_prefix = "";
3380+
}
3381+
3382+
void diff_set_default_prefix(struct diff_options *options)
3383+
{
3384+
options->a_prefix = "a/";
3385+
options->b_prefix = "b/";
3386+
}
3387+
33773388
struct userdiff_driver *get_textconv(struct repository *r,
33783389
struct diff_filespec *one)
33793390
{
@@ -4674,10 +4685,9 @@ void repo_diff_setup(struct repository *r, struct diff_options *options)
46744685
options->flags.ignore_untracked_in_submodules = 1;
46754686

46764687
if (diff_no_prefix) {
4677-
options->a_prefix = options->b_prefix = "";
4688+
diff_set_noprefix(options);
46784689
} else if (!diff_mnemonic_prefix) {
4679-
options->a_prefix = "a/";
4680-
options->b_prefix = "b/";
4690+
diff_set_default_prefix(options);
46814691
}
46824692

46834693
options->color_moved = diff_color_moved_default;
@@ -5261,8 +5271,7 @@ static int diff_opt_no_prefix(const struct option *opt,
52615271

52625272
BUG_ON_OPT_NEG(unset);
52635273
BUG_ON_OPT_ARG(optarg);
5264-
options->a_prefix = "";
5265-
options->b_prefix = "";
5274+
diff_set_noprefix(options);
52665275
return 0;
52675276
}
52685277

diff.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,8 @@ void diff_tree_combined(const struct object_id *oid, const struct oid_array *par
497497
void diff_tree_combined_merge(const struct commit *commit, struct rev_info *rev);
498498

499499
void diff_set_mnemonic_prefix(struct diff_options *options, const char *a, const char *b);
500+
void diff_set_noprefix(struct diff_options *options);
501+
void diff_set_default_prefix(struct diff_options *options);
500502

501503
int diff_can_quit_early(struct diff_options *);
502504

0 commit comments

Comments
 (0)