Skip to content

Commit 3a10fd7

Browse files
committed
difftool: add a skeleton for the upcoming builtin
This adds a builtin difftool that still falls back to the legacy Perl version, which has been renamed to `legacy-difftool`. The idea is that the new, experimental, builtin difftool immediately hands off to the legacy difftool for now, unless the config variable difftool.useBuiltin is set to true. This feature flag will be used in the upcoming Git for Windows v2.11.0 release, to allow early testers to opt-in to use the builtin difftool and flesh out any bugs. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent e2b2d6a commit 3a10fd7

File tree

7 files changed

+75
-1
lines changed

7 files changed

+75
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
/git-init-db
7777
/git-interpret-trailers
7878
/git-instaweb
79+
/git-legacy-difftool
7980
/git-log
8081
/git-ls-files
8182
/git-ls-remote

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ SCRIPT_LIB += git-sh-setup
527527
SCRIPT_LIB += git-sh-i18n
528528

529529
SCRIPT_PERL += git-add--interactive.perl
530-
SCRIPT_PERL += git-difftool.perl
530+
SCRIPT_PERL += git-legacy-difftool.perl
531531
SCRIPT_PERL += git-archimport.perl
532532
SCRIPT_PERL += git-cvsexportcommit.perl
533533
SCRIPT_PERL += git-cvsimport.perl
@@ -888,6 +888,7 @@ BUILTIN_OBJS += builtin/diff-files.o
888888
BUILTIN_OBJS += builtin/diff-index.o
889889
BUILTIN_OBJS += builtin/diff-tree.o
890890
BUILTIN_OBJS += builtin/diff.o
891+
BUILTIN_OBJS += builtin/difftool.o
891892
BUILTIN_OBJS += builtin/fast-export.o
892893
BUILTIN_OBJS += builtin/fetch-pack.o
893894
BUILTIN_OBJS += builtin/fetch.o

builtin.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ extern int cmd_diff_files(int argc, const char **argv, const char *prefix);
6060
extern int cmd_diff_index(int argc, const char **argv, const char *prefix);
6161
extern int cmd_diff(int argc, const char **argv, const char *prefix);
6262
extern int cmd_diff_tree(int argc, const char **argv, const char *prefix);
63+
extern int cmd_difftool(int argc, const char **argv, const char *prefix);
6364
extern int cmd_fast_export(int argc, const char **argv, const char *prefix);
6465
extern int cmd_fetch(int argc, const char **argv, const char *prefix);
6566
extern int cmd_fetch_pack(int argc, const char **argv, const char *prefix);

builtin/difftool.c

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* "git difftool" builtin command
3+
*
4+
* This is a wrapper around the GIT_EXTERNAL_DIFF-compatible
5+
* git-difftool--helper script.
6+
*
7+
* This script exports GIT_EXTERNAL_DIFF and GIT_PAGER for use by git.
8+
* The GIT_DIFF* variables are exported for use by git-difftool--helper.
9+
*
10+
* Any arguments that are unknown to this script are forwarded to 'git diff'.
11+
*
12+
* Copyright (C) 2016 Johannes Schindelin
13+
*/
14+
#include "builtin.h"
15+
#include "run-command.h"
16+
#include "exec_cmd.h"
17+
18+
/*
19+
* NEEDSWORK: this function can go once the legacy-difftool Perl script is
20+
* retired.
21+
*
22+
* We intentionally avoid reading the config directly here, to avoid messing up
23+
* the GIT_* environment variables when we need to fall back to exec()ing the
24+
* Perl script.
25+
*/
26+
static int use_builtin_difftool(void) {
27+
struct child_process cp = CHILD_PROCESS_INIT;
28+
struct strbuf out = STRBUF_INIT;
29+
int ret;
30+
31+
argv_array_pushl(&cp.args,
32+
"config", "--bool", "difftool.usebuiltin", NULL);
33+
cp.git_cmd = 1;
34+
if (capture_command(&cp, &out, 6))
35+
return 0;
36+
strbuf_trim(&out);
37+
ret = !strcmp("true", out.buf);
38+
strbuf_release(&out);
39+
return ret;
40+
}
41+
42+
int cmd_difftool(int argc, const char **argv, const char *prefix)
43+
{
44+
/*
45+
* NEEDSWORK: Once the builtin difftool has been tested enough
46+
* and git-legacy-difftool.perl is retired to contrib/, this preamble
47+
* can be removed.
48+
*/
49+
if (!use_builtin_difftool()) {
50+
const char *path = mkpath("%s/git-legacy-difftool",
51+
git_exec_path());
52+
53+
if (sane_execvp(path, (char **)argv) < 0)
54+
die_errno("could not exec %s", path);
55+
56+
return 0;
57+
}
58+
prefix = setup_git_directory();
59+
trace_repo_setup(prefix);
60+
setup_work_tree();
61+
62+
die("TODO");
63+
}
File renamed without changes.

git.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,12 @@ static struct cmd_struct commands[] = {
424424
{ "diff-files", cmd_diff_files, RUN_SETUP | NEED_WORK_TREE },
425425
{ "diff-index", cmd_diff_index, RUN_SETUP },
426426
{ "diff-tree", cmd_diff_tree, RUN_SETUP },
427+
/*
428+
* NEEDSWORK: Once the redirection to git-legacy-difftool.perl in
429+
* builtin/difftool.c has been removed, this entry should be changed to
430+
* RUN_SETUP | NEED_WORK_TREE
431+
*/
432+
{ "difftool", cmd_difftool },
427433
{ "fast-export", cmd_fast_export, RUN_SETUP },
428434
{ "fetch", cmd_fetch, RUN_SETUP },
429435
{ "fetch-pack", cmd_fetch_pack, RUN_SETUP },

t/t7800-difftool.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ prompt_given ()
2323
test "$prompt" = "Launch 'test-tool' [Y/n]? branch"
2424
}
2525

26+
# NEEDSWORK: lose all the PERL prereqs once legacy-difftool is retired.
27+
2628
# Create a file on master and change it on branch
2729
test_expect_success PERL 'setup' '
2830
echo master >file &&

0 commit comments

Comments
 (0)