From 471efb09aaa266e75e499829fc31a59337ef4a96 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 9 Feb 2007 22:18:19 -0800 Subject: [PATCH 01/13] diff_flush_name(): take struct diff_options parameter. Among the low-level output functions called from flush_one_pair(), this was the only function that did not take (filepair, options) as arguments. Signed-off-by: Junio C Hamano --- diff.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/diff.c b/diff.c index ad476f7c68..22be3f77b5 100644 --- a/diff.c +++ b/diff.c @@ -2191,13 +2191,13 @@ static void diff_flush_raw(struct diff_filepair *p, free((void*)path_two); } -static void diff_flush_name(struct diff_filepair *p, int line_termination) +static void diff_flush_name(struct diff_filepair *p, struct diff_options *opt) { char *path = p->two->path; - if (line_termination) + if (opt->line_termination) path = quote_one(p->two->path); - printf("%s%c", path, line_termination); + printf("%s%c", path, opt->line_termination); if (p->two->path != path) free(path); } @@ -2404,7 +2404,7 @@ static void flush_one_pair(struct diff_filepair *p, struct diff_options *opt) else if (fmt & (DIFF_FORMAT_RAW | DIFF_FORMAT_NAME_STATUS)) diff_flush_raw(p, opt); else if (fmt & DIFF_FORMAT_NAME) - diff_flush_name(p, opt->line_termination); + diff_flush_name(p, opt); } static void show_file_mode_name(const char *newdelete, struct diff_filespec *fs) From f3dd015c9147e3116fc1941d96f4dad38386b1db Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Sat, 10 Feb 2007 19:33:57 -0500 Subject: [PATCH 02/13] Print a sane error message if an alias expands to an invalid git command Signed-off-by: "Theodore Ts'o" Signed-off-by: Junio C Hamano --- git.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/git.c b/git.c index 82a8357272..c43d4ff1fd 100644 --- a/git.c +++ b/git.c @@ -387,8 +387,15 @@ int main(int argc, const char **argv, char **envp) done_alias = 1; } - if (errno == ENOENT) + if (errno == ENOENT) { + if (done_alias) { + fprintf(stderr, "Expansion of alias '%s' failed; " + "'%s' is not a git-command\n", + cmd, argv[0]); + exit(1); + } help_unknown_cmd(cmd); + } fprintf(stderr, "Failed to run command '%s': %s\n", cmd, strerror(errno)); From dfd42a3c6281275b518f10938dcd858558cd82e3 Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Sat, 10 Feb 2007 19:33:58 -0500 Subject: [PATCH 03/13] Allow aliases to expand to shell commands If the alias expansion is prefixed with an exclamation point, treat it as a shell command which is run using system(3). Signed-off-by: "Theodore Ts'o" Signed-off-by: Junio C Hamano --- Documentation/config.txt | 6 ++++++ git.c | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/Documentation/config.txt b/Documentation/config.txt index 4e650af01a..0129b1fd69 100644 --- a/Documentation/config.txt +++ b/Documentation/config.txt @@ -222,6 +222,12 @@ alias.*:: spaces, the usual shell quoting and escaping is supported. quote pair and a backslash can be used to quote them. + If the alias expansion is prefixed with an exclamation point, + it will be treated as a shell command. For example, defining + "alias.new = !gitk --all --not ORIG_HEAD", the invocation + "git new" is equivalent to running the shell command + "gitk --all --not ORIG_HEAD". + apply.whitespace:: Tells `git-apply` how to handle whitespaces, in the same way as the '--whitespace' option. See gitlink:git-apply[1]. diff --git a/git.c b/git.c index c43d4ff1fd..45265f14d0 100644 --- a/git.c +++ b/git.c @@ -159,6 +159,16 @@ static int handle_alias(int *argcp, const char ***argv) alias_command = (*argv)[0]; git_config(git_alias_config); if (alias_string) { + if (alias_string[0] == '!') { + trace_printf("trace: alias to shell cmd: %s => %s\n", + alias_command, alias_string + 1); + ret = system(alias_string + 1); + if (ret >= 0 && WIFEXITED(ret) && + WEXITSTATUS(ret) != 127) + exit(WEXITSTATUS(ret)); + die("Failed to run '%s' when expanding alias '%s'\n", + alias_string + 1, alias_command); + } count = split_cmdline(alias_string, &new_argv); option_count = handle_options(&new_argv, &count); memmove(new_argv - option_count, new_argv, From 7774284ac733fac7a23bff058c949723953ece34 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 10 Feb 2007 21:07:12 -0800 Subject: [PATCH 04/13] git-svn: correctly handle boolean options via git-config We don't append a space after '--bool', so we can't expect a regular expression to match the space. Semi-noticed by Junio C Hamano :) Signed-off-by: Eric Wong Signed-off-by: Junio C Hamano --- git-svn.perl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-svn.perl b/git-svn.perl index 8ebaae9ff8..d792a62d7c 100755 --- a/git-svn.perl +++ b/git-svn.perl @@ -1610,7 +1610,7 @@ sub read_repo_config { @$v = @tmp if @tmp; } else { chomp(my $tmp = `$arg --get svn.$key`); - if ($tmp && !($arg =~ / --bool / && $tmp eq 'false')) { + if ($tmp && !($arg =~ / --bool/ && $tmp eq 'false')) { $$v = $tmp; } } From b4f020c5d0850ff2b6227abebc5ce72cffe8e1c1 Mon Sep 17 00:00:00 2001 From: Mukund Date: Sat, 10 Feb 2007 23:42:01 +0530 Subject: [PATCH 05/13] Fixed some typos in git-repack docs Signed-off-by: Junio C Hamano --- Documentation/git-repack.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Documentation/git-repack.txt b/Documentation/git-repack.txt index 4a57ce8601..d39abc126d 100644 --- a/Documentation/git-repack.txt +++ b/Documentation/git-repack.txt @@ -30,9 +30,9 @@ OPTIONS Instead of incrementally packing the unpacked objects, pack everything available into a single pack. Especially useful when packing a repository that is used - for a private development and there no need to worry - about people fetching via dumb protocols from it. Use - with '-d'. + for private development and there is no need to worry + about people fetching via dumb file transfer protocols + from it. Use with '-d'. -d:: After packing, if the newly created packs make some From 4f75b115d7b997c72f65ae1edc337914ea610b47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=1B=2Cbi=1B=28B=20Scharfe?= Date: Sun, 11 Feb 2007 14:29:58 +0100 Subject: [PATCH 06/13] Avoid ugly linewrap in git help Some of the short help texts that are shown e.g. when running 'git' without any parameters wrap on a 80-column terminal. They are just one character over the line. This patch avoids it by decreasing the number of spaces around the preceding command name from four to three (on both sides for symmetry). Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- help.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/help.c b/help.c index 341b9e370e..b6674635a2 100644 --- a/help.c +++ b/help.c @@ -168,8 +168,8 @@ static void list_common_cmds_help(void) puts("The most commonly used git commands are:"); for (i = 0; i < ARRAY_SIZE(common_cmds); i++) { - printf(" %s", common_cmds[i].name); - mput_char(' ', longest - strlen(common_cmds[i].name) + 4); + printf(" %s ", common_cmds[i].name); + mput_char(' ', longest - strlen(common_cmds[i].name)); puts(common_cmds[i].help); } puts("(use 'git help -a' to get a list of all installed git commands)"); From 1187d7564d67b532df402050711cb494ceaec2f9 Mon Sep 17 00:00:00 2001 From: Dotan Barak Date: Sun, 11 Feb 2007 17:54:40 +0200 Subject: [PATCH 07/13] Make it easier to override path to asciidoc command Allow setting the path of asciidoc in only one place when creating the documentation. Signed-off-by: Dotan Barak Signed-off-by: Junio C Hamano --- Documentation/Makefile | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/Documentation/Makefile b/Documentation/Makefile index 266af47176..aaf95918c3 100644 --- a/Documentation/Makefile +++ b/Documentation/Makefile @@ -31,6 +31,7 @@ man1dir=$(mandir)/man1 man7dir=$(mandir)/man7 # DESTDIR= +ASCIIDOC=asciidoc INSTALL?=install DOC_REF = origin/man @@ -91,16 +92,16 @@ clean: rm -f $(cmds_txt) %.html : %.txt - asciidoc -b xhtml11 -d manpage -f asciidoc.conf $< + $(ASCIIDOC) -b xhtml11 -d manpage -f asciidoc.conf $< %.1 %.7 : %.xml xmlto -m callouts.xsl man $< %.xml : %.txt - asciidoc -b docbook -d manpage -f asciidoc.conf $< + $(ASCIIDOC) -b docbook -d manpage -f asciidoc.conf $< user-manual.xml: user-manual.txt user-manual.conf - asciidoc -b docbook -d book $< + $(ASCIIDOC) -b docbook -d book $< user-manual.html: user-manual.xml xmlto html-nochunks $< @@ -108,7 +109,7 @@ user-manual.html: user-manual.xml glossary.html : glossary.txt sort_glossary.pl cat $< | \ perl sort_glossary.pl | \ - asciidoc -b xhtml11 - > glossary.html + $(ASCIIDOC) -b xhtml11 - > glossary.html howto-index.txt: howto-index.sh $(wildcard howto/*.txt) rm -f $@+ $@ @@ -116,13 +117,13 @@ howto-index.txt: howto-index.sh $(wildcard howto/*.txt) mv $@+ $@ $(patsubst %,%.html,$(ARTICLES)) : %.html : %.txt - asciidoc -b xhtml11 $*.txt + $(ASCIIDOC) -b xhtml11 $*.txt WEBDOC_DEST = /pub/software/scm/git/docs $(patsubst %.txt,%.html,$(wildcard howto/*.txt)): %.html : %.txt rm -f $@+ $@ - sed -e '1,/^$$/d' $< | asciidoc -b xhtml11 - >$@+ + sed -e '1,/^$$/d' $< | $(ASCIIDOC) -b xhtml11 - >$@+ mv $@+ $@ install-webdoc : html From b9f441646c5c8abb92dc110d28decdfe2c9720b2 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Sat, 10 Feb 2007 15:36:47 +0100 Subject: [PATCH 08/13] diff.c: Reuse the pprint_rename function for diff --summary output. This avoids some code duplication, and yields more readable results for directory renames. Signed-off-by: Alexandre Julliard Signed-off-by: Junio C Hamano --- diff.c | 31 ++++--------------------------- 1 file changed, 4 insertions(+), 27 deletions(-) diff --git a/diff.c b/diff.c index 22be3f77b5..acd689643c 100644 --- a/diff.c +++ b/diff.c @@ -2430,34 +2430,11 @@ static void show_mode_change(struct diff_filepair *p, int show_name) static void show_rename_copy(const char *renamecopy, struct diff_filepair *p) { - const char *old, *new; + char *names = pprint_rename(p->one->path, p->two->path); - /* Find common prefix */ - old = p->one->path; - new = p->two->path; - while (1) { - const char *slash_old, *slash_new; - slash_old = strchr(old, '/'); - slash_new = strchr(new, '/'); - if (!slash_old || - !slash_new || - slash_old - old != slash_new - new || - memcmp(old, new, slash_new - new)) - break; - old = slash_old + 1; - new = slash_new + 1; - } - /* p->one->path thru old is the common prefix, and old and new - * through the end of names are renames - */ - if (old != p->one->path) - printf(" %s %.*s{%s => %s} (%d%%)\n", renamecopy, - (int)(old - p->one->path), p->one->path, - old, new, (int)(0.5 + p->score * 100.0/MAX_SCORE)); - else - printf(" %s %s => %s (%d%%)\n", renamecopy, - p->one->path, p->two->path, - (int)(0.5 + p->score * 100.0/MAX_SCORE)); + printf(" %s %s (%d%%)\n", renamecopy, names, + (int)(0.5 + p->score * 100.0/MAX_SCORE)); + free(names); show_mode_change(p, 0); } From 0d26a64ece4d2692463a7bcb5235b75ee2f35ec0 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Sat, 10 Feb 2007 15:37:48 +0100 Subject: [PATCH 09/13] diff.c: Properly quote file names in diff --summary output. Signed-off-by: Alexandre Julliard Signed-off-by: Junio C Hamano --- diff.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/diff.c b/diff.c index acd689643c..14684a5c81 100644 --- a/diff.c +++ b/diff.c @@ -2409,19 +2409,24 @@ static void flush_one_pair(struct diff_filepair *p, struct diff_options *opt) static void show_file_mode_name(const char *newdelete, struct diff_filespec *fs) { + char *name = quote_one(fs->path); if (fs->mode) - printf(" %s mode %06o %s\n", newdelete, fs->mode, fs->path); + printf(" %s mode %06o %s\n", newdelete, fs->mode, name); else - printf(" %s %s\n", newdelete, fs->path); + printf(" %s %s\n", newdelete, name); + free(name); } static void show_mode_change(struct diff_filepair *p, int show_name) { if (p->one->mode && p->two->mode && p->one->mode != p->two->mode) { - if (show_name) + if (show_name) { + char *name = quote_one(p->two->path); printf(" mode change %06o => %06o %s\n", - p->one->mode, p->two->mode, p->two->path); + p->one->mode, p->two->mode, name); + free(name); + } else printf(" mode change %06o => %06o\n", p->one->mode, p->two->mode); @@ -2455,8 +2460,10 @@ static void diff_summary(struct diff_filepair *p) break; default: if (p->score) { - printf(" rewrite %s (%d%%)\n", p->two->path, + char *name = quote_one(p->two->path); + printf(" rewrite %s (%d%%)\n", name, (int)(0.5 + p->score * 100.0/MAX_SCORE)); + free(name); show_mode_change(p, 0); } else show_mode_change(p, 1); break; From e5bfbf9b3ee57292aea95313e8659d26f90f8cc5 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Sat, 10 Feb 2007 15:39:00 +0100 Subject: [PATCH 10/13] diff.c: More logical file name quoting for renames in diffstat. Quote both file names separately when printing a rename, yielding something like "foo" => "bar" instead of the current "foo => bar" Signed-off-by: Alexandre Julliard Signed-off-by: Junio C Hamano --- diff.c | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/diff.c b/diff.c index 14684a5c81..aaab3095a5 100644 --- a/diff.c +++ b/diff.c @@ -545,6 +545,24 @@ static char *pprint_rename(const char *a, const char *b) int pfx_length, sfx_length; int len_a = strlen(a); int len_b = strlen(b); + int qlen_a = quote_c_style(a, NULL, NULL, 0); + int qlen_b = quote_c_style(b, NULL, NULL, 0); + + if (qlen_a || qlen_b) { + if (qlen_a) len_a = qlen_a; + if (qlen_b) len_b = qlen_b; + name = xmalloc( len_a + len_b + 5 ); + if (qlen_a) + quote_c_style(a, name, NULL, 0); + else + memcpy(name, a, len_a); + memcpy(name + len_a, " => ", 4); + if (qlen_b) + quote_c_style(b, name + len_a + 4, NULL, 0); + else + memcpy(name + len_a + 4, b, len_b + 1); + return name; + } /* Find common prefix */ pfx_length = 0; @@ -701,12 +719,14 @@ static void show_stats(struct diffstat_t* data, struct diff_options *options) struct diffstat_file *file = data->files[i]; int change = file->added + file->deleted; - len = quote_c_style(file->name, NULL, NULL, 0); - if (len) { - char *qname = xmalloc(len + 1); - quote_c_style(file->name, qname, NULL, 0); - free(file->name); - file->name = qname; + if (!file->is_renamed) { /* renames are already quoted by pprint_rename */ + len = quote_c_style(file->name, NULL, NULL, 0); + if (len) { + char *qname = xmalloc(len + 1); + quote_c_style(file->name, qname, NULL, 0); + free(file->name); + file->name = qname; + } } len = strlen(file->name); @@ -838,7 +858,7 @@ static void show_numstat(struct diffstat_t* data, struct diff_options *options) printf("-\t-\t"); else printf("%d\t%d\t", file->added, file->deleted); - if (options->line_termination && + if (options->line_termination && !file->is_renamed && quote_c_style(file->name, NULL, NULL, 0)) quote_c_style(file->name, NULL, stdout, 0); else From 788743240e7076a285e226ca230385e041d66db5 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sun, 11 Feb 2007 13:28:42 -0800 Subject: [PATCH 11/13] t4016: test quoting funny pathnames in diff output Signed-off-by: Junio C Hamano --- t/t4016-diff-quote.sh | 66 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100755 t/t4016-diff-quote.sh diff --git a/t/t4016-diff-quote.sh b/t/t4016-diff-quote.sh new file mode 100755 index 0000000000..edde8f5568 --- /dev/null +++ b/t/t4016-diff-quote.sh @@ -0,0 +1,66 @@ +#!/bin/sh +# +# Copyright (c) 2007 Junio C Hamano +# + +test_description='Quoting paths in diff output. +' + +. ./test-lib.sh + +P0='pathname' +P1='pathname with HT' +P2='pathname with SP' +P3='pathname +with LF' + +test_expect_success setup ' + echo P0.0 >"$P0.0" && + echo P0.1 >"$P0.1" && + echo P0.2 >"$P0.2" && + echo P0.3 >"$P0.3" && + echo P1.0 >"$P1.0" && + echo P1.2 >"$P1.2" && + echo P1.3 >"$P1.3" && + git add . && + git commit -m initial && + git mv "$P0.0" "R$P0.0" && + git mv "$P0.1" "R$P1.0" && + git mv "$P0.2" "R$P2.0" && + git mv "$P0.3" "R$P3.0" && + git mv "$P1.0" "R$P0.1" && + git mv "$P1.2" "R$P2.1" && + git mv "$P1.3" "R$P3.1" && + : +' + +cat >expect <<\EOF + rename pathname.1 => "Rpathname\twith HT.0" (100%) + rename pathname.3 => "Rpathname\nwith LF.0" (100%) + rename "pathname\twith HT.3" => "Rpathname\nwith LF.1" (100%) + rename pathname.2 => Rpathname with SP.0 (100%) + rename "pathname\twith HT.2" => Rpathname with SP.1 (100%) + rename pathname.0 => Rpathname.0 (100%) + rename "pathname\twith HT.0" => Rpathname.1 (100%) +EOF +test_expect_success 'git diff --summary -M HEAD' ' + git diff --summary -M HEAD >actual && + diff -u expect actual +' + +cat >expect <<\EOF + pathname.1 => "Rpathname\twith HT.0" | 0 + pathname.3 => "Rpathname\nwith LF.0" | 0 + "pathname\twith HT.3" => "Rpathname\nwith LF.1" | 0 + pathname.2 => Rpathname with SP.0 | 0 + "pathname\twith HT.2" => Rpathname with SP.1 | 0 + pathname.0 => Rpathname.0 | 0 + "pathname\twith HT.0" => Rpathname.1 | 0 + 7 files changed, 0 insertions(+), 0 deletions(-) +EOF +test_expect_success 'git diff --stat -M HEAD' ' + git diff --stat -M HEAD >actual && + diff -u expect actual +' + +test_done From 602598fd5d8f64028f84d2772725c5e3414a112f Mon Sep 17 00:00:00 2001 From: Mark Levedahl Date: Thu, 8 Feb 2007 22:22:24 -0500 Subject: [PATCH 12/13] Make gitk save and restore the user set window position. gitk was saving widget sizes and positions when the main window was destroyed, which is after all child widgets are destroyed. The cure is to trap the WM_DELETE_WINDOW event before the gui is torn down. Also, the saved geometry was captured using "winfo geometry .", rather than "wm geometry ." Under Linux, these two return different answers and the latter one is correct. [jc: credit goes to Brett Schwarz for suggesting the use of "wm protocol"; I also squashed the follow-up patch to remove extraneous -0 from expressions.] Signed-off-by: Mark Levedahl Signed-off-by: Junio C Hamano --- gitk | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/gitk b/gitk index 1c36235bff..df1ce8cbbd 100755 --- a/gitk +++ b/gitk @@ -725,7 +725,7 @@ proc makewindow {} { bind . {incrfont 1} bind . {incrfont -1} bind . {incrfont -1} - bind . {savestuff %W} + wm protocol . WM_DELETE_WINDOW doquit bind . "click %W" bind $fstring dofind bind $sha1entry gotocommit @@ -829,12 +829,12 @@ proc savestuff {w} { puts $f [list set colors $colors] puts $f [list set diffcolors $diffcolors] - puts $f "set geometry(main) [winfo geometry .]" + puts $f "set geometry(main) [wm geometry .]" puts $f "set geometry(topwidth) [winfo width .tf]" puts $f "set geometry(topheight) [winfo height .tf]" - puts $f "set geometry(canv) [expr {[winfo width $canv]-0}]" - puts $f "set geometry(canv2) [expr {[winfo width $canv2]-0}]" - puts $f "set geometry(canv3) [expr {[winfo width $canv3]-0}]" + puts $f "set geometry(canv) [winfo width $canv]" + puts $f "set geometry(canv2) [winfo width $canv2]" + puts $f "set geometry(canv3) [winfo width $canv3]" puts $f "set geometry(botwidth) [winfo width .bleft]" puts $f "set geometry(botheight) [winfo height .bleft]" @@ -5800,6 +5800,7 @@ proc showtag {tag isnew} { proc doquit {} { global stopped set stopped 100 + savestuff . destroy . } From d4144612958c255d273ad1bd1fe33f03c0f67ada Mon Sep 17 00:00:00 2001 From: "Michael S. Tsirkin" Date: Fri, 9 Feb 2007 12:23:23 +0200 Subject: [PATCH 13/13] Document that git-am can read standard input. Signed-off-by: Michael S. Tsirkin Signed-off-by: Junio C Hamano --- Documentation/git-am.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Documentation/git-am.txt b/Documentation/git-am.txt index f7d551e2c7..77ef103b21 100644 --- a/Documentation/git-am.txt +++ b/Documentation/git-am.txt @@ -21,6 +21,10 @@ current branch. OPTIONS ------- +...:: + The list of mailbox files to read patches from. If you do not + supply this argument, reads from the standard input. + --signoff:: Add `Signed-off-by:` line to the commit message, using the committer identity of yourself.