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 */ 26static 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 42int 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}