From 114ef90854c395145594974c222a004060b2acd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Steinbrink?= Date: Thu, 28 Aug 2008 04:14:02 +0200 Subject: [PATCH 1/6] for-each-ref: Allow a trailing slash in the patterns MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit More often than not, I end up using something like refs/remotes/ as the pattern for for-each-ref, but that doesn't work, because it expects to see the slash in the ref name right after the matched pattern. So teach it to accept the slash as the final character in the pattern as well. Signed-off-by: Björn Steinbrink Signed-off-by: Junio C Hamano --- builtin-for-each-ref.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/builtin-for-each-ref.c b/builtin-for-each-ref.c index 4d25ec51d0..21e92bbcb5 100644 --- a/builtin-for-each-ref.c +++ b/builtin-for-each-ref.c @@ -652,7 +652,8 @@ static int grab_single_ref(const char *refname, const unsigned char *sha1, int f if ((plen <= namelen) && !strncmp(refname, p, plen) && (refname[plen] == '\0' || - refname[plen] == '/')) + refname[plen] == '/' || + p[plen-1] == '/')) break; if (!fnmatch(p, refname, FNM_PATHNAME)) break; From 441bca0bbc6d80a78ce332ef4fa6225155dfbce6 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Thu, 28 Aug 2008 16:19:08 -0700 Subject: [PATCH 2/6] Fix '--dirstat' with cross-directory renaming The dirstat code depends on the fact that we always generate diffs with the names sorted, since it then just does a single-pass walk-over of the sorted list of names and how many changes there were. The sorting means that all files are nicely grouped by directory. That all works fine. Except when we have rename detection, and suddenly the nicely sorted list of pathnames isn't all that sorted at all. And now the single-pass dirstat walk gets all confused, and you can get results like this: [torvalds@nehalem linux]$ git diff --dirstat=2 -M v2.6.27-rc4..v2.6.27-rc5 3.0% arch/powerpc/configs/ 6.8% arch/arm/configs/ 2.7% arch/powerpc/configs/ 4.2% arch/arm/configs/ 5.6% arch/powerpc/configs/ 8.4% arch/arm/configs/ 5.5% arch/powerpc/configs/ 23.3% arch/arm/configs/ 8.6% arch/powerpc/configs/ 4.0% arch/ 4.4% drivers/usb/musb/ 4.0% drivers/watchdog/ 7.6% drivers/ 3.5% fs/ The trivial fix is to add a sorting pass, fixing it to: [torvalds@nehalem linux]$ git diff --dirstat=2 -M v2.6.27-rc4..v2.6.27-rc5 43.0% arch/arm/configs/ 25.5% arch/powerpc/configs/ 5.3% arch/ 4.4% drivers/usb/musb/ 4.0% drivers/watchdog/ 7.6% drivers/ 3.5% fs/ Spot the difference. In case anybody wonders: it's because of a ton of renames from {include/asm-blackfin => arch/blackfin/include/asm} that just totally messed up the file ordering in between arch/arm and arch/powerpc. Signed-off-by: Linus Torvalds Signed-off-by: Junio C Hamano --- diff.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/diff.c b/diff.c index f70e6b4912..7b4300a74a 100644 --- a/diff.c +++ b/diff.c @@ -1054,6 +1054,13 @@ static long gather_dirstat(FILE *file, struct dirstat_dir *dir, unsigned long ch return this_dir; } +static int dirstat_compare(const void *_a, const void *_b) +{ + const struct dirstat_file *a = _a; + const struct dirstat_file *b = _b; + return strcmp(a->name, b->name); +} + static void show_dirstat(struct diff_options *options) { int i; @@ -1113,6 +1120,7 @@ static void show_dirstat(struct diff_options *options) return; /* Show all directories with more than x% of the changes */ + qsort(dir.files, dir.nr, sizeof(dir.files[0]), dirstat_compare); gather_dirstat(options->file, &dir, changed, "", 0); } From 29f28151c5ac0ed842e9a00438f1930ee4052757 Mon Sep 17 00:00:00 2001 From: Yann Dirson Date: Fri, 29 Aug 2008 00:00:28 +0200 Subject: [PATCH 3/6] Document gitk --argscmd flag. This was part of my original patch, but appears to have been lost. Signed-off-by: Yann Dirson Signed-off-by: Junio C Hamano --- Documentation/gitk.txt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Documentation/gitk.txt b/Documentation/gitk.txt index 6e827cd11c..ae29a00d59 100644 --- a/Documentation/gitk.txt +++ b/Documentation/gitk.txt @@ -49,6 +49,13 @@ frequently used options. the history between two branches (i.e. the HEAD and the MERGE_HEAD) that modify the conflicted files. +--argscmd=:: + Command to be run each time gitk has to determine the list of + to show. The command is expected to print on its standard + output a list of additional revs to be shown, one per line. + Use this instead of explicitly specifying if the set of + commits to show may vary between refreshes. + :: Limit the revisions to show. This can be either a single revision From 0cfeed2e1d320cc76c434e0bfc26d90065754e46 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Wed, 27 Aug 2008 17:20:35 +0200 Subject: [PATCH 4/6] make git-shell paranoid about closed stdin/stdout/stderr It is in general unsafe to start a program with one or more of file descriptors 0/1/2 closed. Karl Chen for example noticed that stat_command does this in order to rename a pipe file descriptor to 0: dup2(from, 0); close(from); ... but if stdin was closed (for example) from == 0, so that dup2(0, 0); close(0); just ends up closing the pipe. Another extremely rare but nasty problem would occur if an "important" file ends up in file descriptor 2, and is corrupted by a call to die(). Fixing this in git was considered to be overkill, so this patch works around it only for git-shell. The fix is simply to open all the "low" descriptors to /dev/null in main. Signed-off-by: Paolo Bonzini Acked-by: Stephen R. van den Berg Signed-off-by: Junio C Hamano --- shell.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/shell.c b/shell.c index 6a48de05ff..ad60200d28 100644 --- a/shell.c +++ b/shell.c @@ -56,6 +56,19 @@ int main(int argc, char **argv) { char *prog; struct commands *cmd; + int devnull_fd; + + /* + * Always open file descriptors 0/1/2 to avoid clobbering files + * in die(). It also avoids not messing up when the pipes are + * dup'ed onto stdin/stdout/stderr in the child processes we spawn. + */ + devnull_fd = open("/dev/null", O_RDWR); + while (devnull_fd >= 0 && devnull_fd <= 2) + devnull_fd = dup(devnull_fd); + if (devnull_fd == -1) + die("opening /dev/null failed (%s)", strerror(errno)); + close (devnull_fd); /* * Special hack to pretend to be a CVS server From d36f8679e94c2a0d4d15d6adcea434634af6d627 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Thu, 28 Aug 2008 20:54:59 -0400 Subject: [PATCH 5/6] pretty=format: respect date format options When running a command like: git log --pretty=format:%ad --date=short the date option was ignored. This patch causes it to use whatever format was specified by --date (or by --relative-date, etc), just as the non-user formats would do. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- Documentation/pretty-formats.txt | 2 +- archive.c | 2 +- builtin-commit.c | 2 +- commit.h | 3 ++- pretty.c | 17 +++++++++++------ t/t6006-rev-list-format.sh | 6 ++++++ 6 files changed, 22 insertions(+), 10 deletions(-) diff --git a/Documentation/pretty-formats.txt b/Documentation/pretty-formats.txt index c11d495771..388d4925e6 100644 --- a/Documentation/pretty-formats.txt +++ b/Documentation/pretty-formats.txt @@ -103,7 +103,7 @@ The placeholders are: - '%an': author name - '%aN': author name (respecting .mailmap) - '%ae': author email -- '%ad': author date +- '%ad': author date (format respects --date= option) - '%aD': author date, RFC2822 style - '%ar': author date, relative - '%at': author date, UNIX timestamp diff --git a/archive.c b/archive.c index 5b40e261f1..e2280df567 100644 --- a/archive.c +++ b/archive.c @@ -48,7 +48,7 @@ static void format_subst(const struct commit *commit, strbuf_add(&fmt, b + 8, c - b - 8); strbuf_add(buf, src, b - src); - format_commit_message(commit, fmt.buf, buf); + format_commit_message(commit, fmt.buf, buf, DATE_NORMAL); len -= c + 1 - src; src = c + 1; } diff --git a/builtin-commit.c b/builtin-commit.c index 649c8beb3e..c870037b07 100644 --- a/builtin-commit.c +++ b/builtin-commit.c @@ -882,7 +882,7 @@ static void print_summary(const char *prefix, const unsigned char *sha1) if (!log_tree_commit(&rev, commit)) { struct strbuf buf = STRBUF_INIT; - format_commit_message(commit, "%h: %s", &buf); + format_commit_message(commit, "%h: %s", &buf, DATE_NORMAL); printf("%s\n", buf.buf); strbuf_release(&buf); } diff --git a/commit.h b/commit.h index 77de9621d9..ecdd5733f9 100644 --- a/commit.h +++ b/commit.h @@ -67,7 +67,8 @@ extern int non_ascii(int); struct rev_info; /* in revision.h, it circularly uses enum cmit_fmt */ extern void get_commit_format(const char *arg, struct rev_info *); extern void format_commit_message(const struct commit *commit, - const void *format, struct strbuf *sb); + const void *format, struct strbuf *sb, + enum date_mode dmode); extern void pretty_print_commit(enum cmit_fmt fmt, const struct commit*, struct strbuf *, int abbrev, const char *subject, diff --git a/pretty.c b/pretty.c index 33ef34a411..a29c290009 100644 --- a/pretty.c +++ b/pretty.c @@ -310,7 +310,7 @@ static int mailmap_name(struct strbuf *sb, const char *email) } static size_t format_person_part(struct strbuf *sb, char part, - const char *msg, int len) + const char *msg, int len, enum date_mode dmode) { /* currently all placeholders have same length */ const int placeholder_len = 2; @@ -377,7 +377,7 @@ static size_t format_person_part(struct strbuf *sb, char part, switch (part) { case 'd': /* date */ - strbuf_addstr(sb, show_date(date, tz, DATE_NORMAL)); + strbuf_addstr(sb, show_date(date, tz, dmode)); return placeholder_len; case 'D': /* date, RFC2822 style */ strbuf_addstr(sb, show_date(date, tz, DATE_RFC2822)); @@ -409,6 +409,7 @@ struct chunk { struct format_commit_context { const struct commit *commit; + enum date_mode dmode; /* These offsets are relative to the start of the commit message. */ int commit_header_parsed; @@ -584,10 +585,12 @@ static size_t format_commit_item(struct strbuf *sb, const char *placeholder, return 1; case 'a': /* author ... */ return format_person_part(sb, placeholder[1], - msg + c->author.off, c->author.len); + msg + c->author.off, c->author.len, + c->dmode); case 'c': /* committer ... */ return format_person_part(sb, placeholder[1], - msg + c->committer.off, c->committer.len); + msg + c->committer.off, c->committer.len, + c->dmode); case 'e': /* encoding */ strbuf_add(sb, msg + c->encoding.off, c->encoding.len); return 1; @@ -599,12 +602,14 @@ static size_t format_commit_item(struct strbuf *sb, const char *placeholder, } void format_commit_message(const struct commit *commit, - const void *format, struct strbuf *sb) + const void *format, struct strbuf *sb, + enum date_mode dmode) { struct format_commit_context context; memset(&context, 0, sizeof(context)); context.commit = commit; + context.dmode = dmode; strbuf_expand(sb, format, format_commit_item, &context); } @@ -770,7 +775,7 @@ void pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit, const char *encoding; if (fmt == CMIT_FMT_USERFORMAT) { - format_commit_message(commit, user_format, sb); + format_commit_message(commit, user_format, sb, dmode); return; } diff --git a/t/t6006-rev-list-format.sh b/t/t6006-rev-list-format.sh index 9176484db2..485ad4d44a 100755 --- a/t/t6006-rev-list-format.sh +++ b/t/t6006-rev-list-format.sh @@ -139,6 +139,12 @@ commit 131a310eb913d107dd3c09a65d1651175898735d commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873 EOF +test_expect_success '%ad respects --date=' ' + echo 2005-04-07 >expect.ad-short && + git log -1 --date=short --pretty=tformat:%ad >output.ad-short master && + test_cmp expect.ad-short output.ad-short +' + test_expect_success 'empty email' ' test_tick && C=$(GIT_AUTHOR_EMAIL= git commit-tree HEAD^{tree} Date: Thu, 28 Aug 2008 14:23:52 +0200 Subject: [PATCH 6/6] tutorial: gentler illustration of Alice/Bob workflow using gitk Update to gitutorial as discussedin the git mailing list: http://marc.info/?t=121969390900002&r=1&w=2 Signed-off-by: Paolo Ciarrocchi Signed-off-by: Junio C Hamano --- Documentation/gittutorial.txt | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/Documentation/gittutorial.txt b/Documentation/gittutorial.txt index 48d1454a90..384972cb9b 100644 --- a/Documentation/gittutorial.txt +++ b/Documentation/gittutorial.txt @@ -321,10 +321,37 @@ pulling, like this: ------------------------------------------------ alice$ git fetch /home/bob/myrepo master -alice$ git log -p ..FETCH_HEAD +alice$ git log -p HEAD..FETCH_HEAD ------------------------------------------------ This operation is safe even if Alice has uncommitted local changes. +The range notation HEAD..FETCH_HEAD" means "show everything that is reachable +from the FETCH_HEAD but exclude anything that is reachable from HEAD. +Alice already knows everything that leads to her current state (HEAD), +and reviewing what Bob has in his state (FETCH_HEAD) that she has not +seen with this command + +If Alice wants to visualize what Bob did since their histories forked +she can issue the following command: + +------------------------------------------------ +$ gitk HEAD..FETCH_HEAD +------------------------------------------------ + +This uses the same two-dot range notation we saw earlier with 'git log'. + +Alice may want to view what both of them did since they forked. +She can use three-dot form instead of the two-dot form: + +------------------------------------------------ +$ gitk HEAD...FETCH_HEAD +------------------------------------------------ + +This means "show everything that is reachable from either one, but +exclude anything that is reachable from both of them". + +Please note that these range notation can be used with both gitk +and "git log". After inspecting what Bob did, if there is nothing urgent, Alice may decide to continue working without pulling from Bob. If Bob's history