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 intuse_builtin_difftool(void) { 27struct child_process cp = CHILD_PROCESS_INIT; 28struct strbuf out = STRBUF_INIT; 29int ret; 30 31argv_array_pushl(&cp.args, 32"config","--bool","difftool.usebuiltin", NULL); 33 cp.git_cmd =1; 34if(capture_command(&cp, &out,6)) 35return0; 36strbuf_trim(&out); 37 ret = !strcmp("true", out.buf); 38strbuf_release(&out); 39return ret; 40} 41 42intcmd_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 */ 49if(!use_builtin_difftool()) { 50const char*path =mkpath("%s/git-legacy-difftool", 51git_exec_path()); 52 53if(sane_execvp(path, (char**)argv) <0) 54die_errno("could not exec%s", path); 55 56return0; 57} 58 prefix =setup_git_directory(); 59trace_repo_setup(prefix); 60setup_work_tree(); 61 62die("TODO"); 63}