mirror of
https://github.com/git/git.git
synced 2026-01-19 07:04:49 +00:00
Merge branch 'ml/trace' into next
* ml/trace: GIT_TRACE: fix a mixed declarations and code warning GIT_TRACE: show which built-in/external commands are executed Disable color detection during format-patch git-cvsexportcommit can't handle merge commits correctly Using 'perl' in *.sh sed -e '/RE/r rfile/' needs space in 'r rfile' Close the index file between writing and committing colored diff: diff.color = auto fix
This commit is contained in:
@@ -615,6 +615,13 @@ git Diffs
|
||||
gitlink:git-diff-files[1];
|
||||
gitlink:git-diff-tree[1]
|
||||
|
||||
other
|
||||
~~~~~
|
||||
'GIT_TRACE'::
|
||||
If this variable is set git will print `trace:` messages on
|
||||
stderr telling about alias expansion, built-in command
|
||||
execution and external command execution.
|
||||
|
||||
Discussion[[Discussion]]
|
||||
------------------------
|
||||
include::README[]
|
||||
|
||||
5
Makefile
5
Makefile
@@ -546,6 +546,7 @@ common-cmds.h: Documentation/git-*.txt
|
||||
$(patsubst %.sh,%,$(SCRIPT_SH)) : % : %.sh
|
||||
rm -f $@ $@+
|
||||
sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \
|
||||
-e 's|@@PERL@@|$(PERL_PATH_SQ)|g' \
|
||||
-e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \
|
||||
-e 's/@@NO_CURL@@/$(NO_CURL)/g' \
|
||||
-e 's/@@NO_PYTHON@@/$(NO_PYTHON)/g' \
|
||||
@@ -589,9 +590,9 @@ git-instaweb: git-instaweb.sh gitweb/gitweb.cgi gitweb/gitweb.css
|
||||
-e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \
|
||||
-e 's/@@NO_CURL@@/$(NO_CURL)/g' \
|
||||
-e 's/@@NO_PYTHON@@/$(NO_PYTHON)/g' \
|
||||
-e '/@@GITWEB_CGI@@/rgitweb/gitweb.cgi' \
|
||||
-e '/@@GITWEB_CGI@@/r gitweb/gitweb.cgi' \
|
||||
-e '/@@GITWEB_CGI@@/d' \
|
||||
-e '/@@GITWEB_CSS@@/rgitweb/gitweb.css' \
|
||||
-e '/@@GITWEB_CSS@@/r gitweb/gitweb.css' \
|
||||
-e '/@@GITWEB_CSS@@/d' \
|
||||
$@.sh > $@+
|
||||
chmod +x $@+
|
||||
|
||||
@@ -181,7 +181,7 @@ int cmd_add(int argc, const char **argv, char **envp)
|
||||
|
||||
if (active_cache_changed) {
|
||||
if (write_cache(newfd, active_cache, active_nr) ||
|
||||
commit_lock_file(&lock_file))
|
||||
close(newfd) || commit_lock_file(&lock_file))
|
||||
die("Unable to write new index file");
|
||||
}
|
||||
|
||||
|
||||
@@ -2323,7 +2323,7 @@ int cmd_apply(int argc, const char **argv, char **envp)
|
||||
|
||||
if (write_index) {
|
||||
if (write_cache(newfd, active_cache, active_nr) ||
|
||||
commit_lock_file(&lock_file))
|
||||
close(newfd) || commit_lock_file(&lock_file))
|
||||
die("Unable to write new index file");
|
||||
}
|
||||
|
||||
|
||||
@@ -105,6 +105,9 @@ static int git_format_config(const char *var, const char *value)
|
||||
strcat(extra_headers, value);
|
||||
return 0;
|
||||
}
|
||||
if (!strcmp(var, "diff.color")) {
|
||||
return 0;
|
||||
}
|
||||
return git_diff_ui_config(var, value);
|
||||
}
|
||||
|
||||
|
||||
@@ -1038,7 +1038,7 @@ int cmd_read_tree(int argc, const char **argv, char **envp)
|
||||
}
|
||||
|
||||
if (write_cache(newfd, active_cache, active_nr) ||
|
||||
commit_lock_file(&lock_file))
|
||||
close(newfd) || commit_lock_file(&lock_file))
|
||||
die("unable to write new index file");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -147,7 +147,7 @@ int cmd_rm(int argc, const char **argv, char **envp)
|
||||
|
||||
if (active_cache_changed) {
|
||||
if (write_cache(newfd, active_cache, active_nr) ||
|
||||
commit_lock_file(&lock_file))
|
||||
close(newfd) || commit_lock_file(&lock_file))
|
||||
die("Unable to write new index file");
|
||||
}
|
||||
|
||||
|
||||
@@ -648,7 +648,7 @@ int cmd_update_index(int argc, const char **argv, char **envp)
|
||||
finish:
|
||||
if (active_cache_changed) {
|
||||
if (write_cache(newfd, active_cache, active_nr) ||
|
||||
commit_lock_file(lock_file))
|
||||
close(newfd) || commit_lock_file(lock_file))
|
||||
die("Unable to write new index file");
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +35,8 @@ int write_tree(unsigned char *sha1, int missing_ok, const char *prefix)
|
||||
missing_ok, 0) < 0)
|
||||
die("git-write-tree: error building trees");
|
||||
if (0 <= newfd) {
|
||||
if (!write_cache(newfd, active_cache, active_nr))
|
||||
if (!write_cache(newfd, active_cache, active_nr)
|
||||
&& !close(newfd))
|
||||
commit_lock_file(lock_file);
|
||||
}
|
||||
/* Not being able to write is fine -- we are only interested
|
||||
|
||||
@@ -311,7 +311,7 @@ int main(int argc, char **argv)
|
||||
|
||||
if (0 <= newfd &&
|
||||
(write_cache(newfd, active_cache, active_nr) ||
|
||||
commit_lock_file(&lock_file)))
|
||||
close(newfd) || commit_lock_file(&lock_file)))
|
||||
die("Unable to write new index file");
|
||||
return 0;
|
||||
}
|
||||
|
||||
10
diff.c
10
diff.c
@@ -117,8 +117,14 @@ int git_diff_ui_config(const char *var, const char *value)
|
||||
if (!strcmp(var, "diff.color")) {
|
||||
if (!value)
|
||||
diff_use_color_default = 1; /* bool */
|
||||
else if (!strcasecmp(value, "auto"))
|
||||
diff_use_color_default = isatty(1);
|
||||
else if (!strcasecmp(value, "auto")) {
|
||||
diff_use_color_default = 0;
|
||||
if (isatty(1)) {
|
||||
char *term = getenv("TERM");
|
||||
if (term && strcmp(term, "dumb"))
|
||||
diff_use_color_default = 1;
|
||||
}
|
||||
}
|
||||
else if (!strcasecmp(value, "never"))
|
||||
diff_use_color_default = 0;
|
||||
else if (!strcasecmp(value, "always"))
|
||||
|
||||
19
exec_cmd.c
19
exec_cmd.c
@@ -1,5 +1,6 @@
|
||||
#include "cache.h"
|
||||
#include "exec_cmd.h"
|
||||
#include "quote.h"
|
||||
#define MAX_ARGS 32
|
||||
|
||||
extern char **environ;
|
||||
@@ -96,9 +97,27 @@ int execv_git_cmd(const char **argv)
|
||||
tmp = argv[0];
|
||||
argv[0] = git_command;
|
||||
|
||||
if (getenv("GIT_TRACE")) {
|
||||
const char **p = argv;
|
||||
fputs("trace: exec:", stderr);
|
||||
while (*p) {
|
||||
fputc(' ', stderr);
|
||||
sq_quote_print(stderr, *p);
|
||||
++p;
|
||||
}
|
||||
putc('\n', stderr);
|
||||
fflush(stderr);
|
||||
}
|
||||
|
||||
/* execve() can only ever return if it fails */
|
||||
execve(git_command, (char **)argv, environ);
|
||||
|
||||
if (getenv("GIT_TRACE")) {
|
||||
fprintf(stderr, "trace: exec failed: %s\n",
|
||||
strerror(errno));
|
||||
fflush(stderr);
|
||||
}
|
||||
|
||||
argv[0] = tmp;
|
||||
}
|
||||
return -1;
|
||||
|
||||
@@ -13,7 +13,7 @@ git bisect log show bisect log.'
|
||||
. git-sh-setup
|
||||
|
||||
sq() {
|
||||
perl -e '
|
||||
@@PERL@@ -e '
|
||||
for (@ARGV) {
|
||||
s/'\''/'\'\\\\\'\''/g;
|
||||
print " '\''$_'\''";
|
||||
|
||||
@@ -324,7 +324,7 @@ test -d "$GIT_DIR/refs/reference-tmp" && rm -fr "$GIT_DIR/refs/reference-tmp"
|
||||
if test -f "$GIT_DIR/CLONE_HEAD"
|
||||
then
|
||||
# Read git-fetch-pack -k output and store the remote branches.
|
||||
perl -e "$copy_refs" "$GIT_DIR" "$use_separate_remote" "$origin"
|
||||
@@PERL@@ -e "$copy_refs" "$GIT_DIR" "$use_separate_remote" "$origin"
|
||||
fi
|
||||
|
||||
cd "$D" || exit
|
||||
|
||||
@@ -147,7 +147,7 @@ run_status () {
|
||||
git-ls-files -z --others $option \
|
||||
--exclude-per-directory=.gitignore
|
||||
fi |
|
||||
perl -e '$/ = "\0";
|
||||
@@PERL@@ -e '$/ = "\0";
|
||||
my $shown = 0;
|
||||
while (<>) {
|
||||
chomp;
|
||||
|
||||
@@ -63,15 +63,15 @@ foreach my $p (@commit) {
|
||||
}
|
||||
|
||||
if ($parent) {
|
||||
my $found;
|
||||
# double check that it's a valid parent
|
||||
foreach my $p (@parents) {
|
||||
my $found;
|
||||
if ($p eq $parent) {
|
||||
$found = 1;
|
||||
last;
|
||||
}; # found it
|
||||
die "Did not find $parent in the parents for this commit!";
|
||||
}
|
||||
die "Did not find $parent in the parents for this commit!" if !$found;
|
||||
} else { # we don't have a parent from the cmdline...
|
||||
if (@parents == 1) { # it's safe to get it from the commit
|
||||
$parent = $parents[0];
|
||||
|
||||
@@ -278,7 +278,7 @@ fetch_main () {
|
||||
head="ref: $remote_name"
|
||||
while (expr "z$head" : "zref:" && expr $depth \< $max_depth) >/dev/null
|
||||
do
|
||||
remote_name_quoted=$(perl -e '
|
||||
remote_name_quoted=$(@@PERL@@ -e '
|
||||
my $u = $ARGV[0];
|
||||
$u =~ s/^ref:\s*//;
|
||||
$u =~ s{([^-a-zA-Z0-9/.])}{sprintf"%%%02x",ord($1)}eg;
|
||||
|
||||
@@ -311,7 +311,7 @@ echo "$prev_head" > "$dotest/prev_head"
|
||||
|
||||
msgnum=0
|
||||
for cmt in `git-rev-list --no-merges "$upstream"..ORIG_HEAD \
|
||||
| perl -e 'print reverse <>'`
|
||||
| @@PERL@@ -e 'print reverse <>'`
|
||||
do
|
||||
msgnum=$(($msgnum + 1))
|
||||
echo "$cmt" > "$dotest/cmt.$msgnum"
|
||||
|
||||
25
git.c
25
git.c
@@ -11,6 +11,7 @@
|
||||
#include "git-compat-util.h"
|
||||
#include "exec_cmd.h"
|
||||
#include "cache.h"
|
||||
#include "quote.h"
|
||||
|
||||
#include "builtin.h"
|
||||
|
||||
@@ -120,6 +121,18 @@ static int handle_alias(int *argcp, const char ***argv)
|
||||
if (!strcmp(alias_command, new_argv[0]))
|
||||
die("recursive alias: %s", alias_command);
|
||||
|
||||
if (getenv("GIT_TRACE")) {
|
||||
int i;
|
||||
fprintf(stderr, "trace: alias expansion: %s =>",
|
||||
alias_command);
|
||||
for (i = 0; i < count; ++i) {
|
||||
fputc(' ', stderr);
|
||||
sq_quote_print(stderr, new_argv[i]);
|
||||
}
|
||||
fputc('\n', stderr);
|
||||
fflush(stderr);
|
||||
}
|
||||
|
||||
/* insert after command name */
|
||||
if (*argcp > 1) {
|
||||
new_argv = realloc(new_argv, sizeof(char*) *
|
||||
@@ -202,6 +215,18 @@ static void handle_internal_command(int argc, const char **argv, char **envp)
|
||||
struct cmd_struct *p = commands+i;
|
||||
if (strcmp(p->cmd, cmd))
|
||||
continue;
|
||||
|
||||
if (getenv("GIT_TRACE")) {
|
||||
int i;
|
||||
fprintf(stderr, "trace: built-in: git");
|
||||
for (i = 0; i < argc; ++i) {
|
||||
fputc(' ', stderr);
|
||||
sq_quote_print(stderr, argv[i]);
|
||||
}
|
||||
putc('\n', stderr);
|
||||
fflush(stderr);
|
||||
}
|
||||
|
||||
exit(p->fn(argc, argv, envp));
|
||||
}
|
||||
}
|
||||
|
||||
17
quote.c
17
quote.c
@@ -45,6 +45,23 @@ size_t sq_quote_buf(char *dst, size_t n, const char *src)
|
||||
return len;
|
||||
}
|
||||
|
||||
void sq_quote_print(FILE *stream, const char *src)
|
||||
{
|
||||
char c;
|
||||
|
||||
fputc('\'', stream);
|
||||
while ((c = *src++)) {
|
||||
if (need_bs_quote(c)) {
|
||||
fputs("'\\", stream);
|
||||
fputc(c, stream);
|
||||
fputc('\'', stream);
|
||||
} else {
|
||||
fputc(c, stream);
|
||||
}
|
||||
}
|
||||
fputc('\'', stream);
|
||||
}
|
||||
|
||||
char *sq_quote(const char *src)
|
||||
{
|
||||
char *buf;
|
||||
|
||||
Reference in New Issue
Block a user