From c8c4450e1949055cb57e32425b125f45f3481742 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Tue, 19 Aug 2008 20:42:04 +0200 Subject: [PATCH 01/11] git format-patch: avoid underrun when format.headers is empty or all NLs * builtin-log.c (add_header): Avoid a buffer underrun when format.headers is empty or all newlines. Reproduce with this: git config format.headers '' && git format-patch -1 Signed-off-by: Jim Meyering Signed-off-by: Junio C Hamano --- builtin-log.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builtin-log.c b/builtin-log.c index f4975cf35f..911fd65990 100644 --- a/builtin-log.c +++ b/builtin-log.c @@ -461,7 +461,7 @@ static int extra_cc_alloc; static void add_header(const char *value) { int len = strlen(value); - while (value[len - 1] == '\n') + while (len && value[len - 1] == '\n') len--; if (!strncasecmp(value, "to: ", 4)) { ALLOC_GROW(extra_to, extra_to_nr + 1, extra_to_alloc); From e9d7d10a7f17fb9cc6a4d37b6fdf27170f4deede Mon Sep 17 00:00:00 2001 From: Jeff King Date: Tue, 19 Aug 2008 13:28:24 -0400 Subject: [PATCH 02/11] mailinfo: avoid violating strbuf assertion In handle_from, we calculate the end boundary of a section to remove from a strbuf using strcspn like this: el = strcspn(buf, set_of_end_boundaries); strbuf_remove(&sb, start, el + 1); This works fine if "el" is the offset of the boundary character, meaning we remove up to and including that character. But if the end boundary didn't match (that is, we hit the end of the string as the boundary instead) then we want just "el". Asking for "el+1" caught an out-of-bounds assertion in the strbuf library. This manifested itself when we got a 'From' header that had just an email address with nothing else in it (the end of the string was the end of the address, rather than, e.g., a trailing '>' character), causing git-mailinfo to barf. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- builtin-mailinfo.c | 2 +- t/t5100-mailinfo.sh | 11 +++++++++++ t/t5100/info-from.expect | 5 +++++ t/t5100/info-from.in | 8 ++++++++ 4 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 t/t5100/info-from.expect create mode 100644 t/t5100/info-from.in diff --git a/builtin-mailinfo.c b/builtin-mailinfo.c index 26d3e5d7af..e890f7a6d1 100644 --- a/builtin-mailinfo.c +++ b/builtin-mailinfo.c @@ -107,7 +107,7 @@ static void handle_from(const struct strbuf *from) el = strcspn(at, " \n\t\r\v\f>"); strbuf_reset(&email); strbuf_add(&email, at, el); - strbuf_remove(&f, at - f.buf, el + 1); + strbuf_remove(&f, at - f.buf, el + (at[el] ? 1 : 0)); /* The remainder is name. It could be "John Doe " * or "john.doe@xz (John Doe)", but we have removed the diff --git a/t/t5100-mailinfo.sh b/t/t5100-mailinfo.sh index 8dfaddda91..198e3503d5 100755 --- a/t/t5100-mailinfo.sh +++ b/t/t5100-mailinfo.sh @@ -43,4 +43,15 @@ test_expect_success 'Preserve NULs out of MIME encoded message' ' ' +test_expect_success 'mailinfo on from header without name works' ' + + mkdir info-from && + git mailsplit -oinfo-from "$TEST_DIRECTORY"/t5100/info-from.in && + test_cmp "$TEST_DIRECTORY"/t5100/info-from.in info-from/0001 && + git mailinfo info-from/msg info-from/patch \ + info-from/out && + test_cmp "$TEST_DIRECTORY"/t5100/info-from.expect info-from/out + +' + test_done diff --git a/t/t5100/info-from.expect b/t/t5100/info-from.expect new file mode 100644 index 0000000000..c31d2eb550 --- /dev/null +++ b/t/t5100/info-from.expect @@ -0,0 +1,5 @@ +Author: bare@example.com +Email: bare@example.com +Subject: testing bare address in from header +Date: Sun, 25 May 2008 00:38:18 -0700 + diff --git a/t/t5100/info-from.in b/t/t5100/info-from.in new file mode 100644 index 0000000000..4f082093fc --- /dev/null +++ b/t/t5100/info-from.in @@ -0,0 +1,8 @@ +From 667d8940e719cddee1cfe237cbbe215e20270b09 Mon Sep 17 00:00:00 2001 +From: bare@example.com +Date: Sun, 25 May 2008 00:38:18 -0700 +Subject: [PATCH] testing bare address in from header + +commit message +--- +patch From c71e917975ecd5fdc4caef245cf18b244213e3f6 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Tue, 19 Aug 2008 20:46:30 +0200 Subject: [PATCH 03/11] remote.c: remove useless if-before-free test We removed a handful of these useless if-before-free tests several months ago. This change removes a new one that snuck back in. Signed-off-by: Jim Meyering Signed-off-by: Junio C Hamano --- remote.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/remote.c b/remote.c index f61a3ab399..105668f8a3 100644 --- a/remote.c +++ b/remote.c @@ -579,8 +579,7 @@ int valid_fetch_refspec(const char *fetch_refspec_str) struct refspec *refspec; refspec = parse_refspec_internal(1, fetch_refspec, 1, 1); - if (refspec) - free(refspec); + free(refspec); return !!refspec; } From c35539eb10b0ab2a180e523f03ff65dc061bd47e Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Wed, 20 Aug 2008 11:47:55 -0700 Subject: [PATCH 04/11] diff --check: do not get confused by new blank lines in the middle The code remembered that the last diff output it saw was an empty line, and tried to reset that state whenever it sees a context line, a non-blank new line, or a new hunk. However, this codepath asks the underlying diff engine to feed diff without any context, and the "just saw an empty line" state was not reset if you added a new blank line in the last hunk of your patch, even if it is not the last line of the file. Signed-off-by: Junio C Hamano --- diff.c | 1 + t/t4015-diff-whitespace.sh | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/diff.c b/diff.c index bf5d5f15a3..f70e6b4912 100644 --- a/diff.c +++ b/diff.c @@ -1627,6 +1627,7 @@ static void builtin_checkdiff(const char *name_a, const char *name_b, xdemitcb_t ecb; memset(&xecfg, 0, sizeof(xecfg)); + xecfg.ctxlen = 1; /* at least one context line */ xpp.flags = XDF_NEED_MINIMAL; ecb.outf = xdiff_outf; ecb.priv = &data; diff --git a/t/t4015-diff-whitespace.sh b/t/t4015-diff-whitespace.sh index a27fccc8dc..ec98509fd2 100755 --- a/t/t4015-diff-whitespace.sh +++ b/t/t4015-diff-whitespace.sh @@ -341,4 +341,15 @@ test_expect_success 'checkdiff detects trailing blank lines' ' git diff --check | grep "ends with blank" ' +test_expect_success 'checkdiff allows new blank lines' ' + git checkout x && + mv x y && + ( + echo "/* This is new */" && + echo "" && + cat y + ) >x && + git diff --check +' + test_done From e276c26b4b65711c27e3ef37e732d41eeae42094 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Wed, 20 Aug 2008 12:29:27 -0700 Subject: [PATCH 05/11] for-each-ref: cope with tags with incomplete lines If you have a tag with a single, incomplete line as its payload, asking git-for-each-ref for its %(body) element accessed a NULL pointer. Signed-off-by: Junio C Hamano --- builtin-for-each-ref.c | 4 +++- t/t6300-for-each-ref.sh | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/builtin-for-each-ref.c b/builtin-for-each-ref.c index 445039e19c..4d25ec51d0 100644 --- a/builtin-for-each-ref.c +++ b/builtin-for-each-ref.c @@ -459,8 +459,10 @@ static void find_subpos(const char *buf, unsigned long sz, const char **sub, con return; *sub = buf; /* first non-empty line */ buf = strchr(buf, '\n'); - if (!buf) + if (!buf) { + *body = ""; return; /* no body */ + } while (*buf == '\n') buf++; /* skip blank between subject and body */ *body = buf; diff --git a/t/t6300-for-each-ref.sh b/t/t6300-for-each-ref.sh index a3c8941c72..8ced59321e 100755 --- a/t/t6300-for-each-ref.sh +++ b/t/t6300-for-each-ref.sh @@ -262,4 +262,14 @@ for i in "--perl --shell" "-s --python" "--python --tcl" "--tcl --perl"; do " done +test_expect_success 'an unusual tag with an incomplete line' ' + + git tag -m "bogo" bogo && + bogo=$(git cat-file tag bogo) && + bogo=$(printf "%s" "$bogo" | git mktag) && + git tag -f bogo "$bogo" && + git for-each-ref --format "%(body)" refs/tags/bogo + +' + test_done From 54988bdad7dc3f09e40752221c144bf470d73aa7 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Wed, 20 Aug 2008 13:55:33 -0400 Subject: [PATCH 06/11] decorate: allow const objects to be decorated We don't actually modify the struct object, so there is no reason not to accept const versions (and this allows other callsites, like the next patch, to use the decoration machinery). Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- decorate.c | 11 ++++++----- decorate.h | 6 +++--- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/decorate.c b/decorate.c index d9668d2ef9..82d9e221ea 100644 --- a/decorate.c +++ b/decorate.c @@ -6,13 +6,13 @@ #include "object.h" #include "decorate.h" -static unsigned int hash_obj(struct object *obj, unsigned int n) +static unsigned int hash_obj(const struct object *obj, unsigned int n) { unsigned int hash = *(unsigned int *)obj->sha1; return hash % n; } -static void *insert_decoration(struct decoration *n, struct object *base, void *decoration) +static void *insert_decoration(struct decoration *n, const struct object *base, void *decoration) { int size = n->size; struct object_decoration *hash = n->hash; @@ -44,7 +44,7 @@ static void grow_decoration(struct decoration *n) n->nr = 0; for (i = 0; i < old_size; i++) { - struct object *base = old_hash[i].base; + const struct object *base = old_hash[i].base; void *decoration = old_hash[i].decoration; if (!base) @@ -55,7 +55,8 @@ static void grow_decoration(struct decoration *n) } /* Add a decoration pointer, return any old one */ -void *add_decoration(struct decoration *n, struct object *obj, void *decoration) +void *add_decoration(struct decoration *n, const struct object *obj, + void *decoration) { int nr = n->nr + 1; @@ -65,7 +66,7 @@ void *add_decoration(struct decoration *n, struct object *obj, void *decoration) } /* Lookup a decoration pointer */ -void *lookup_decoration(struct decoration *n, struct object *obj) +void *lookup_decoration(struct decoration *n, const struct object *obj) { int j; diff --git a/decorate.h b/decorate.h index 1fa4ad9beb..e7328044ff 100644 --- a/decorate.h +++ b/decorate.h @@ -2,7 +2,7 @@ #define DECORATE_H struct object_decoration { - struct object *base; + const struct object *base; void *decoration; }; @@ -12,7 +12,7 @@ struct decoration { struct object_decoration *hash; }; -extern void *add_decoration(struct decoration *n, struct object *obj, void *decoration); -extern void *lookup_decoration(struct decoration *n, struct object *obj); +extern void *add_decoration(struct decoration *n, const struct object *obj, void *decoration); +extern void *lookup_decoration(struct decoration *n, const struct object *obj); #endif From 25b3d4d6f39d70c4d46dee48570ae7aeeb4a6b58 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Wed, 20 Aug 2008 14:13:42 -0700 Subject: [PATCH 07/11] completion: find out supported merge strategies correctly "git-merge" is a binary executable these days, and looking for assignment to $all_strategies variable with grep/sed does not work well. When asked for an unknown strategy, pre-1.6.0 and post-1.6.0 "git merge" commands respectively say: $ $HOME/git-snap-v1.5.6.5/bin/git merge -s help available strategies are: recur recursive octopus resolve stupid ours subtree $ $HOME/git-snap-v1.6.0/bin/git merge -s help Could not find merge strategy 'help'. Available strategies are: recursive octopus resolve ours subtree. both on their standard error stream. We can use this to learn what strategies are supported. The sed script is written in such a way that it catches both old and new message styles ("Available" vs "available", and the full stop at the end). It also allows future versions of "git merge" to line-wrap the list of strategies, and add extra comments, like this: $ $HOME/git-snap-v1.6.1/bin/git merge -s help Could not find merge strategy 'help'. Available strategies are: blame recursive octopus resolve ours subtree. Also you have custom strategies: theirs Make sure you spell strategy names correctly. Signed-off-by: Junio C Hamano --- contrib/completion/git-completion.bash | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 158b912841..a31004088a 100755 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -271,15 +271,17 @@ __git_merge_strategies () echo "$__git_merge_strategylist" return fi - sed -n "/^all_strategies='/{ - s/^all_strategies='// - s/'// + git merge -s help 2>&1 | + sed -n -e '/[Aa]vailable strategies are: /,/^$/{ + s/\.$// + s/.*:// + s/^[ ]*// + s/[ ]*$// p - q - }" "$(git --exec-path)/git-merge" + }' } __git_merge_strategylist= -__git_merge_strategylist="$(__git_merge_strategies 2>/dev/null)" +__git_merge_strategylist=$(__git_merge_strategies 2>/dev/null) __git_complete_file () { From 9ca8f6079cdb199851636c719900472a9745885f Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Wed, 20 Aug 2008 15:09:28 -0700 Subject: [PATCH 08/11] "git-merge": allow fast-forwarding in a stat-dirty tree We used to refresh the index to clear stat-dirtyness before a fast-forward merge. Recent C rewrite forgot to do this. Signed-off-by: Junio C Hamano --- builtin-merge.c | 2 +- t/t7600-merge.sh | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/builtin-merge.c b/builtin-merge.c index dde0c7ed33..a201c6628d 100644 --- a/builtin-merge.c +++ b/builtin-merge.c @@ -566,6 +566,7 @@ static int checkout_fast_forward(unsigned char *head, unsigned char *remote) if (read_cache_unmerged()) die("you need to resolve your current index first"); + refresh_cache(REFRESH_QUIET); fd = hold_locked_index(lock_file, 1); @@ -936,7 +937,6 @@ int cmd_merge(int argc, const char **argv, const char *prefix) hex, find_unique_abbrev(remoteheads->item->object.sha1, DEFAULT_ABBREV)); - refresh_cache(REFRESH_QUIET); strbuf_init(&msg, 0); strbuf_addstr(&msg, "Fast forward"); if (have_message) diff --git a/t/t7600-merge.sh b/t/t7600-merge.sh index 5eeb6c2b27..fee8fb77d4 100755 --- a/t/t7600-merge.sh +++ b/t/t7600-merge.sh @@ -488,4 +488,14 @@ test_expect_success 'merge c1 with c1 and c2' ' test_debug 'gitk --all' +test_expect_success 'merge fast-forward in a dirty tree' ' + git reset --hard c0 && + mv file file1 && + cat file1 >file && + rm -f file1 && + git merge c2 +' + +test_debug 'gitk --all' + test_done From 71f463773a310de016da20136fd7160685f97faa Mon Sep 17 00:00:00 2001 From: Johannes Sixt Date: Wed, 20 Aug 2008 17:36:25 +0200 Subject: [PATCH 09/11] Install templates with the user and group of the installing personality If 'make install' was run with sufficient privileges, then the installed templates, which are copied using 'tar', would receive the user and group of whoever built git. This instructs 'tar' to ignore the user and group that are recorded in the archive. Signed-off-by: Johannes Sixt Signed-off-by: Junio C Hamano --- templates/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/Makefile b/templates/Makefile index 9f3f1fc352..cc3fc3094c 100644 --- a/templates/Makefile +++ b/templates/Makefile @@ -48,4 +48,4 @@ clean: install: all $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(template_instdir_SQ)' (cd blt && $(TAR) cf - .) | \ - (cd '$(DESTDIR_SQ)$(template_instdir_SQ)' && umask 022 && $(TAR) xf -) + (cd '$(DESTDIR_SQ)$(template_instdir_SQ)' && umask 022 && $(TAR) xfo -) From 3a634dcf51fb0fbb66b5c9287de08c6230c90903 Mon Sep 17 00:00:00 2001 From: Tarmigan Casebolt Date: Tue, 19 Aug 2008 12:50:31 -0700 Subject: [PATCH 10/11] Add hints to revert documentation about other ways to undo changes Based on its name, people may read the 'git revert' documentation when they want to undo local changes, especially people who have used other SCM's. 'git revert' may not be what they had in mind, but git provides several other ways to undo changes to files. We can help them by pointing them towards the git commands that do what they might want to do. Cc: Daniel Barkalow Cc: Lea Wiemann Signed-off-by: Tarmigan Casebolt Signed-off-by: Junio C Hamano --- Documentation/git-revert.txt | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Documentation/git-revert.txt b/Documentation/git-revert.txt index 98cfa3c0d0..caa07298a6 100644 --- a/Documentation/git-revert.txt +++ b/Documentation/git-revert.txt @@ -15,6 +15,15 @@ Given one existing commit, revert the change the patch introduces, and record a new commit that records it. This requires your working tree to be clean (no modifications from the HEAD commit). +Note: 'git revert' is used to record a new commit to reverse the +effect of an earlier commit (often a faulty one). If you want to +throw away all uncommitted changes in your working directory, you +should see linkgit:git-reset[1], particularly the '--hard' option. If +you want to extract specific files as they were in another commit, you +should see linkgit:git-checkout[1], specifically the 'git checkout + -- ' syntax. Take care with these alternatives as +both will discard uncommitted changes in your working directory. + OPTIONS ------- :: From 9b99e641c11044dba661f574f9098d362a3f0ef8 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Wed, 20 Aug 2008 15:19:00 -0700 Subject: [PATCH 11/11] Update draft release notes for 1.6.0.1 Signed-off-by: Junio C Hamano --- Documentation/RelNotes-1.6.0.1.txt | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/Documentation/RelNotes-1.6.0.1.txt b/Documentation/RelNotes-1.6.0.1.txt index 3ee85a7993..bac117e89d 100644 --- a/Documentation/RelNotes-1.6.0.1.txt +++ b/Documentation/RelNotes-1.6.0.1.txt @@ -4,12 +4,28 @@ GIT v1.6.0.1 Release Notes Fixes since v1.6.0 ------------------ -* ... +* "git diff --check" incorrectly detected new trailing blank lines when + whitespace check was in effect. + +* "git for-each-ref" tried to dereference NULL when asked for '%(body)" on + a tag with a single incomplete line as its payload. + +* "git format-patch" peeked before the beginning of a string when + "format.headers" variable is empty (a misconfiguration). + +* "git mailinfo" (hence "git am") was unhappy when MIME multipart message + contained garbage after the finishing boundary. + +* "git mailinfo" also was unhappy when the "From: " line only had a bare + e-mail address. + +* "git merge" did not refresh the index correctly when a merge resulted in + a fast-forward. Contains other various documentation fixes. -- exec >/var/tmp/1 -O=v1.6.0 +O=v1.6.0-14-g3a634dc echo O=$(git describe maint) git shortlog --no-merges $O..maint