diff options
76 files changed, 1349 insertions, 438 deletions
diff --git a/Documentation/Makefile b/Documentation/Makefile index 551325604e..304b31edee 100644 --- a/Documentation/Makefile +++ b/Documentation/Makefile @@ -46,8 +46,8 @@ MANPAGE_XSL = manpage-normal.xsl XMLTO_EXTRA = INSTALL?=install RM ?= rm -f -DOC_REF = origin/man -HTML_REF = origin/html +MAN_REPO = ../../git-manpages +HTML_REPO = ../../git-htmldocs infodir?=$(prefix)/share/info MAKEINFO=makeinfo @@ -327,12 +327,23 @@ $(patsubst %.txt,%.html,$(wildcard howto/*.txt)): %.html : %.txt install-webdoc : html '$(SHELL_PATH_SQ)' ./install-webdoc.sh $(WEBDOC_DEST) +# You must have a clone of git-htmldocs and git-manpages repositories +# next to the git repository itself for the following to work. + quick-install: quick-install-man -quick-install-man: - '$(SHELL_PATH_SQ)' ./install-doc-quick.sh $(DOC_REF) $(DESTDIR)$(mandir) +require-manrepo:: + @if test ! -d $(MAN_REPO); \ + then echo "git-manpages repository must exist at $(MAN_REPO)"; exit 1; fi + +quick-install-man: require-manrepo + '$(SHELL_PATH_SQ)' ./install-doc-quick.sh $(MAN_REPO) $(DESTDIR)$(mandir) + +require-htmlrepo:: + @if test ! -d $(HTML_REPO); \ + then echo "git-htmldocs repository must exist at $(HTML_REPO)"; exit 1; fi -quick-install-html: - '$(SHELL_PATH_SQ)' ./install-doc-quick.sh $(HTML_REF) $(DESTDIR)$(htmldir) +quick-install-html: require-htmlrepo + '$(SHELL_PATH_SQ)' ./install-doc-quick.sh $(HTML_REPO) $(DESTDIR)$(htmldir) .PHONY: FORCE diff --git a/Documentation/RelNotes/1.7.6.5.txt b/Documentation/RelNotes/1.7.6.5.txt new file mode 100644 index 0000000000..6713132a9e --- /dev/null +++ b/Documentation/RelNotes/1.7.6.5.txt @@ -0,0 +1,26 @@ +Git v1.7.6.5 Release Notes +========================== + +Fixes since v1.7.6.4 +-------------------- + + * The date parser did not accept timezone designators that lack minutes + part and also has a colon between "hh:mm". + + * After fetching from a remote that has very long refname, the reporting + output could have corrupted by overrunning a static buffer. + + * "git mergetool" did not use its arguments as pathspec, but as a path to + the file that may not even have any conflict. + + * "git name-rev --all" tried to name all _objects_, naturally failing to + describe many blobs and trees, instead of showing only commits as + advertised in its documentation. + + * "git remote rename $a $b" were not careful to match the remote name + against $a (i.e. source side of the remote nickname). + + * "gitweb" used to produce a non-working link while showing the contents + of a blob, when JavaScript actions are enabled. + +Also contains minor fixes and documentation updates. diff --git a/Documentation/RelNotes/1.7.7.2.txt b/Documentation/RelNotes/1.7.7.2.txt new file mode 100644 index 0000000000..e6bbef2f01 --- /dev/null +++ b/Documentation/RelNotes/1.7.7.2.txt @@ -0,0 +1,44 @@ +Git v1.7.7.2 Release Notes +========================== + +Fixes since v1.7.7.1 +-------------------- + + * We used to drop error messages from libcurl on certain kinds of + errors. + + * Error report from smart HTTP transport, when the connection was + broken in the middle of a transfer, showed a useless message on + a corrupt packet. + + * "git fetch --prune" was unsafe when used with refspecs from the + command line. + + * The attribute mechanism did not use case insensitive match when + core.ignorecase was set. + + * "git bisect" did not notice when it failed to update the working tree + to the next commit to be tested. + + * "git config --bool --get-regexp" failed to separate the variable name + and its value "true" when the variable is defined without "= true". + + * "git remote rename $a $b" were not careful to match the remote name + against $a (i.e. source side of the remote nickname). + + * "git mergetool" did not use its arguments as pathspec, but as a path to + the file that may not even have any conflict. + + * "git diff --[num]stat" used to use the number of lines of context + different from the default, potentially giving different results from + "git diff | diffstat" and confusing the users. + + * "git pull" and "git rebase" did not work well even when GIT_WORK_TREE is + set correctly with GIT_DIR if the current directory is outside the working + tree. + + * "git send-email" did not honor the configured hostname when restarting + the HELO/EHLO exchange after switching TLS on. + + * "gitweb" used to produce a non-working link while showing the contents + of a blob, when JavaScript actions are enabled. diff --git a/Documentation/RelNotes/1.7.7.3.txt b/Documentation/RelNotes/1.7.7.3.txt new file mode 100644 index 0000000000..09301f0957 --- /dev/null +++ b/Documentation/RelNotes/1.7.7.3.txt @@ -0,0 +1,19 @@ +Git v1.7.7.3 Release Notes +========================== + +Fixes since v1.7.7.2 +-------------------- + + * Adjust the "quick-install-doc" procedures as preformatted + html/manpage are no longer in the source repository. + + * The logic to optimize the locality of the data in a pack introduced in + 1.7.7 was grossly inefficient. + + * The logic to filter out forked projects in the project list in + "gitweb" was broken for some time. + + * "git branch -m/-M" advertised to update RENAME_REF ref in the + commit log message that introduced the feature but not anywhere in + the documentation, and never did update such a ref anyway. This + undocumented misfeature that did not exist has been excised. diff --git a/Documentation/RelNotes/1.7.7.4.txt b/Documentation/RelNotes/1.7.7.4.txt new file mode 100644 index 0000000000..e5234485e7 --- /dev/null +++ b/Documentation/RelNotes/1.7.7.4.txt @@ -0,0 +1,14 @@ +Git v1.7.7.4 Release Notes +========================== + +Fixes since v1.7.7.3 +-------------------- + + * A few header dependencies were missing from the Makefile. + + * Some newer parts of the code used C99 __VA_ARGS__ while we still + try to cater to older compilers. + + * "git name-rev --all" tried to name all _objects_, naturally failing to + describe many blobs and trees, instead of showing only commits as + advertised in its documentation. diff --git a/Documentation/RelNotes/1.7.7.5.txt b/Documentation/RelNotes/1.7.7.5.txt new file mode 100644 index 0000000000..7b0931987b --- /dev/null +++ b/Documentation/RelNotes/1.7.7.5.txt @@ -0,0 +1,14 @@ +Git v1.7.7.5 Release Notes +========================== + +Fixes since v1.7.7.4 +-------------------- + + * After fetching from a remote that has very long refname, the reporting + output could have corrupted by overrunning a static buffer. + + * "git checkout" and "git merge" treated in-tree .gitignore and exclude + file in $GIT_DIR/info/ directory inconsistently when deciding which + untracked files are ignored and expendable. + +Also contains minor fixes and documentation updates. diff --git a/Documentation/RelNotes/1.7.8.txt b/Documentation/RelNotes/1.7.8.txt index 3045245aa6..b4d90bba0f 100644 --- a/Documentation/RelNotes/1.7.8.txt +++ b/Documentation/RelNotes/1.7.8.txt @@ -1,5 +1,5 @@ -Git v1.7.8 Release Notes (draft) -================================ +Git v1.7.8 Release Notes +======================== Updates since v1.7.7 -------------------- @@ -29,7 +29,7 @@ Updates since v1.7.7 files from the index, not from the working tree. * Variants of "git cherry-pick" and "git revert" that take multiple - commits learned to "--continue". + commits learned to "--continue" and "--abort". * "git daemon" gives more human readble error messages to clients using ERR packets when appropriate. @@ -79,6 +79,9 @@ Updates since v1.7.7 * "git ls-remote" learned to respond to "-h"(elp) requests. + * "mediawiki" remote helper can interact with (surprise!) MediaWiki + with "git fetch" & "git push". + * "git merge" learned the "--edit" option to allow users to edit the merge commit log message. @@ -110,9 +113,6 @@ Updates since v1.7.7 between commits in the superproject that has and does not have the submodule in the tree without re-cloning. - * "mediawiki" remote helper can interact with (surprise!) MediaWiki - with "git fetch" & "git push". - * "gitweb" leaked unescaped control characters from syntax hiliter outputs. @@ -131,93 +131,31 @@ Fixes since v1.7.7 Unless otherwise noted, all fixes in the 1.7.7.X maintenance track are included in this release. - * We used to drop error messages from libcurl on certain kinds of - errors. - (merge be22d92eac8 jn/maint-http-error-message later to maint). - - * Error report from smart HTTP transport, when the connection was - broken in the middle of a transfer, showed a useless message on - a corrupt packet. - (merge 6cdf022 sp/smart-http-failure later to maint). - * HTTP transport did not use pushurl correctly, and also did not tell what host it is trying to authenticate with when asking for credentials. (merge deba493 jk/http-auth later to maint). - * "git branch -m/-M" advertised to update RENAME_REF ref in the - commit log message that introduced the feature but not anywhere in - the documentation, and never did update such a ref anyway. This - undocumented misfeature that did not exist has been excised. - (merge b0eab01 jc/maint-remove-renamed-ref later to maint). + * "git blame" was aborted if started from an uncommitted content and + the path had the textconv filter in effect. + (merge 8518088 ss/blame-textconv-fake-working-tree later to maint). * Adding many refs to the local repository in one go (e.g. "git fetch" that fetches many tags) and looking up a ref by name in a repository with too many refs were unnecessarily slow. (merge 17d68a54d jp/get-ref-dir-unsorted later to maint). - * "git fetch --prune" was unsafe when used with refspecs from the - command line. - (merge e8c1e6c cn/fetch-prune later to maint). - * Report from "git commit" on untracked files was confused under core.ignorecase option. - (merge 2548183b jk/name-hash-dirent later to maint). - - * The attribute mechanism did not use case insensitive match when - core.ignorecase was set. - (merge 6eba621 bc/attr-ignore-case later to maint). - - * "git bisect" did not notice when it failed to update the working tree - to the next commit to be tested. - (merge 1acf11717 js/bisect-no-checkout later to maint). - - * "git config --bool --get-regexp" failed to separate the variable name - and its value "true" when the variable is defined without "= true". - (merge 880e3cc mm/maint-config-explicit-bool-display later to maint). - - * "git remote rename $a $b" were not careful to match the remote name - against $a (i.e. source side of the remote nickname). - (merge b52d00aed mz/remote-rename later to maint). - - * "git diff --[num]stat" used to use the number of lines of context - different from the default, potentially giving different results from - "git diff | diffstat" and confusing the users. - (merge f01cae918 jc/maint-diffstat-numstat-context later to maint). + (merge 395c7356 jk/name-hash-dirent later to maint). * "git merge" did not understand ":/<pattern>" as a way to name a commit. - * "git mergetool" learned to use its arguments as pathspec, not a path to - the file that may not even have any conflict. - (merge 6d9990a jm/mergetool-pathspec later to maint). - - * "git pull" and "git rebase" did not work well even when GIT_WORK_TREE is - set correctly with GIT_DIR if the current directory is outside the working - tree. - (merge 035b5bf jk/pull-rebase-with-work-tree later to maint). - " "git push" on the receiving end used to call post-receive and post-update hooks for attempted removal of non-existing refs. (merge 160b81ed ph/push-to-delete-nothing later to maint). - * "git send-email" did not honor the configured hostname when restarting - the HELO/EHLO exchange after switching TLS on. - (merge 155b940 md/smtp-tls-hello-again later to maint). - - * "gitweb" used to produce a non-working link while showing the contents - of a blob, when JavaScript actions are enabled. - (merge 2b07ff3ff ps/gitweb-js-with-lineno later to maint). - - * The logic to filter out forked projects in the project list in - "gitweb" was broken for some time. - (merge 53c632f jm/maint-gitweb-filter-forks-fix later to maint). - - - ---- -exec >/var/tmp/1 -O=v1.7.7.1-453-g0b26d1e -echo O=$(git describe --always master) -git log --first-parent --oneline --reverse ^$O master -echo -git shortlog --no-merges ^$O master + * Help text for "git remote set-url" and "git remote set-branches" + were misspelled. + (merge c49904e fc/remote-seturl-usage-fix later to maint). + (merge 656cdf0 jc/remote-setbranches-usage-fix later to maint). diff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt index 08b581f040..9f7cba2be6 100644 --- a/Documentation/diff-options.txt +++ b/Documentation/diff-options.txt @@ -413,6 +413,7 @@ endif::git-format-patch[] Show whole surrounding functions of changes. ifndef::git-format-patch[] +ifndef::git-log[] --exit-code:: Make the program exit with codes similar to diff(1). That is, it exits with 1 if there were differences and @@ -420,6 +421,7 @@ ifndef::git-format-patch[] --quiet:: Disable all output of the program. Implies `--exit-code`. +endif::git-log[] endif::git-format-patch[] --ext-diff:: diff --git a/Documentation/git-cherry-pick.txt b/Documentation/git-cherry-pick.txt index 2660a842fc..fed5097e00 100644 --- a/Documentation/git-cherry-pick.txt +++ b/Documentation/git-cherry-pick.txt @@ -9,8 +9,9 @@ SYNOPSIS -------- [verse] 'git cherry-pick' [--edit] [-n] [-m parent-number] [-s] [-x] [--ff] <commit>... -'git cherry-pick' --reset 'git cherry-pick' --continue +'git cherry-pick' --quit +'git cherry-pick' --abort DESCRIPTION ----------- diff --git a/Documentation/git-difftool.txt b/Documentation/git-difftool.txt index a03515f1ec..19d473c070 100644 --- a/Documentation/git-difftool.txt +++ b/Documentation/git-difftool.txt @@ -31,7 +31,7 @@ OPTIONS -t <tool>:: --tool=<tool>:: Use the diff tool specified by <tool>. - Valid merge tools are: + Valid diff tools are: araxis, bc3, diffuse, emerge, ecmerge, gvimdiff, kdiff3, kompare, meld, opendiff, p4merge, tkdiff, vimdiff and xxdiff. + diff --git a/Documentation/git-reset.txt b/Documentation/git-reset.txt index b2832fc7eb..b674866e6d 100644 --- a/Documentation/git-reset.txt +++ b/Documentation/git-reset.txt @@ -9,8 +9,8 @@ SYNOPSIS -------- [verse] 'git reset' [-q] [<commit>] [--] <paths>... -'git reset' [--patch|-p] [<commit>] [--] [<paths>...] -'git reset' [--soft | --mixed | --hard | --merge | --keep] [-q] [<commit>] +'git reset' (--patch | -p) [<commit>] [--] [<paths>...] +'git reset' (--soft | --mixed | --hard | --merge | --keep) [-q] [<commit>] DESCRIPTION ----------- @@ -34,7 +34,7 @@ Alternatively, using linkgit:git-checkout[1] and specifying a commit, you can copy the contents of a path out of a commit to the index and to the working tree in one go. -'git reset' --patch|-p [<commit>] [--] [<paths>...]:: +'git reset' (--patch | -p) [<commit>] [--] [<paths>...]:: Interactively select hunks in the difference between the index and <commit> (defaults to HEAD). The chosen hunks are applied in reverse to the index. @@ -43,7 +43,7 @@ This means that `git reset -p` is the opposite of `git add -p`, i.e. you can use it to selectively reset hunks. See the ``Interactive Mode'' section of linkgit:git-add[1] to learn how to operate the `\--patch` mode. -'git reset' [--<mode>] [<commit>]:: +'git reset' --<mode> [<commit>]:: This form resets the current branch head to <commit> and possibly updates the index (resetting it to the tree of <commit>) and the working tree depending on <mode>, which diff --git a/Documentation/git-revert.txt b/Documentation/git-revert.txt index f3519413e7..b699a3458e 100644 --- a/Documentation/git-revert.txt +++ b/Documentation/git-revert.txt @@ -9,8 +9,9 @@ SYNOPSIS -------- [verse] 'git revert' [--edit | --no-edit] [-n] [-m parent-number] [-s] <commit>... -'git revert' --reset 'git revert' --continue +'git revert' --quit +'git revert' --abort DESCRIPTION ----------- diff --git a/Documentation/git-symbolic-ref.txt b/Documentation/git-symbolic-ref.txt index 75b1ae5061..a45d4c4f29 100644 --- a/Documentation/git-symbolic-ref.txt +++ b/Documentation/git-symbolic-ref.txt @@ -43,12 +43,9 @@ In the past, `.git/HEAD` was a symbolic link pointing at `refs/heads/master`. When we wanted to switch to another branch, we did `ln -sf refs/heads/newbranch .git/HEAD`, and when we wanted to find out which branch we are on, we did `readlink .git/HEAD`. -This was fine, and internally that is what still happens by -default, but on platforms that do not have working symlinks, -or that do not have the `readlink(1)` command, this was a bit -cumbersome. On some platforms, `ln -sf` does not even work as -advertised (horrors). Therefore symbolic links are now deprecated -and symbolic refs are used by default. +But symbolic links are not entirely portable, so they are now +deprecated and symbolic refs (as described above) are used by +default. 'git symbolic-ref' will exit with status 0 if the contents of the symbolic ref were printed correctly, with status 1 if the requested diff --git a/Documentation/git.txt b/Documentation/git.txt index 5e80cfd71a..da7d48787e 100644 --- a/Documentation/git.txt +++ b/Documentation/git.txt @@ -44,15 +44,25 @@ unreleased) version of git, that is available from 'master' branch of the `git.git` repository. Documentation for older releases are available here: -* link:v1.7.7.1/git.html[documentation for release 1.7.7.1] +* link:v1.7.8/git.html[documentation for release 1.7.8] * release notes for + link:RelNotes/1.7.8.txt[1.7.8]. + +* link:v1.7.7.5/git.html[documentation for release 1.7.7.5] + +* release notes for + link:RelNotes/1.7.7.5.txt[1.7.7.5], + link:RelNotes/1.7.7.4.txt[1.7.7.4], + link:RelNotes/1.7.7.3.txt[1.7.7.3], + link:RelNotes/1.7.7.2.txt[1.7.7.2], link:RelNotes/1.7.7.1.txt[1.7.7.1], link:RelNotes/1.7.7.txt[1.7.7]. -* link:v1.7.6.4/git.html[documentation for release 1.7.6.4] +* link:v1.7.6.5/git.html[documentation for release 1.7.6.5] * release notes for + link:RelNotes/1.7.6.5.txt[1.7.6.5], link:RelNotes/1.7.6.4.txt[1.7.6.4], link:RelNotes/1.7.6.3.txt[1.7.6.3], link:RelNotes/1.7.6.2.txt[1.7.6.2], diff --git a/Documentation/install-doc-quick.sh b/Documentation/install-doc-quick.sh index 35f440876e..327f69bcf5 100755 --- a/Documentation/install-doc-quick.sh +++ b/Documentation/install-doc-quick.sh @@ -1,31 +1,39 @@ #!/bin/sh -# This requires a branch named in $head -# (usually 'man' or 'html', provided by the git.git repository) -set -e -head="$1" -mandir="$2" -SUBDIRECTORY_OK=t -USAGE='<refname> <target directory>' -. "$(git --exec-path)"/git-sh-setup -cd_to_toplevel +# This requires git-manpages and/or git-htmldocs repositories -test -z "$mandir" && usage -if ! git rev-parse --verify "$head^0" >/dev/null; then - echo >&2 "head: $head does not exist in the current repository" - usage +repository=${1?repository} +destdir=${2?destination} + +head=master GIT_DIR= +for d in "$repository/.git" "$repository" +do + if GIT_DIR="$d" git rev-parse refs/heads/master >/dev/null 2>&1 + then + GIT_DIR="$d" + export GIT_DIR + break + fi +done + +if test -z "$GIT_DIR" +then + echo >&2 "Neither $repository nor $repository/.git is a repository" + exit 1 fi -GIT_INDEX_FILE=`pwd`/.quick-doc.index -export GIT_INDEX_FILE +GIT_WORK_TREE=$(pwd) +GIT_INDEX_FILE=$(pwd)/.quick-doc.$$ +export GIT_INDEX_FILE GIT_WORK_TREE rm -f "$GIT_INDEX_FILE" trap 'rm -f "$GIT_INDEX_FILE"' 0 git read-tree $head -git checkout-index -a -f --prefix="$mandir"/ +git checkout-index -a -f --prefix="$destdir"/ -if test -n "$GZ"; then +if test -n "$GZ" +then git ls-tree -r --name-only $head | - xargs printf "$mandir/%s\n" | + xargs printf "$destdir/%s\n" | xargs gzip -f fi rm -f "$GIT_INDEX_FILE" diff --git a/Documentation/merge-options.txt b/Documentation/merge-options.txt index 6bd0b041c3..1a5c12e317 100644 --- a/Documentation/merge-options.txt +++ b/Documentation/merge-options.txt @@ -9,7 +9,6 @@ inspect and further tweak the merge result before committing. --edit:: -e:: -+ Invoke editor before committing successful merge to further edit the default merge message. diff --git a/Documentation/sequencer.txt b/Documentation/sequencer.txt index 3e6df338be..5747f442f2 100644 --- a/Documentation/sequencer.txt +++ b/Documentation/sequencer.txt @@ -1,9 +1,12 @@ ---reset:: - Forget about the current operation in progress. Can be used - to clear the sequencer state after a failed cherry-pick or - revert. - --continue:: Continue the operation in progress using the information in '.git/sequencer'. Can be used to continue after resolving conflicts in a failed cherry-pick or revert. + +--quit:: + Forget about the current operation in progress. Can be used + to clear the sequencer state after a failed cherry-pick or + revert. + +--abort:: + Cancel the operation and return to the pre-sequence state. diff --git a/GIT-VERSION-GEN b/GIT-VERSION-GEN index 19a142adc2..a04c8f32b7 100755 --- a/GIT-VERSION-GEN +++ b/GIT-VERSION-GEN @@ -1,7 +1,7 @@ #!/bin/sh GVF=GIT-VERSION-FILE -DEF_VER=v1.7.7.GIT +DEF_VER=v1.7.8 LF=' ' @@ -139,34 +139,11 @@ Issues of note: uses some compatibility wrappers to work on AsciiDoc 8. If you have AsciiDoc 7, try "make ASCIIDOC7=YesPlease". - Alternatively, pre-formatted documentation is available in - "html" and "man" branches of the git repository itself. For - example, you could: - - $ mkdir manual && cd manual - $ git init - $ git fetch-pack git://git.kernel.org/pub/scm/git/git.git man html | - while read a b - do - echo $a >.git/$b - done - $ cp .git/refs/heads/man .git/refs/heads/master - $ git checkout - - to checkout the pre-built man pages. Also in this repository: - - $ git checkout html - - would instead give you a copy of what you see at: - - http://www.kernel.org/pub/software/scm/git/docs/ - There are also "make quick-install-doc", "make quick-install-man" and "make quick-install-html" which install preformatted man pages - and html documentation. - This does not require asciidoc/xmlto, but it only works from within - a cloned checkout of git.git with these two extra branches, and will - not work for the maintainer for obvious chicken-and-egg reasons. + and html documentation. To use these build targets, you need to + clone two separate git-htmldocs and git-manpages repositories next + to the clone of git itself. It has been reported that docbook-xsl version 1.72 and 1.73 are buggy; 1.72 misformats manual pages for callouts, and 1.73 needs @@ -250,6 +250,12 @@ all:: # DEFAULT_EDITOR='$GIT_FALLBACK_EDITOR', # DEFAULT_EDITOR='"C:\Program Files\Vim\gvim.exe" --nofork' # +# Define COMPUTE_HEADER_DEPENDENCIES to "yes" if you want dependencies on +# header files to be automatically computed, to avoid rebuilding objects when +# an unrelated header file changes. Define it to "no" to use the hard-coded +# dependency rules. The default is "auto", which means to use computed header +# dependencies if your compiler is detected to support it. +# # Define CHECK_HEADER_DEPENDENCIES to check for problems in the hard-coded # dependency rules. # @@ -515,9 +521,10 @@ LIB_H += compat/mingw.h LIB_H += compat/obstack.h LIB_H += compat/win32/pthread.h LIB_H += compat/win32/syslog.h -LIB_H += compat/win32/sys/poll.h +LIB_H += compat/win32/poll.h LIB_H += compat/win32/dirent.h LIB_H += connected.h +LIB_H += convert.h LIB_H += csum-file.h LIB_H += decorate.h LIB_H += delta.h @@ -1088,6 +1095,7 @@ ifeq ($(uname_S),Windows) NO_PREAD = YesPlease NEEDS_CRYPTO_WITH_SSL = YesPlease NO_LIBGEN_H = YesPlease + NO_SYS_POLL_H = YesPlease NO_SYMLINK_HEAD = YesPlease NO_IPV6 = YesPlease NO_SETENV = YesPlease @@ -1126,7 +1134,7 @@ ifeq ($(uname_S),Windows) BASIC_CFLAGS = -nologo -I. -I../zlib -Icompat/vcbuild -Icompat/vcbuild/include -DWIN32 -D_CONSOLE -DHAVE_STRING_H -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_DEPRECATE COMPAT_OBJS = compat/msvc.o compat/winansi.o \ compat/win32/pthread.o compat/win32/syslog.o \ - compat/win32/sys/poll.o compat/win32/dirent.o + compat/win32/poll.o compat/win32/dirent.o COMPAT_CFLAGS = -D__USE_MINGW_ACCESS -DNOGDI -DHAVE_STRING_H -DHAVE_ALLOCA_H -Icompat -Icompat/regex -Icompat/win32 -DSTRIP_EXTENSION=\".exe\" BASIC_LDFLAGS = -IGNORE:4217 -IGNORE:4049 -NOLOGO -SUBSYSTEM:CONSOLE -NODEFAULTLIB:MSVCRT.lib EXTLIBS = user32.lib advapi32.lib shell32.lib wininet.lib ws2_32.lib @@ -1181,6 +1189,7 @@ ifneq (,$(findstring MINGW,$(uname_S))) NO_PREAD = YesPlease NEEDS_CRYPTO_WITH_SSL = YesPlease NO_LIBGEN_H = YesPlease + NO_SYS_POLL_H = YesPlease NO_SYMLINK_HEAD = YesPlease NO_SETENV = YesPlease NO_UNSETENV = YesPlease @@ -1214,7 +1223,7 @@ ifneq (,$(findstring MINGW,$(uname_S))) COMPAT_CFLAGS += -DSTRIP_EXTENSION=\".exe\" COMPAT_OBJS += compat/mingw.o compat/winansi.o \ compat/win32/pthread.o compat/win32/syslog.o \ - compat/win32/sys/poll.o compat/win32/dirent.o + compat/win32/poll.o compat/win32/dirent.o EXTLIBS += -lws2_32 PTHREAD_LIBS = X = .exe @@ -1243,21 +1252,32 @@ endif endif ifdef CHECK_HEADER_DEPENDENCIES -COMPUTE_HEADER_DEPENDENCIES = +COMPUTE_HEADER_DEPENDENCIES = no USE_COMPUTED_HEADER_DEPENDENCIES = -else +endif + ifndef COMPUTE_HEADER_DEPENDENCIES +COMPUTE_HEADER_DEPENDENCIES = auto +endif + +ifeq ($(COMPUTE_HEADER_DEPENDENCIES),auto) dep_check = $(shell $(CC) $(ALL_CFLAGS) \ -c -MF /dev/null -MMD -MP -x c /dev/null -o /dev/null 2>&1; \ echo $$?) ifeq ($(dep_check),0) -COMPUTE_HEADER_DEPENDENCIES=YesPlease -endif +override COMPUTE_HEADER_DEPENDENCIES = yes +else +override COMPUTE_HEADER_DEPENDENCIES = no endif endif -ifdef COMPUTE_HEADER_DEPENDENCIES +ifeq ($(COMPUTE_HEADER_DEPENDENCIES),yes) USE_COMPUTED_HEADER_DEPENDENCIES = YesPlease +else +ifneq ($(COMPUTE_HEADER_DEPENDENCIES),no) +$(error please set COMPUTE_HEADER_DEPENDENCIES to yes, no, or auto \ +(not "$(COMPUTE_HEADER_DEPENDENCIES)")) +endif endif ifdef SANE_TOOL_PATH @@ -1904,7 +1924,7 @@ OBJECTS := $(GIT_OBJS) $(XDIFF_OBJS) $(VCSSVN_OBJS) dep_files := $(foreach f,$(OBJECTS),$(dir $f).depend/$(notdir $f).d) dep_dirs := $(addsuffix .depend,$(sort $(dir $(OBJECTS)))) -ifdef COMPUTE_HEADER_DEPENDENCIES +ifeq ($(COMPUTE_HEADER_DEPENDENCIES),yes) $(dep_dirs): @mkdir -p $@ @@ -1917,7 +1937,7 @@ Please unset CHECK_HEADER_DEPENDENCIES and try again) endif endif -ifndef COMPUTE_HEADER_DEPENDENCIES +ifneq ($(COMPUTE_HEADER_DEPENDENCIES),yes) ifndef CHECK_HEADER_DEPENDENCIES dep_dirs = missing_dep_dirs = @@ -2007,13 +2027,13 @@ builtin/branch.o builtin/checkout.o builtin/clone.o builtin/reset.o branch.o tra builtin/bundle.o bundle.o transport.o: bundle.h builtin/bisect--helper.o builtin/rev-list.o bisect.o: bisect.h builtin/clone.o builtin/fetch-pack.o transport.o: fetch-pack.h -builtin/grep.o builtin/pack-objects.o transport-helper.o: thread-utils.h +builtin/grep.o builtin/pack-objects.o transport-helper.o thread-utils.o: thread-utils.h builtin/send-pack.o transport.o: send-pack.h builtin/log.o builtin/shortlog.o: shortlog.h builtin/prune.o builtin/reflog.o reachable.o: reachable.h builtin/commit.o builtin/revert.o wt-status.o: wt-status.h builtin/tar-tree.o archive-tar.o: tar.h -connect.o transport.o http-backend.o: url.h +connect.o transport.o url.o http-backend.o: url.h http-fetch.o http-walker.o remote-curl.o transport.o walker.o: walker.h http.o http-walker.o http-push.o http-fetch.o remote-curl.o: http.h url.h @@ -241,6 +241,7 @@ void create_branch(const char *head, void remove_branch_state(void) { unlink(git_path("CHERRY_PICK_HEAD")); + unlink(git_path("REVERT_HEAD")); unlink(git_path("MERGE_HEAD")); unlink(git_path("MERGE_RR")); unlink(git_path("MERGE_MSG")); diff --git a/builtin/apply.c b/builtin/apply.c index 84a8a0b521..b3b59db534 100644 --- a/builtin/apply.c +++ b/builtin/apply.c @@ -250,9 +250,6 @@ static int fuzzy_matchlines(const char *s1, size_t n1, const char *last2 = s2 + n2 - 1; int result = 0; - if (n1 < 0 || n2 < 0) - return 0; - /* ignore line endings */ while ((*last1 == '\r') || (*last1 == '\n')) last1--; diff --git a/builtin/blame.c b/builtin/blame.c index 26a5d424b8..5a67c202f0 100644 --- a/builtin/blame.c +++ b/builtin/blame.c @@ -1598,7 +1598,7 @@ static const char *format_time(unsigned long time, const char *tz_str, int tz; if (show_raw_time) { - sprintf(time_buf, "%lu %s", time, tz_str); + snprintf(time_buf, sizeof(time_buf), "%lu %s", time, tz_str); } else { tz = atoi(tz_str); @@ -2096,6 +2096,7 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt, if (!contents_from || strcmp("-", contents_from)) { struct stat st; const char *read_from; + char *buf_ptr; unsigned long buf_len; if (contents_from) { @@ -2113,8 +2114,8 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt, switch (st.st_mode & S_IFMT) { case S_IFREG: if (DIFF_OPT_TST(opt, ALLOW_TEXTCONV) && - textconv_object(read_from, mode, null_sha1, &buf.buf, &buf_len)) - buf.len = buf_len; + textconv_object(read_from, mode, null_sha1, &buf_ptr, &buf_len)) + strbuf_attach(&buf, buf_ptr, buf_len, buf_len + 1); else if (strbuf_read_file(&buf, read_from, st.st_size) != st.st_size) die_errno("cannot open or read '%s'", read_from); break; diff --git a/builtin/branch.c b/builtin/branch.c index 009b7138ac..55cad766c7 100644 --- a/builtin/branch.c +++ b/builtin/branch.c @@ -705,7 +705,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix) argc = parse_options(argc, argv, prefix, options, builtin_branch_usage, 0); - if (!delete && !rename && !force_create && argc == 0) + if (!delete && !rename && argc == 0) list = 1; if (!!delete + !!rename + !!force_create + !!list > 1) @@ -719,11 +719,14 @@ int cmd_branch(int argc, const char **argv, const char *prefix) else if (list) return print_ref_list(kinds, detached, verbose, abbrev, with_commit, argv); - else if (rename && (argc == 1)) - rename_branch(head, argv[0], rename > 1); - else if (rename && (argc == 2)) - rename_branch(argv[0], argv[1], rename > 1); - else if (argc <= 2) { + else if (rename) { + if (argc == 1) + rename_branch(head, argv[0], rename > 1); + else if (argc == 2) + rename_branch(argv[0], argv[1], rename > 1); + else + usage_with_options(builtin_branch_usage, options); + } else if (argc > 0 && argc <= 2) { if (kinds != REF_LOCAL_BRANCH) die(_("-a and -r options to 'git branch' do not make sense with a branch name")); create_branch(head, argv[0], (argc == 2) ? argv[1] : head, diff --git a/builtin/checkout.c b/builtin/checkout.c index 2a80772425..51840b9784 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -411,7 +411,7 @@ static int merge_working_tree(struct checkout_opts *opts, topts.fn = twoway_merge; topts.dir = xcalloc(1, sizeof(*topts.dir)); topts.dir->flags |= DIR_SHOW_IGNORED; - topts.dir->exclude_per_dir = ".gitignore"; + setup_standard_excludes(topts.dir); tree = parse_tree_indirect(old->commit ? old->commit->object.sha1 : EMPTY_TREE_SHA1_BIN); diff --git a/builtin/clone.c b/builtin/clone.c index 488f48e9a5..efe8b6cce5 100644 --- a/builtin/clone.c +++ b/builtin/clone.c @@ -577,9 +577,9 @@ int cmd_clone(int argc, const char **argv, const char *prefix) if (0 <= option_verbosity) { if (option_bare) - printf(_("Cloning into bare repository %s...\n"), dir); + printf(_("Cloning into bare repository '%s'...\n"), dir); else - printf(_("Cloning into %s...\n"), dir); + printf(_("Cloning into '%s'...\n"), dir); } init_db(option_template, INIT_DB_QUIET); write_config(&option_config); diff --git a/builtin/commit.c b/builtin/commit.c index c46f2d18e1..8f2bebecf3 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -1514,6 +1514,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix) } unlink(git_path("CHERRY_PICK_HEAD")); + unlink(git_path("REVERT_HEAD")); unlink(git_path("MERGE_HEAD")); unlink(git_path("MERGE_MSG")); unlink(git_path("MERGE_MODE")); diff --git a/builtin/diff.c b/builtin/diff.c index 1118689fb2..0fe638fc45 100644 --- a/builtin/diff.c +++ b/builtin/diff.c @@ -182,7 +182,7 @@ static int builtin_diff_combined(struct rev_info *revs, hashcpy((unsigned char *)(parent + i), ent[i].item->sha1); diff_tree_combined(parent[0], parent + 1, ents - 1, revs->dense_combined_merges, revs); - free(parent); + free((void *)parent); return 0; } diff --git a/builtin/fetch.c b/builtin/fetch.c index 91731b909a..8761a33b49 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -240,23 +240,23 @@ static int s_update_ref(const char *action, static int update_local_ref(struct ref *ref, const char *remote, - char *display) + struct strbuf *display) { struct commit *current = NULL, *updated; enum object_type type; struct branch *current_branch = branch_get(NULL); const char *pretty_ref = prettify_refname(ref->name); - *display = 0; type = sha1_object_info(ref->new_sha1, NULL); if (type < 0) die(_("object %s not found"), sha1_to_hex(ref->new_sha1)); if (!hashcmp(ref->old_sha1, ref->new_sha1)) { if (verbosity > 0) - sprintf(display, "= %-*s %-*s -> %s", TRANSPORT_SUMMARY_WIDTH, - _("[up to date]"), REFCOL_WIDTH, remote, - pretty_ref); + strbuf_addf(display, "= %-*s %-*s -> %s", + TRANSPORT_SUMMARY_WIDTH, + _("[up to date]"), REFCOL_WIDTH, + remote, pretty_ref); return 0; } @@ -268,9 +268,10 @@ static int update_local_ref(struct ref *ref, * If this is the head, and it's not okay to update * the head, and the old value of the head isn't empty... */ - sprintf(display, _("! %-*s %-*s -> %s (can't fetch in current branch)"), - TRANSPORT_SUMMARY_WIDTH, _("[rejected]"), REFCOL_WIDTH, remote, - pretty_ref); + strbuf_addf(display, + _("! %-*s %-*s -> %s (can't fetch in current branch)"), + TRANSPORT_SUMMARY_WIDTH, _("[rejected]"), + REFCOL_WIDTH, remote, pretty_ref); return 1; } @@ -278,9 +279,11 @@ static int update_local_ref(struct ref *ref, !prefixcmp(ref->name, "refs/tags/")) { int r; r = s_update_ref("updating tag", ref, 0); - sprintf(display, "%c %-*s %-*s -> %s%s", r ? '!' : '-', - TRANSPORT_SUMMARY_WIDTH, _("[tag update]"), REFCOL_WIDTH, remote, - pretty_ref, r ? _(" (unable to update local ref)") : ""); + strbuf_addf(display, "%c %-*s %-*s -> %s%s", + r ? '!' : '-', + TRANSPORT_SUMMARY_WIDTH, _("[tag update]"), + REFCOL_WIDTH, remote, pretty_ref, + r ? _(" (unable to update local ref)") : ""); return r; } @@ -303,9 +306,11 @@ static int update_local_ref(struct ref *ref, } r = s_update_ref(msg, ref, 0); - sprintf(display, "%c %-*s %-*s -> %s%s", r ? '!' : '*', - TRANSPORT_SUMMARY_WIDTH, what, REFCOL_WIDTH, remote, pretty_ref, - r ? _(" (unable to update local ref)") : ""); + strbuf_addf(display, "%c %-*s %-*s -> %s%s", + r ? '!' : '*', + TRANSPORT_SUMMARY_WIDTH, what, + REFCOL_WIDTH, remote, pretty_ref, + r ? _(" (unable to update local ref)") : ""); return r; } @@ -319,9 +324,11 @@ static int update_local_ref(struct ref *ref, (recurse_submodules != RECURSE_SUBMODULES_ON)) check_for_new_submodule_commits(ref->new_sha1); r = s_update_ref("fast-forward", ref, 1); - sprintf(display, "%c %-*s %-*s -> %s%s", r ? '!' : ' ', - TRANSPORT_SUMMARY_WIDTH, quickref, REFCOL_WIDTH, remote, - pretty_ref, r ? _(" (unable to update local ref)") : ""); + strbuf_addf(display, "%c %-*s %-*s -> %s%s", + r ? '!' : ' ', + TRANSPORT_SUMMARY_WIDTH, quickref, + REFCOL_WIDTH, remote, pretty_ref, + r ? _(" (unable to update local ref)") : ""); return r; } else if (force || ref->force) { char quickref[84]; @@ -333,15 +340,17 @@ static int update_local_ref(struct ref *ref, (recurse_submodules != RECURSE_SUBMODULES_ON)) check_for_new_submodule_commits(ref->new_sha1); r = s_update_ref("forced-update", ref, 1); - sprintf(display, "%c %-*s %-*s -> %s (%s)", r ? '!' : '+', - TRANSPORT_SUMMARY_WIDTH, quickref, REFCOL_WIDTH, remote, - pretty_ref, - r ? _("unable to update local ref") : _("forced update")); + strbuf_addf(display, "%c %-*s %-*s -> %s (%s)", + r ? '!' : '+', + TRANSPORT_SUMMARY_WIDTH, quickref, + REFCOL_WIDTH, remote, pretty_ref, + r ? _("unable to update local ref") : _("forced update")); return r; } else { - sprintf(display, "! %-*s %-*s -> %s %s", - TRANSPORT_SUMMARY_WIDTH, _("[rejected]"), REFCOL_WIDTH, remote, - pretty_ref, _("(non-fast-forward)")); + strbuf_addf(display, "! %-*s %-*s -> %s %s", + TRANSPORT_SUMMARY_WIDTH, _("[rejected]"), + REFCOL_WIDTH, remote, pretty_ref, + _("(non-fast-forward)")); return 1; } } @@ -363,8 +372,8 @@ static int store_updated_refs(const char *raw_url, const char *remote_name, { FILE *fp; struct commit *commit; - int url_len, i, note_len, shown_url = 0, rc = 0; - char note[1024]; + int url_len, i, shown_url = 0, rc = 0; + struct strbuf note = STRBUF_INIT; const char *what, *kind; struct ref *rm; char *url, *filename = dry_run ? "/dev/null" : git_path("FETCH_HEAD"); @@ -427,19 +436,17 @@ static int store_updated_refs(const char *raw_url, const char *remote_name, if (4 < i && !strncmp(".git", url + i - 3, 4)) url_len = i - 3; - note_len = 0; + strbuf_reset(¬e); if (*what) { if (*kind) - note_len += sprintf(note + note_len, "%s ", - kind); - note_len += sprintf(note + note_len, "'%s' of ", what); + strbuf_addf(¬e, "%s ", kind); + strbuf_addf(¬e, "'%s' of ", what); } - note[note_len] = '\0'; fprintf(fp, "%s\t%s\t%s", sha1_to_hex(commit ? commit->object.sha1 : rm->old_sha1), rm->merge ? "" : "not-for-merge", - note); + note.buf); for (i = 0; i < url_len; ++i) if ('\n' == url[i]) fputs("\\n", fp); @@ -447,21 +454,24 @@ static int store_updated_refs(const char *raw_url, const char *remote_name, fputc(url[i], fp); fputc('\n', fp); + strbuf_reset(¬e); if (ref) { - rc |= update_local_ref(ref, what, note); + rc |= update_local_ref(ref, what, ¬e); free(ref); } else - sprintf(note, "* %-*s %-*s -> FETCH_HEAD", - TRANSPORT_SUMMARY_WIDTH, *kind ? kind : "branch", - REFCOL_WIDTH, *what ? what : "HEAD"); - if (*note) { + strbuf_addf(¬e, "* %-*s %-*s -> FETCH_HEAD", + TRANSPORT_SUMMARY_WIDTH, + *kind ? kind : "branch", + REFCOL_WIDTH, + *what ? what : "HEAD"); + if (note.len) { if (verbosity >= 0 && !shown_url) { fprintf(stderr, _("From %.*s\n"), url_len, url); shown_url = 1; } if (verbosity >= 0) - fprintf(stderr, " %s\n", note); + fprintf(stderr, " %s\n", note.buf); } } @@ -471,6 +481,7 @@ static int store_updated_refs(const char *raw_url, const char *remote_name, "branches"), remote_name); abort: + strbuf_release(¬e); free(url); fclose(fp); return rc; diff --git a/builtin/grep.c b/builtin/grep.c index 2fc51fa2dc..988ea1d332 100644 --- a/builtin/grep.c +++ b/builtin/grep.c @@ -74,13 +74,32 @@ static int all_work_added; /* This lock protects all the variables above. */ static pthread_mutex_t grep_mutex; +static inline void grep_lock(void) +{ + if (use_threads) + pthread_mutex_lock(&grep_mutex); +} + +static inline void grep_unlock(void) +{ + if (use_threads) + pthread_mutex_unlock(&grep_mutex); +} + /* Used to serialize calls to read_sha1_file. */ static pthread_mutex_t read_sha1_mutex; -#define grep_lock() pthread_mutex_lock(&grep_mutex) -#define grep_unlock() pthread_mutex_unlock(&grep_mutex) -#define read_sha1_lock() pthread_mutex_lock(&read_sha1_mutex) -#define read_sha1_unlock() pthread_mutex_unlock(&read_sha1_mutex) +static inline void read_sha1_lock(void) +{ + if (use_threads) + pthread_mutex_lock(&read_sha1_mutex); +} + +static inline void read_sha1_unlock(void) +{ + if (use_threads) + pthread_mutex_unlock(&read_sha1_mutex); +} /* Signalled when a new work_item is added to todo. */ static pthread_cond_t cond_add; @@ -354,13 +373,9 @@ static void *lock_and_read_sha1_file(const unsigned char *sha1, enum object_type { void *data; - if (use_threads) { - read_sha1_lock(); - data = read_sha1_file(sha1, type, size); - read_sha1_unlock(); - } else { - data = read_sha1_file(sha1, type, size); - } + read_sha1_lock(); + data = read_sha1_file(sha1, type, size); + read_sha1_unlock(); return data; } diff --git a/builtin/merge.c b/builtin/merge.c index dffd5ec124..1387376248 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -316,13 +316,15 @@ static void squash_message(struct commit *commit) struct rev_info rev; struct strbuf out = STRBUF_INIT; struct commit_list *j; + const char *filename; int fd; struct pretty_print_context ctx = {0}; printf(_("Squash commit -- not updating HEAD\n")); - fd = open(git_path("SQUASH_MSG"), O_WRONLY | O_CREAT, 0666); + filename = git_path("SQUASH_MSG"); + fd = open(filename, O_WRONLY | O_CREAT, 0666); if (fd < 0) - die_errno(_("Could not write to '%s'"), git_path("SQUASH_MSG")); + die_errno(_("Could not write to '%s'"), filename); init_revisions(&rev, NULL); rev.ignore_merges = 1; @@ -492,14 +494,16 @@ static void merge_name(const char *remote, struct strbuf *msg) if (!strcmp(remote, "FETCH_HEAD") && !access(git_path("FETCH_HEAD"), R_OK)) { + const char *filename; FILE *fp; struct strbuf line = STRBUF_INIT; char *ptr; - fp = fopen(git_path("FETCH_HEAD"), "r"); + filename = git_path("FETCH_HEAD"); + fp = fopen(filename, "r"); if (!fp) die_errno(_("could not open '%s' for reading"), - git_path("FETCH_HEAD")); + filename); strbuf_getline(&line, fp, '\n'); fclose(fp); ptr = strstr(line.buf, "\tnot-for-merge\t"); @@ -771,7 +775,7 @@ int checkout_fast_forward(const unsigned char *head, const unsigned char *remote memset(&t, 0, sizeof(t)); memset(&dir, 0, sizeof(dir)); dir.flags |= DIR_SHOW_IGNORED; - dir.exclude_per_dir = ".gitignore"; + setup_standard_excludes(&dir); opts.dir = &dir; opts.head_idx = 1; @@ -847,20 +851,22 @@ static void add_strategies(const char *string, unsigned attr) static void write_merge_msg(struct strbuf *msg) { - int fd = open(git_path("MERGE_MSG"), O_WRONLY | O_CREAT, 0666); + const char *filename = git_path("MERGE_MSG"); + int fd = open(filename, O_WRONLY | O_CREAT, 0666); if (fd < 0) die_errno(_("Could not open '%s' for writing"), - git_path("MERGE_MSG")); + filename); if (write_in_full(fd, msg->buf, msg->len) != msg->len) - die_errno(_("Could not write to '%s'"), git_path("MERGE_MSG")); + die_errno(_("Could not write to '%s'"), filename); close(fd); } static void read_merge_msg(struct strbuf *msg) { + const char *filename = git_path("MERGE_MSG"); strbuf_reset(msg); - if (strbuf_read_file(msg, git_path("MERGE_MSG"), 0) < 0) - die_errno(_("Could not read from '%s'"), git_path("MERGE_MSG")); + if (strbuf_read_file(msg, filename, 0) < 0) + die_errno(_("Could not read from '%s'"), filename); } static void write_merge_state(void); @@ -948,13 +954,14 @@ static int finish_automerge(struct commit *head, static int suggest_conflicts(int renormalizing) { + const char *filename; FILE *fp; int pos; - fp = fopen(git_path("MERGE_MSG"), "a"); + filename = git_path("MERGE_MSG"); + fp = fopen(filename, "a"); if (!fp) - die_errno(_("Could not open '%s' for writing"), - git_path("MERGE_MSG")); + die_errno(_("Could not open '%s' for writing"), filename); fprintf(fp, "\nConflicts:\n"); for (pos = 0; pos < active_nr; pos++) { struct cache_entry *ce = active_cache[pos]; @@ -1046,6 +1053,7 @@ static int setup_with_upstream(const char ***argv) static void write_merge_state(void) { + const char *filename; int fd; struct commit_list *j; struct strbuf buf = STRBUF_INIT; @@ -1053,24 +1061,25 @@ static void write_merge_state(void) for (j = remoteheads; j; j = j->next) strbuf_addf(&buf, "%s\n", sha1_to_hex(j->item->object.sha1)); - fd = open(git_path("MERGE_HEAD"), O_WRONLY | O_CREAT, 0666); + filename = git_path("MERGE_HEAD"); + fd = open(filename, O_WRONLY | O_CREAT, 0666); if (fd < 0) - die_errno(_("Could not open '%s' for writing"), - git_path("MERGE_HEAD")); + die_errno(_("Could not open '%s' for writing"), filename); if (write_in_full(fd, buf.buf, buf.len) != buf.len) - die_errno(_("Could not write to '%s'"), git_path("MERGE_HEAD")); + die_errno(_("Could not write to '%s'"), filename); close(fd); strbuf_addch(&merge_msg, '\n'); write_merge_msg(&merge_msg); - fd = open(git_path("MERGE_MODE"), O_WRONLY | O_CREAT | O_TRUNC, 0666); + + filename = git_path("MERGE_MODE"); + fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0666); if (fd < 0) - die_errno(_("Could not open '%s' for writing"), - git_path("MERGE_MODE")); + die_errno(_("Could not open '%s' for writing"), filename); strbuf_reset(&buf); if (!allow_fast_forward) strbuf_addf(&buf, "no-ff"); if (write_in_full(fd, buf.buf, buf.len) != buf.len) - die_errno(_("Could not write to '%s'"), git_path("MERGE_MODE")); + die_errno(_("Could not write to '%s'"), filename); close(fd); } diff --git a/builtin/mktree.c b/builtin/mktree.c index 098395fda1..4ae1c412d4 100644 --- a/builtin/mktree.c +++ b/builtin/mktree.c @@ -60,6 +60,7 @@ static void write_tree(unsigned char *sha1) } write_sha1_file(buf.buf, buf.len, tree_type, sha1); + strbuf_release(&buf); } static const char *mktree_usage[] = { diff --git a/builtin/name-rev.c b/builtin/name-rev.c index 7864056f1e..1b374583c2 100644 --- a/builtin/name-rev.c +++ b/builtin/name-rev.c @@ -291,7 +291,7 @@ int cmd_name_rev(int argc, const char **argv, const char *prefix) max = get_max_object_index(); for (i = 0; i < max; i++) { struct object *obj = get_indexed_object(i); - if (!obj) + if (!obj || obj->type != OBJ_COMMIT) continue; show_name(obj, NULL, always, allow_undefined, data.name_only); diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c index b4f7855550..558cd34bcc 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -454,8 +454,8 @@ static int mark_tagged(const char *path, const unsigned char *sha1, int flag, return 0; } -static void add_to_write_order(struct object_entry **wo, - int *endp, +static inline void add_to_write_order(struct object_entry **wo, + unsigned int *endp, struct object_entry *e) { if (e->filled) @@ -465,32 +465,62 @@ static void add_to_write_order(struct object_entry **wo, } static void add_descendants_to_write_order(struct object_entry **wo, - int *endp, + unsigned int *endp, struct object_entry *e) { - struct object_entry *child; - - for (child = e->delta_child; child; child = child->delta_sibling) - add_to_write_order(wo, endp, child); - for (child = e->delta_child; child; child = child->delta_sibling) - add_descendants_to_write_order(wo, endp, child); + int add_to_order = 1; + while (e) { + if (add_to_order) { + struct object_entry *s; + /* add this node... */ + add_to_write_order(wo, endp, e); + /* all its siblings... */ + for (s = e->delta_sibling; s; s = s->delta_sibling) { + add_to_write_order(wo, endp, s); + } + } + /* drop down a level to add left subtree nodes if possible */ + if (e->delta_child) { + add_to_order = 1; + e = e->delta_child; + } else { + add_to_order = 0; + /* our sibling might have some children, it is next */ + if (e->delta_sibling) { + e = e->delta_sibling; + continue; + } + /* go back to our parent node */ + e = e->delta; + while (e && !e->delta_sibling) { + /* we're on the right side of a subtree, keep + * going up until we can go right again */ + e = e->delta; + } + if (!e) { + /* done- we hit our original root node */ + return; + } + /* pass it off to sibling at this level */ + e = e->delta_sibling; + } + }; } static void add_family_to_write_order(struct object_entry **wo, - int *endp, + unsigned int *endp, struct object_entry *e) { struct object_entry *root; for (root = e; root->delta; root = root->delta) ; /* nothing */ - add_to_write_order(wo, endp, root); add_descendants_to_write_order(wo, endp, root); } static struct object_entry **compute_write_order(void) { - int i, wo_end; + unsigned int i, wo_end, last_untagged; struct object_entry **wo = xmalloc(nr_objects * sizeof(*wo)); @@ -506,8 +536,8 @@ static struct object_entry **compute_write_order(void) * Make sure delta_sibling is sorted in the original * recency order. */ - for (i = nr_objects - 1; 0 <= i; i--) { - struct object_entry *e = &objects[i]; + for (i = nr_objects; i > 0;) { + struct object_entry *e = &objects[--i]; if (!e->delta) continue; /* Mark me as the first child */ @@ -521,7 +551,7 @@ static struct object_entry **compute_write_order(void) for_each_tag_ref(mark_tagged, NULL); /* - * Give the commits in the original recency order until + * Give the objects in the original recency order until * we see a tagged tip. */ for (i = wo_end = 0; i < nr_objects; i++) { @@ -529,6 +559,7 @@ static struct object_entry **compute_write_order(void) break; add_to_write_order(wo, &wo_end, &objects[i]); } + last_untagged = i; /* * Then fill all the tagged tips. @@ -541,7 +572,7 @@ static struct object_entry **compute_write_order(void) /* * And then all remaining commits and tags. */ - for (i = 0; i < nr_objects; i++) { + for (i = last_untagged; i < nr_objects; i++) { if (objects[i].type != OBJ_COMMIT && objects[i].type != OBJ_TAG) continue; @@ -551,7 +582,7 @@ static struct object_entry **compute_write_order(void) /* * And then all the trees. */ - for (i = 0; i < nr_objects; i++) { + for (i = last_untagged; i < nr_objects; i++) { if (objects[i].type != OBJ_TREE) continue; add_to_write_order(wo, &wo_end, &objects[i]); @@ -560,8 +591,13 @@ static struct object_entry **compute_write_order(void) /* * Finally all the rest in really tight order */ - for (i = 0; i < nr_objects; i++) - add_family_to_write_order(wo, &wo_end, &objects[i]); + for (i = last_untagged; i < nr_objects; i++) { + if (!objects[i].filled) + add_family_to_write_order(wo, &wo_end, &objects[i]); + } + + if (wo_end != nr_objects) + die("ordered %u objects, expected %"PRIu32, wo_end, nr_objects); return wo; } diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c index 261b610d24..7ec68a1e80 100644 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@ -634,7 +634,7 @@ static int command_singleton_iterator(void *cb_data, unsigned char sha1[20]) struct command **cmd_list = cb_data; struct command *cmd = *cmd_list; - if (!cmd) + if (!cmd || is_null_sha1(cmd->new_sha1)) return -1; /* end of list */ *cmd_list = NULL; /* this returns only one */ hashcpy(sha1, cmd->new_sha1); @@ -659,11 +659,16 @@ static int iterate_receive_command_list(void *cb_data, unsigned char sha1[20]) struct command **cmd_list = cb_data; struct command *cmd = *cmd_list; - if (!cmd) - return -1; /* end of list */ - *cmd_list = cmd->next; - hashcpy(sha1, cmd->new_sha1); - return 0; + while (cmd) { + if (!is_null_sha1(cmd->new_sha1)) { + hashcpy(sha1, cmd->new_sha1); + *cmd_list = cmd->next; + return 0; + } + cmd = cmd->next; + } + *cmd_list = NULL; + return -1; /* end of list */ } static void execute_commands(struct command *commands, const char *unpacker_error) diff --git a/builtin/remote.c b/builtin/remote.c index 7335149799..c810643815 100644 --- a/builtin/remote.c +++ b/builtin/remote.c @@ -1399,7 +1399,7 @@ static int set_branches(int argc, const char **argv) builtin_remote_setbranches_usage, 0); if (argc == 0) { error("no remote specified"); - usage_with_options(builtin_remote_seturl_usage, options); + usage_with_options(builtin_remote_setbranches_usage, options); } argv[argc] = NULL; @@ -1427,7 +1427,7 @@ static int set_url(int argc, const char **argv) "delete URLs"), OPT_END() }; - argc = parse_options(argc, argv, NULL, options, builtin_remote_update_usage, + argc = parse_options(argc, argv, NULL, options, builtin_remote_seturl_usage, PARSE_OPT_KEEP_ARGV0); if (add_mode && delete_mode) diff --git a/builtin/revert.c b/builtin/revert.c index 87df70edc3..1ea525c10e 100644 --- a/builtin/revert.c +++ b/builtin/revert.c @@ -40,7 +40,12 @@ static const char * const cherry_pick_usage[] = { }; enum replay_action { REVERT, CHERRY_PICK }; -enum replay_subcommand { REPLAY_NONE, REPLAY_RESET, REPLAY_CONTINUE }; +enum replay_subcommand { + REPLAY_NONE, + REPLAY_REMOVE_STATE, + REPLAY_CONTINUE, + REPLAY_ROLLBACK +}; struct replay_opts { enum replay_action action; @@ -133,11 +138,13 @@ static void parse_args(int argc, const char **argv, struct replay_opts *opts) { const char * const * usage_str = revert_or_cherry_pick_usage(opts); const char *me = action_name(opts); - int reset = 0; + int remove_state = 0; int contin = 0; + int rollback = 0; struct option options[] = { - OPT_BOOLEAN(0, "reset", &reset, "forget the current operation"), - OPT_BOOLEAN(0, "continue", &contin, "continue the current operation"), + OPT_BOOLEAN(0, "quit", &remove_state, "end revert or cherry-pick sequence"), + OPT_BOOLEAN(0, "continue", &contin, "resume revert or cherry-pick sequence"), + OPT_BOOLEAN(0, "abort", &rollback, "cancel revert or cherry-pick sequence"), OPT_BOOLEAN('n', "no-commit", &opts->no_commit, "don't automatically commit"), OPT_BOOLEAN('e', "edit", &opts->edit, "edit the commit message"), OPT_NOOP_NOARG('r', NULL), @@ -168,25 +175,32 @@ static void parse_args(int argc, const char **argv, struct replay_opts *opts) /* Check for incompatible subcommands */ verify_opt_mutually_compatible(me, - "--reset", reset, + "--quit", remove_state, "--continue", contin, + "--abort", rollback, NULL); /* Set the subcommand */ - if (reset) - opts->subcommand = REPLAY_RESET; + if (remove_state) + opts->subcommand = REPLAY_REMOVE_STATE; else if (contin) opts->subcommand = REPLAY_CONTINUE; + else if (rollback) + opts->subcommand = REPLAY_ROLLBACK; else opts->subcommand = REPLAY_NONE; /* Check for incompatible command line arguments */ if (opts->subcommand != REPLAY_NONE) { char *this_operation; - if (opts->subcommand == REPLAY_RESET) - this_operation = "--reset"; - else + if (opts->subcommand == REPLAY_REMOVE_STATE) + this_operation = "--quit"; + else if (opts->subcommand == REPLAY_CONTINUE) this_operation = "--continue"; + else { + assert(opts->subcommand == REPLAY_ROLLBACK); + this_operation = "--abort"; + } verify_opt_compatible(me, this_operation, "--no-commit", opts->no_commit, @@ -286,19 +300,20 @@ static char *get_encoding(const char *message) return NULL; } -static void write_cherry_pick_head(struct commit *commit) +static void write_cherry_pick_head(struct commit *commit, const char *pseudoref) { + const char *filename; int fd; struct strbuf buf = STRBUF_INIT; strbuf_addf(&buf, "%s\n", sha1_to_hex(commit->object.sha1)); - fd = open(git_path("CHERRY_PICK_HEAD"), O_WRONLY | O_CREAT, 0666); + filename = git_path("%s", pseudoref); + fd = open(filename, O_WRONLY | O_CREAT, 0666); if (fd < 0) - die_errno(_("Could not open '%s' for writing"), - git_path("CHERRY_PICK_HEAD")); + die_errno(_("Could not open '%s' for writing"), filename); if (write_in_full(fd, buf.buf, buf.len) != buf.len || close(fd)) - die_errno(_("Could not write to '%s'"), git_path("CHERRY_PICK_HEAD")); + die_errno(_("Could not write to '%s'"), filename); strbuf_release(&buf); } @@ -331,7 +346,7 @@ static void write_message(struct strbuf *msgbuf, const char *filename) int msg_fd = hold_lock_file_for_update(&msg_file, filename, LOCK_DIE_ON_ERROR); if (write_in_full(msg_fd, msgbuf->buf, msgbuf->len) < 0) - die_errno(_("Could not write to %s."), filename); + die_errno(_("Could not write to %s"), filename); strbuf_release(msgbuf); if (commit_lock_file(&msg_file) < 0) die(_("Error wrapping up %s"), filename); @@ -593,7 +608,9 @@ static int do_pick_commit(struct commit *commit, struct replay_opts *opts) * write it at all. */ if (opts->action == CHERRY_PICK && !opts->no_commit && (res == 0 || res == 1)) - write_cherry_pick_head(commit); + write_cherry_pick_head(commit, "CHERRY_PICK_HEAD"); + if (opts->action == REVERT && ((opts->no_commit && res == 0) || res == 1)) + write_cherry_pick_head(commit, "REVERT_HEAD"); if (res) { error(opts->action == REVERT @@ -767,7 +784,7 @@ static void read_populate_todo(struct commit_list **todo_list, fd = open(todo_file, O_RDONLY); if (fd < 0) - die_errno(_("Could not open %s."), todo_file); + die_errno(_("Could not open %s"), todo_file); if (strbuf_read(&buf, fd, 0) < 0) { close(fd); strbuf_release(&buf); @@ -842,10 +859,13 @@ static int create_seq_dir(void) { const char *seq_dir = git_path(SEQ_DIR); - if (file_exists(seq_dir)) - return error(_("%s already exists."), seq_dir); + if (file_exists(seq_dir)) { + error(_("a cherry-pick or revert is already in progress")); + advise(_("try \"git cherry-pick (--continue | --quit | --abort)\"")); + return -1; + } else if (mkdir(seq_dir, 0777) < 0) - die_errno(_("Could not create sequencer directory '%s'."), seq_dir); + die_errno(_("Could not create sequencer directory %s"), seq_dir); return 0; } @@ -859,11 +879,77 @@ static void save_head(const char *head) fd = hold_lock_file_for_update(&head_lock, head_file, LOCK_DIE_ON_ERROR); strbuf_addf(&buf, "%s\n", head); if (write_in_full(fd, buf.buf, buf.len) < 0) - die_errno(_("Could not write to %s."), head_file); + die_errno(_("Could not write to %s"), head_file); if (commit_lock_file(&head_lock) < 0) die(_("Error wrapping up %s."), head_file); } +static int reset_for_rollback(const unsigned char *sha1) +{ + const char *argv[4]; /* reset --merge <arg> + NULL */ + argv[0] = "reset"; + argv[1] = "--merge"; + argv[2] = sha1_to_hex(sha1); + argv[3] = NULL; + return run_command_v_opt(argv, RUN_GIT_CMD); +} + +static int rollback_single_pick(void) +{ + unsigned char head_sha1[20]; + + if (!file_exists(git_path("CHERRY_PICK_HEAD")) && + !file_exists(git_path("REVERT_HEAD"))) + return error(_("no cherry-pick or revert in progress")); + if (!resolve_ref("HEAD", head_sha1, 0, NULL)) + return error(_("cannot resolve HEAD")); + if (is_null_sha1(head_sha1)) + return error(_("cannot abort from a branch yet to be born")); + return reset_for_rollback(head_sha1); +} + +static int sequencer_rollback(struct replay_opts *opts) +{ + const char *filename; + FILE *f; + unsigned char sha1[20]; + struct strbuf buf = STRBUF_INIT; + + filename = git_path(SEQ_HEAD_FILE); + f = fopen(filename, "r"); + if (!f && errno == ENOENT) { + /* + * There is no multiple-cherry-pick in progress. + * If CHERRY_PICK_HEAD or REVERT_HEAD indicates + * a single-cherry-pick in progress, abort that. + */ + return rollback_single_pick(); + } + if (!f) + return error(_("cannot open %s: %s"), filename, + strerror(errno)); + if (strbuf_getline(&buf, f, '\n')) { + error(_("cannot read %s: %s"), filename, ferror(f) ? + strerror(errno) : _("unexpected end of file")); + fclose(f); + goto fail; + } + fclose(f); + if (get_sha1_hex(buf.buf, sha1) || buf.buf[40] != '\0') { + error(_("stored pre-cherry-pick HEAD file '%s' is corrupt"), + filename); + goto fail; + } + if (reset_for_rollback(sha1)) + goto fail; + remove_sequencer_state(1); + strbuf_release(&buf); + return 0; +fail: + strbuf_release(&buf); + return -1; +} + static void save_todo(struct commit_list *todo_list, struct replay_opts *opts) { const char *todo_file = git_path(SEQ_TODO_FILE); @@ -876,7 +962,7 @@ static void save_todo(struct commit_list *todo_list, struct replay_opts *opts) die(_("Could not format %s."), todo_file); if (write_in_full(fd, buf.buf, buf.len) < 0) { strbuf_release(&buf); - die_errno(_("Could not write to %s."), todo_file); + die_errno(_("Could not write to %s"), todo_file); } if (commit_lock_file(&todo_lock) < 0) { strbuf_release(&buf); @@ -964,43 +1050,41 @@ static int pick_revisions(struct replay_opts *opts) * cherry-pick should be handled differently from an existing * one that is being continued */ - if (opts->subcommand == REPLAY_RESET) { + if (opts->subcommand == REPLAY_REMOVE_STATE) { remove_sequencer_state(1); return 0; - } else if (opts->subcommand == REPLAY_CONTINUE) { + } + if (opts->subcommand == REPLAY_ROLLBACK) + return sequencer_rollback(opts); + if (opts->subcommand == REPLAY_CONTINUE) { if (!file_exists(git_path(SEQ_TODO_FILE))) - goto error; + return error(_("No %s in progress"), action_name(opts)); read_populate_opts(&opts); read_populate_todo(&todo_list, opts); /* Verify that the conflict has been resolved */ if (!index_differs_from("HEAD", 0)) todo_list = todo_list->next; - } else { - /* - * Start a new cherry-pick/ revert sequence; but - * first, make sure that an existing one isn't in - * progress - */ + return pick_commits(todo_list, opts); + } - walk_revs_populate_todo(&todo_list, opts); - if (create_seq_dir() < 0) { - error(_("A cherry-pick or revert is in progress.")); - advise(_("Use --continue to continue the operation")); - advise(_("or --reset to forget about it")); - return -1; - } - if (get_sha1("HEAD", sha1)) { - if (opts->action == REVERT) - return error(_("Can't revert as initial commit")); - return error(_("Can't cherry-pick into empty head")); - } - save_head(sha1_to_hex(sha1)); - save_opts(opts); + /* + * Start a new cherry-pick/ revert sequence; but + * first, make sure that an existing one isn't in + * progress + */ + + walk_revs_populate_todo(&todo_list, opts); + if (create_seq_dir() < 0) + return -1; + if (get_sha1("HEAD", sha1)) { + if (opts->action == REVERT) + return error(_("Can't revert as initial commit")); + return error(_("Can't cherry-pick into empty head")); } + save_head(sha1_to_hex(sha1)); + save_opts(opts); return pick_commits(todo_list, opts); -error: - return error(_("No %s in progress"), action_name(opts)); } int cmd_revert(int argc, const char **argv, const char *prefix) diff --git a/builtin/stripspace.c b/builtin/stripspace.c index 4d3b93fedb..1288ffcc52 100644 --- a/builtin/stripspace.c +++ b/builtin/stripspace.c @@ -22,8 +22,6 @@ static size_t cleanup(char *line, size_t len) * Remove empty lines from the beginning and end * and also trailing spaces from every line. * - * Note that the buffer will not be NUL-terminated. - * * Turn multiple consecutive empty lines between paragraphs * into just one empty line. * diff --git a/compat/mingw.c b/compat/mingw.c index efdc703257..a0ac487c0c 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -1712,7 +1712,7 @@ char *getpass(const char *prompt) return strbuf_detach(&buf, NULL); } -pid_t waitpid(pid_t pid, int *status, unsigned options) +pid_t waitpid(pid_t pid, int *status, int options) { HANDLE h = OpenProcess(SYNCHRONIZE | PROCESS_QUERY_INFORMATION, FALSE, pid); diff --git a/compat/mingw.h b/compat/mingw.h index fecf0d0776..0ff1e04812 100644 --- a/compat/mingw.h +++ b/compat/mingw.h @@ -120,7 +120,7 @@ static inline int mingw_mkdir(const char *path, int mode) #define mkdir mingw_mkdir #define WNOHANG 1 -pid_t waitpid(pid_t pid, int *status, unsigned options); +pid_t waitpid(pid_t pid, int *status, int options); #define kill mingw_kill int mingw_kill(pid_t pid, int sig); diff --git a/compat/win32/sys/poll.c b/compat/win32/poll.c index 708a6c9bec..403eaa7a3c 100644 --- a/compat/win32/sys/poll.c +++ b/compat/win32/poll.c @@ -1,7 +1,7 @@ /* Emulation for poll(2) Contributed by Paolo Bonzini. - Copyright 2001-2003, 2006-2010 Free Software Foundation, Inc. + Copyright 2001-2003, 2006-2011 Free Software Foundation, Inc. This file is part of gnulib. @@ -27,7 +27,10 @@ #include <malloc.h> #include <sys/types.h> -#include "poll.h" + +/* Specification. */ +#include <poll.h> + #include <errno.h> #include <limits.h> #include <assert.h> @@ -314,10 +317,7 @@ compute_revents (int fd, int sought, fd_set *rfds, fd_set *wfds, fd_set *efds) #endif /* !MinGW */ int -poll (pfd, nfd, timeout) - struct pollfd *pfd; - nfds_t nfd; - int timeout; +poll (struct pollfd *pfd, nfds_t nfd, int timeout) { #ifndef WIN32_NATIVE fd_set rfds, wfds, efds; @@ -454,6 +454,7 @@ poll (pfd, nfd, timeout) if (!hEvent) hEvent = CreateEvent (NULL, FALSE, FALSE, NULL); +restart: handle_array[0] = hEvent; nhandles = 1; FD_ZERO (&rfds); @@ -594,6 +595,12 @@ poll (pfd, nfd, timeout) rc++; } + if (!rc && timeout == INFTIM) + { + SwitchToThread(); + goto restart; + } + return rc; #endif } diff --git a/compat/win32/sys/poll.h b/compat/win32/poll.h index b7aa59d973..b7aa59d973 100644 --- a/compat/win32/sys/poll.h +++ b/compat/win32/poll.h @@ -865,12 +865,12 @@ int git_config_early(config_fn_t fn, void *data, const char *repo_config) home = getenv("HOME"); if (home) { - char *user_config = xstrdup(mkpath("%s/.gitconfig", home)); + char buf[PATH_MAX]; + char *user_config = mksnpath(buf, sizeof(buf), "%s/.gitconfig", home); if (!access(user_config, R_OK)) { ret += git_config_from_file(fn, user_config, data); found += 1; } - free(user_config); } if (repo_config && !access(repo_config, R_OK)) { diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 888e8e10cc..b7c1edf1cc 100755 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -110,6 +110,7 @@ __git_ps1_show_upstream () local upstream=git legacy="" verbose="" # get some config options from git-config + local output="$(git config -z --get-regexp '^(svn-remote\..*\.url|bash\.showupstream)$' 2>/dev/null | tr '\0\n' '\n ')" while read key value; do case "$key" in bash.showupstream) @@ -125,7 +126,7 @@ __git_ps1_show_upstream () upstream=svn+git # default upstream is SVN if available, else git ;; esac - done < <(git config -z --get-regexp '^(svn-remote\..*\.url|bash\.showupstream)$' 2>/dev/null | tr '\0\n' '\n ') + done <<< "$output" # parse configuration values for option in ${GIT_PS1_SHOWUPSTREAM}; do @@ -1429,6 +1430,10 @@ _git_gitk () _gitk } +__git_match_ctag() { + awk "/^${1////\\/}/ { print \$1 }" "$2" +} + _git_grep () { __git_has_doubledash && return @@ -1451,6 +1456,15 @@ _git_grep () ;; esac + case "$cword,$prev" in + 2,*|*,-*) + if test -r tags; then + __gitcomp "$(__git_match_ctag "$cur" tags)" + return + fi + ;; + esac + __gitcomp "$(__git_refs)" } diff --git a/contrib/diff-highlight/README b/contrib/diff-highlight/README new file mode 100644 index 0000000000..1b7b6df8eb --- /dev/null +++ b/contrib/diff-highlight/README @@ -0,0 +1,57 @@ +diff-highlight +============== + +Line oriented diffs are great for reviewing code, because for most +hunks, you want to see the old and the new segments of code next to each +other. Sometimes, though, when an old line and a new line are very +similar, it's hard to immediately see the difference. + +You can use "--color-words" to highlight only the changed portions of +lines. However, this can often be hard to read for code, as it loses +the line structure, and you end up with oddly formatted bits. + +Instead, this script post-processes the line-oriented diff, finds pairs +of lines, and highlights the differing segments. It's currently very +simple and stupid about doing these tasks. In particular: + + 1. It will only highlight a pair of lines if they are the only two + lines in a hunk. It could instead try to match up "before" and + "after" lines for a given hunk into pairs of similar lines. + However, this may end up visually distracting, as the paired + lines would have other highlighted lines in between them. And in + practice, the lines which most need attention called to their + small, hard-to-see changes are touching only a single line. + + 2. It will find the common prefix and suffix of two lines, and + consider everything in the middle to be "different". It could + instead do a real diff of the characters between the two lines and + find common subsequences. However, the point of the highlight is to + call attention to a certain area. Even if some small subset of the + highlighted area actually didn't change, that's OK. In practice it + ends up being more readable to just have a single blob on the line + showing the interesting bit. + +The goal of the script is therefore not to be exact about highlighting +changes, but to call attention to areas of interest without being +visually distracting. Non-diff lines and existing diff coloration is +preserved; the intent is that the output should look exactly the same as +the input, except for the occasional highlight. + +Use +--- + +You can try out the diff-highlight program with: + +--------------------------------------------- +git log -p --color | /path/to/diff-highlight +--------------------------------------------- + +If you want to use it all the time, drop it in your $PATH and put the +following in your git configuration: + +--------------------------------------------- +[pager] + log = diff-highlight | less + show = diff-highlight | less + diff = diff-highlight | less +--------------------------------------------- diff --git a/contrib/diff-highlight/diff-highlight b/contrib/diff-highlight/diff-highlight new file mode 100755 index 0000000000..d8938982e4 --- /dev/null +++ b/contrib/diff-highlight/diff-highlight @@ -0,0 +1,124 @@ +#!/usr/bin/perl + +# Highlight by reversing foreground and background. You could do +# other things like bold or underline if you prefer. +my $HIGHLIGHT = "\x1b[7m"; +my $UNHIGHLIGHT = "\x1b[27m"; +my $COLOR = qr/\x1b\[[0-9;]*m/; + +my @window; + +while (<>) { + # We highlight only single-line changes, so we need + # a 4-line window to make a decision on whether + # to highlight. + push @window, $_; + next if @window < 4; + if ($window[0] =~ /^$COLOR*(\@| )/ && + $window[1] =~ /^$COLOR*-/ && + $window[2] =~ /^$COLOR*\+/ && + $window[3] !~ /^$COLOR*\+/) { + print shift @window; + show_pair(shift @window, shift @window); + } + else { + print shift @window; + } + + # Most of the time there is enough output to keep things streaming, + # but for something like "git log -Sfoo", you can get one early + # commit and then many seconds of nothing. We want to show + # that one commit as soon as possible. + # + # Since we can receive arbitrary input, there's no optimal + # place to flush. Flushing on a blank line is a heuristic that + # happens to match git-log output. + if (!length) { + local $| = 1; + } +} + +# Special case a single-line hunk at the end of file. +if (@window == 3 && + $window[0] =~ /^$COLOR*(\@| )/ && + $window[1] =~ /^$COLOR*-/ && + $window[2] =~ /^$COLOR*\+/) { + print shift @window; + show_pair(shift @window, shift @window); +} + +# And then flush any remaining lines. +while (@window) { + print shift @window; +} + +exit 0; + +sub show_pair { + my @a = split_line(shift); + my @b = split_line(shift); + + # Find common prefix, taking care to skip any ansi + # color codes. + my $seen_plusminus; + my ($pa, $pb) = (0, 0); + while ($pa < @a && $pb < @b) { + if ($a[$pa] =~ /$COLOR/) { + $pa++; + } + elsif ($b[$pb] =~ /$COLOR/) { + $pb++; + } + elsif ($a[$pa] eq $b[$pb]) { + $pa++; + $pb++; + } + elsif (!$seen_plusminus && $a[$pa] eq '-' && $b[$pb] eq '+') { + $seen_plusminus = 1; + $pa++; + $pb++; + } + else { + last; + } + } + + # Find common suffix, ignoring colors. + my ($sa, $sb) = ($#a, $#b); + while ($sa >= $pa && $sb >= $pb) { + if ($a[$sa] =~ /$COLOR/) { + $sa--; + } + elsif ($b[$sb] =~ /$COLOR/) { + $sb--; + } + elsif ($a[$sa] eq $b[$sb]) { + $sa--; + $sb--; + } + else { + last; + } + } + + print highlight(\@a, $pa, $sa); + print highlight(\@b, $pb, $sb); +} + +sub split_line { + local $_ = shift; + return map { /$COLOR/ ? $_ : (split //) } + split /($COLOR*)/; +} + +sub highlight { + my ($line, $prefix, $suffix) = @_; + + return join('', + @{$line}[0..($prefix-1)], + $HIGHLIGHT, + @{$line}[$prefix..$suffix], + $UNHIGHLIGHT, + @{$line}[($suffix+1)..$#$line] + ); +} diff --git a/contrib/fast-import/git-p4 b/contrib/fast-import/git-p4 index f885d707c4..b975d67fca 100755 --- a/contrib/fast-import/git-p4 +++ b/contrib/fast-import/git-p4 @@ -1318,6 +1318,19 @@ class P4Sync(Command, P4UserMap): text = p4_read_pipe(['print', '-q', '-o', '-', file['depotFile']]) contents = [ text ] + if type_base == "apple": + # Apple filetype files will be streamed as a concatenation of + # its appledouble header and the contents. This is useless + # on both macs and non-macs. If using "print -q -o xx", it + # will create "xx" with the data, and "%xx" with the header. + # This is also not very useful. + # + # Ideally, someday, this script can learn how to generate + # appledouble files directly and import those to git, but + # non-mac machines can never find a use for apple filetype. + print "\nIgnoring apple filetype file %s" % file['depotFile'] + return + # Perhaps windows wants unicode, utf16 newlines translated too; # but this is not doing it. if self.isWindows and type_base == "text": diff --git a/contrib/git-jump/README b/contrib/git-jump/README new file mode 100644 index 0000000000..1cebc328cb --- /dev/null +++ b/contrib/git-jump/README @@ -0,0 +1,92 @@ +git-jump +======== + +Git-jump is a script for helping you jump to "interesting" parts of your +project in your editor. It works by outputting a set of interesting +spots in the "quickfix" format, which editors like vim can use as a +queue of places to visit (this feature is usually used to jump to errors +produced by a compiler). For example, given a diff like this: + +------------------------------------ +diff --git a/foo.c b/foo.c +index a655540..5a59044 100644 +--- a/foo.c ++++ b/foo.c +@@ -1,3 +1,3 @@ + int main(void) { +- printf("hello word!\n"); ++ printf("hello world!\n"); + } +----------------------------------- + +git-jump will feed this to the editor: + +----------------------------------- +foo.c:2: printf("hello word!\n"); +----------------------------------- + +Obviously this trivial case isn't that interesting; you could just open +`foo.c` yourself. But when you have many changes scattered across a +project, you can use the editor's support to "jump" from point to point. + +Git-jump can generate three types of interesting lists: + + 1. The beginning of any diff hunks. + + 2. The beginning of any merge conflict markers. + + 3. Any grep matches. + + +Using git-jump +-------------- + +To use it, just drop git-jump in your PATH, and then invoke it like +this: + +-------------------------------------------------- +# jump to changes not yet staged for commit +git jump diff + +# jump to changes that are staged for commit; you can give +# arbitrary diff options +git jump diff --cached + +# jump to merge conflicts +git jump merge + +# jump to all instances of foo_bar +git jump grep foo_bar + +# same as above, but case-insensitive; you can give +# arbitrary grep options +git jump grep -i foo_bar +-------------------------------------------------- + + +Related Programs +---------------- + +You can accomplish some of the same things with individual tools. For +example, you can use `git mergetool` to start vimdiff on each unmerged +file. `git jump merge` is for the vim-wielding luddite who just wants to +jump straight to the conflict text with no fanfare. + +As of git v1.7.2, `git grep` knows the `--open-files-in-pager` option, +which does something similar to `git jump grep`. However, it is limited +to positioning the cursor to the correct line in only the first file, +leaving you to locate subsequent hits in that file or other files using +the editor or pager. By contrast, git-jump provides the editor with a +complete list of files and line numbers for each match. + + +Limitations +----------- + +This scripts was written and tested with vim. Given that the quickfix +format is the same as what gcc produces, I expect emacs users have a +similar feature for iterating through the list, but I know nothing about +how to activate it. + +The shell snippets to generate the quickfix lines will almost certainly +choke on filenames with exotic characters (like newlines). diff --git a/contrib/git-jump/git-jump b/contrib/git-jump/git-jump new file mode 100755 index 0000000000..a33674e47a --- /dev/null +++ b/contrib/git-jump/git-jump @@ -0,0 +1,69 @@ +#!/bin/sh + +usage() { + cat <<\EOF +usage: git jump <mode> [<args>] + +Jump to interesting elements in an editor. +The <mode> parameter is one of: + +diff: elements are diff hunks. Arguments are given to diff. + +merge: elements are merge conflicts. Arguments are ignored. + +grep: elements are grep hits. Arguments are given to grep. +EOF +} + +open_editor() { + editor=`git var GIT_EDITOR` + eval "$editor -q \$1" +} + +mode_diff() { + git diff --relative "$@" | + perl -ne ' + if (m{^\+\+\+ b/(.*)}) { $file = $1; next } + defined($file) or next; + if (m/^@@ .*\+(\d+)/) { $line = $1; next } + defined($line) or next; + if (/^ /) { $line++; next } + if (/^[-+]\s*(.*)/) { + print "$file:$line: $1\n"; + $line = undef; + } + ' +} + +mode_merge() { + git ls-files -u | + perl -pe 's/^.*?\t//' | + sort -u | + while IFS= read fn; do + grep -Hn '^<<<<<<<' "$fn" + done +} + +# Grep -n generates nice quickfix-looking lines by itself, +# but let's clean up extra whitespace, so they look better if the +# editor shows them to us in the status bar. +mode_grep() { + git grep -n "$@" | + perl -pe ' + s/[ \t]+/ /g; + s/^ *//; + ' +} + +if test $# -lt 1; then + usage >&2 + exit 1 +fi +mode=$1; shift + +trap 'rm -f "$tmp"' 0 1 2 3 15 +tmp=`mktemp -t git-jump.XXXXXX` || exit 1 +type "mode_$mode" >/dev/null 2>&1 || { usage >&2; exit 1; } +"mode_$mode" "$@" >"$tmp" +test -s "$tmp" || exit 0 +open_editor "$tmp" @@ -641,7 +641,7 @@ static int ident_to_worktree(const char *path, const char *src, size_t len, return 1; } -static int git_path_check_crlf(const char *path, struct git_attr_check *check) +static enum crlf_action git_path_check_crlf(const char *path, struct git_attr_check *check) { const char *value = check->value; @@ -658,7 +658,7 @@ static int git_path_check_crlf(const char *path, struct git_attr_check *check) return CRLF_GUESS; } -static int git_path_check_eol(const char *path, struct git_attr_check *check) +static enum eol git_path_check_eol(const char *path, struct git_attr_check *check) { const char *value = check->value; @@ -811,7 +811,7 @@ int renormalize_buffer(const char *path, const char *src, size_t len, struct str src = dst->buf; len = dst->len; } - return ret | convert_to_git(path, src, len, dst, 0); + return ret | convert_to_git(path, src, len, dst, SAFE_CRLF_FALSE); } /***************************************************************** @@ -530,7 +530,6 @@ else echo "$sign" >"$dotest/sign" echo "$utf8" >"$dotest/utf8" echo "$keep" >"$dotest/keep" - echo "$keepcr" >"$dotest/keepcr" echo "$scissors" >"$dotest/scissors" echo "$no_inbody_headers" >"$dotest/no_inbody_headers" echo "$GIT_QUIET" >"$dotest/quiet" @@ -576,12 +575,6 @@ if test "$(cat "$dotest/keep")" = t then keep=-k fi -case "$(cat "$dotest/keepcr")" in -t) - keepcr=--keep-cr ;; -f) - keepcr=--no-keep-cr ;; -esac case "$(cat "$dotest/scissors")" in t) scissors=--scissors ;; diff --git a/git-compat-util.h b/git-compat-util.h index 5ef8ff76f6..8b4dd5c022 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -219,7 +219,7 @@ extern char *gitbasename(char *); #define find_last_dir_sep(path) strrchr(path, '/') #endif -#if __HP_cc >= 61000 +#if defined(__HP_cc) && (__HP_cc >= 61000) #define NORETURN __attribute__((noreturn)) #define NORETURN_PTR #elif defined(__GNUC__) && !defined(NO_NORETURN) diff --git a/git-svn.perl b/git-svn.perl index b67fef0bf6..e30df22d89 100755 --- a/git-svn.perl +++ b/git-svn.perl @@ -684,7 +684,7 @@ sub populate_merge_info { fatal "merge commit $d has ancestor $parent, but that change " ."does not have git-svn metadata!"; } - unless ($branchurl =~ /^$rooturl(.*)/) { + unless ($branchurl =~ /^\Q$rooturl\E(.*)/) { fatal "commit $parent git-svn metadata changed mid-run!"; } my $branchpath = $1; @@ -867,7 +867,7 @@ sub cmd_dcommit { ."has uuid $uuid!"; } - unless ($branchurl =~ /^$rooturl(.*)/) { + unless ($branchurl =~ /^\Q$rooturl\E(.*)/) { # This branch is very strange indeed. fatal "merge parent $parent for $d is on branch " ."$branchurl, which is not under the " diff --git a/gitweb/Makefile b/gitweb/Makefile index e65fc27e4f..cd194d057f 100644 --- a/gitweb/Makefile +++ b/gitweb/Makefile @@ -187,7 +187,9 @@ install: all ### Cleaning rules clean: - $(RM) gitweb.cgi static/gitweb.min.js static/gitweb.min.css GITWEB-BUILD-OPTIONS + $(RM) gitweb.cgi static/gitweb.js \ + static/gitweb.min.js static/gitweb.min.css \ + GITWEB-BUILD-OPTIONS .PHONY: all clean install test test-installed .FORCE-GIT-VERSION-FILE FORCE @@ -279,8 +279,6 @@ static CURL *get_curl_handle(void) curl_easy_setopt(result, CURLOPT_HTTPAUTH, CURLAUTH_ANY); #endif - init_curl_http_auth(result); - if (ssl_cert != NULL) curl_easy_setopt(result, CURLOPT_SSLCERT, ssl_cert); if (has_cert_password()) @@ -749,14 +747,6 @@ static inline int needs_quote(int ch) return 1; } -static inline int hex(int v) -{ - if (v < 10) - return '0' + v; - else - return 'A' + v - 10; -} - static char *quote_ref_url(const char *base, const char *ref) { struct strbuf buf = STRBUF_INIT; @@ -846,7 +836,7 @@ static int http_request(const char *url, void *result, int target, int options) else if (missing_target(&results)) ret = HTTP_MISSING_TARGET; else if (results.http_code == 401) { - if (user_name) { + if (user_name && user_pass) { ret = HTTP_NOAUTH; } else { /* @@ -855,7 +845,8 @@ static int http_request(const char *url, void *result, int target, int options) * but that is non-portable. Using git_getpass() can at least be stubbed * on other platforms with a different implementation if/when necessary. */ - user_name = xstrdup(git_getpass_with_description("Username", description)); + if (!user_name) + user_name = xstrdup(git_getpass_with_description("Username", description)); init_curl_http_auth(slot->curl); ret = HTTP_REAUTH; } @@ -70,8 +70,7 @@ static void add_mapping(struct string_list *map, } else { /* create mailmap entry */ struct string_list_item *item = string_list_insert_at_index(map, index, old_email); - item->util = xmalloc(sizeof(struct mailmap_entry)); - memset(item->util, 0, sizeof(struct mailmap_entry)); + item->util = xcalloc(1, sizeof(struct mailmap_entry)); ((struct mailmap_entry *)item->util)->namemap.strdup_strings = 1; } me = (struct mailmap_entry *)map->items[index].util; @@ -88,7 +87,7 @@ static void add_mapping(struct string_list *map, me->email = xstrdup(new_email); } } else { - struct mailmap_info *mi = xmalloc(sizeof(struct mailmap_info)); + struct mailmap_info *mi = xcalloc(1, sizeof(struct mailmap_info)); debug_mm("mailmap: adding (complex) entry for %s at index %d\n", old_email, index); if (new_name) mi->name = xstrdup(new_name); diff --git a/name-hash.c b/name-hash.c index 225dd76995..d8d25c23e9 100644 --- a/name-hash.c +++ b/name-hash.c @@ -74,7 +74,7 @@ static void hash_index_entry(struct index_state *istate, struct cache_entry *ce) if (ce->ce_flags & CE_HASHED) return; ce->ce_flags |= CE_HASHED; - ce->next = NULL; + ce->next = ce->dir_next = NULL; hash = hash_name(ce->name, ce_namelen(ce)); pos = insert_hash(hash, ce, &istate->name_hash); if (pos) { diff --git a/notes-merge.c b/notes-merge.c index e9e4199311..ce10aacf29 100644 --- a/notes-merge.c +++ b/notes-merge.c @@ -21,14 +21,6 @@ void init_notes_merge_options(struct notes_merge_options *o) o->verbosity = NOTES_MERGE_VERBOSITY_DEFAULT; } -#define OUTPUT(o, v, ...) \ - do { \ - if ((o)->verbosity >= (v)) { \ - printf(__VA_ARGS__); \ - puts(""); \ - } \ - } while (0) - static int path_to_sha1(const char *path, unsigned char *sha1) { char hex_sha1[40]; @@ -392,21 +384,26 @@ static int merge_one_change_manual(struct notes_merge_options *o, strbuf_addf(&(o->commit_msg), "\t%s\n", sha1_to_hex(p->obj)); - OUTPUT(o, 2, "Auto-merging notes for %s", sha1_to_hex(p->obj)); + if (o->verbosity >= 2) + printf("Auto-merging notes for %s\n", sha1_to_hex(p->obj)); check_notes_merge_worktree(o); if (is_null_sha1(p->local)) { /* D/F conflict, checkout p->remote */ assert(!is_null_sha1(p->remote)); - OUTPUT(o, 1, "CONFLICT (delete/modify): Notes for object %s " - "deleted in %s and modified in %s. Version from %s " - "left in tree.", sha1_to_hex(p->obj), lref, rref, rref); + if (o->verbosity >= 1) + printf("CONFLICT (delete/modify): Notes for object %s " + "deleted in %s and modified in %s. Version from %s " + "left in tree.\n", + sha1_to_hex(p->obj), lref, rref, rref); write_note_to_worktree(p->obj, p->remote); } else if (is_null_sha1(p->remote)) { /* D/F conflict, checkout p->local */ assert(!is_null_sha1(p->local)); - OUTPUT(o, 1, "CONFLICT (delete/modify): Notes for object %s " - "deleted in %s and modified in %s. Version from %s " - "left in tree.", sha1_to_hex(p->obj), rref, lref, lref); + if (o->verbosity >= 1) + printf("CONFLICT (delete/modify): Notes for object %s " + "deleted in %s and modified in %s. Version from %s " + "left in tree.\n", + sha1_to_hex(p->obj), rref, lref, lref); write_note_to_worktree(p->obj, p->local); } else { /* "regular" conflict, checkout result of ll_merge() */ @@ -415,8 +412,9 @@ static int merge_one_change_manual(struct notes_merge_options *o, reason = "add/add"; assert(!is_null_sha1(p->local)); assert(!is_null_sha1(p->remote)); - OUTPUT(o, 1, "CONFLICT (%s): Merge conflict in notes for " - "object %s", reason, sha1_to_hex(p->obj)); + if (o->verbosity >= 1) + printf("CONFLICT (%s): Merge conflict in notes for " + "object %s\n", reason, sha1_to_hex(p->obj)); ll_merge_in_worktree(o, p); } @@ -438,24 +436,30 @@ static int merge_one_change(struct notes_merge_options *o, case NOTES_MERGE_RESOLVE_MANUAL: return merge_one_change_manual(o, p, t); case NOTES_MERGE_RESOLVE_OURS: - OUTPUT(o, 2, "Using local notes for %s", sha1_to_hex(p->obj)); + if (o->verbosity >= 2) + printf("Using local notes for %s\n", + sha1_to_hex(p->obj)); /* nothing to do */ return 0; case NOTES_MERGE_RESOLVE_THEIRS: - OUTPUT(o, 2, "Using remote notes for %s", sha1_to_hex(p->obj)); + if (o->verbosity >= 2) + printf("Using remote notes for %s\n", + sha1_to_hex(p->obj)); if (add_note(t, p->obj, p->remote, combine_notes_overwrite)) die("BUG: combine_notes_overwrite failed"); return 0; case NOTES_MERGE_RESOLVE_UNION: - OUTPUT(o, 2, "Concatenating local and remote notes for %s", - sha1_to_hex(p->obj)); + if (o->verbosity >= 2) + printf("Concatenating local and remote notes for %s\n", + sha1_to_hex(p->obj)); if (add_note(t, p->obj, p->remote, combine_notes_concatenate)) die("failed to concatenate notes " "(combine_notes_concatenate)"); return 0; case NOTES_MERGE_RESOLVE_CAT_SORT_UNIQ: - OUTPUT(o, 2, "Concatenating unique lines in local and remote " - "notes for %s", sha1_to_hex(p->obj)); + if (o->verbosity >= 2) + printf("Concatenating unique lines in local and remote " + "notes for %s\n", sha1_to_hex(p->obj)); if (add_note(t, p->obj, p->remote, combine_notes_cat_sort_uniq)) die("failed to concatenate notes " "(combine_notes_cat_sort_uniq)"); @@ -518,8 +522,9 @@ static int merge_from_diffs(struct notes_merge_options *o, conflicts = merge_changes(o, changes, &num_changes, t); free(changes); - OUTPUT(o, 4, "Merge result: %i unmerged notes and a %s notes tree", - conflicts, t->dirty ? "dirty" : "clean"); + if (o->verbosity >= 4) + printf("Merge result: %i unmerged notes and a %s notes tree\n", + conflicts, t->dirty ? "dirty" : "clean"); return conflicts ? -1 : 1; } @@ -617,33 +622,40 @@ int notes_merge(struct notes_merge_options *o, if (!bases) { base_sha1 = null_sha1; base_tree_sha1 = EMPTY_TREE_SHA1_BIN; - OUTPUT(o, 4, "No merge base found; doing history-less merge"); + if (o->verbosity >= 4) + printf("No merge base found; doing history-less merge\n"); } else if (!bases->next) { base_sha1 = bases->item->object.sha1; base_tree_sha1 = bases->item->tree->object.sha1; - OUTPUT(o, 4, "One merge base found (%.7s)", - sha1_to_hex(base_sha1)); + if (o->verbosity >= 4) + printf("One merge base found (%.7s)\n", + sha1_to_hex(base_sha1)); } else { /* TODO: How to handle multiple merge-bases? */ base_sha1 = bases->item->object.sha1; base_tree_sha1 = bases->item->tree->object.sha1; - OUTPUT(o, 3, "Multiple merge bases found. Using the first " - "(%.7s)", sha1_to_hex(base_sha1)); + if (o->verbosity >= 3) + printf("Multiple merge bases found. Using the first " + "(%.7s)\n", sha1_to_hex(base_sha1)); } - OUTPUT(o, 4, "Merging remote commit %.7s into local commit %.7s with " - "merge-base %.7s", sha1_to_hex(remote->object.sha1), - sha1_to_hex(local->object.sha1), sha1_to_hex(base_sha1)); + if (o->verbosity >= 4) + printf("Merging remote commit %.7s into local commit %.7s with " + "merge-base %.7s\n", sha1_to_hex(remote->object.sha1), + sha1_to_hex(local->object.sha1), + sha1_to_hex(base_sha1)); if (!hashcmp(remote->object.sha1, base_sha1)) { /* Already merged; result == local commit */ - OUTPUT(o, 2, "Already up-to-date!"); + if (o->verbosity >= 2) + printf("Already up-to-date!\n"); hashcpy(result_sha1, local->object.sha1); goto found_result; } if (!hashcmp(local->object.sha1, base_sha1)) { /* Fast-forward; result == remote commit */ - OUTPUT(o, 2, "Fast-forward"); + if (o->verbosity >= 2) + printf("Fast-forward\n"); hashcpy(result_sha1, remote->object.sha1); goto found_result; } @@ -685,8 +697,9 @@ int notes_merge_commit(struct notes_merge_options *o, int path_len = strlen(path), i; const char *msg = strstr(partial_commit->buffer, "\n\n"); - OUTPUT(o, 3, "Committing notes in notes merge worktree at %.*s", - path_len - 1, path); + if (o->verbosity >= 3) + printf("Committing notes in notes merge worktree at %.*s\n", + path_len - 1, path); if (!msg || msg[2] == '\0') die("partial notes commit has empty message"); @@ -701,7 +714,9 @@ int notes_merge_commit(struct notes_merge_options *o, unsigned char obj_sha1[20], blob_sha1[20]; if (ent->len - path_len != 40 || get_sha1_hex(relpath, obj_sha1)) { - OUTPUT(o, 3, "Skipping non-SHA1 entry '%s'", ent->name); + if (o->verbosity >= 3) + printf("Skipping non-SHA1 entry '%s'\n", + ent->name); continue; } @@ -713,14 +728,16 @@ int notes_merge_commit(struct notes_merge_options *o, if (add_note(partial_tree, obj_sha1, blob_sha1, NULL)) die("Failed to add resolved note '%s' to notes tree", ent->name); - OUTPUT(o, 4, "Added resolved note for object %s: %s", - sha1_to_hex(obj_sha1), sha1_to_hex(blob_sha1)); + if (o->verbosity >= 4) + printf("Added resolved note for object %s: %s\n", + sha1_to_hex(obj_sha1), sha1_to_hex(blob_sha1)); } create_notes_commit(partial_tree, partial_commit->parents, msg, result_sha1); - OUTPUT(o, 4, "Finalized notes merge commit: %s", - sha1_to_hex(result_sha1)); + if (o->verbosity >= 4) + printf("Finalized notes merge commit: %s\n", + sha1_to_hex(result_sha1)); free(path); return 0; } @@ -732,7 +749,8 @@ int notes_merge_abort(struct notes_merge_options *o) int ret; strbuf_addstr(&buf, git_path(NOTES_MERGE_WORKTREE)); - OUTPUT(o, 3, "Removing notes merge worktree at %s", buf.buf); + if (o->verbosity >= 3) + printf("Removing notes merge worktree at %s\n", buf.buf); ret = remove_dir_recursively(&buf, 0); strbuf_release(&buf); return ret; diff --git a/perl/.gitignore b/perl/.gitignore index 98b24772c7..9235e73163 100644 --- a/perl/.gitignore +++ b/perl/.gitignore @@ -1,5 +1,6 @@ perl.mak perl.mak.old +MYMETA.yml blib blibdirs pm_to_blib @@ -1094,7 +1094,6 @@ void format_commit_message(const struct commit *commit, { struct format_commit_context context; static const char utf8[] = "UTF-8"; - const char *enc; const char *output_enc = pretty_ctx->output_encoding; memset(&context, 0, sizeof(context)); @@ -1103,10 +1102,13 @@ void format_commit_message(const struct commit *commit, context.wrap_start = sb->len; context.message = commit->buffer; if (output_enc) { - enc = get_header(commit, "encoding"); - enc = enc ? enc : utf8; - if (strcmp(enc, output_enc)) + char *enc = get_header(commit, "encoding"); + if (strcmp(enc ? enc : utf8, output_enc)) { context.message = logmsg_reencode(commit, output_enc); + if (!context.message) + context.message = commit->buffer; + } + free(enc); } strbuf_expand(sb, format, format_commit_item, &context); diff --git a/read-cache.c b/read-cache.c index 01a0e25051..5790a91044 100644 --- a/read-cache.c +++ b/read-cache.c @@ -1249,9 +1249,9 @@ static void convert_from_disk(struct ondisk_cache_entry *ondisk, struct cache_en static inline size_t estimate_cache_size(size_t ondisk_size, unsigned int entries) { - long per_entry; - - per_entry = sizeof(struct cache_entry) - sizeof(struct ondisk_cache_entry); + size_t fix_size_mem = offsetof(struct cache_entry, name); + size_t fix_size_dsk = offsetof(struct ondisk_cache_entry, name); + long per_entry = (fix_size_mem - fix_size_dsk + 7) & ~7; /* * Alignment can cause differences. This should be "alignof", but @@ -48,7 +48,7 @@ static const char *parse_ref_line(char *line, unsigned char *sha1) } static void add_ref(const char *name, const unsigned char *sha1, - int flag, struct ref_array *refs, + int flag, int check_name, struct ref_array *refs, struct ref_entry **new_entry) { int len; @@ -59,7 +59,8 @@ static void add_ref(const char *name, const unsigned char *sha1, entry = xmalloc(sizeof(struct ref_entry) + len); hashcpy(entry->sha1, sha1); hashclr(entry->peeled); - if (check_refname_format(name, REFNAME_ALLOW_ONELEVEL|REFNAME_DOT_COMPONENT)) + if (check_name && + check_refname_format(name, REFNAME_ALLOW_ONELEVEL|REFNAME_DOT_COMPONENT)) die("Reference has invalid format: '%s'", name); memcpy(entry->name, name, len); entry->flag = flag; @@ -234,7 +235,7 @@ static void read_packed_refs(FILE *f, struct ref_array *array) name = parse_ref_line(refline, sha1); if (name) { - add_ref(name, sha1, flag, array, &last); + add_ref(name, sha1, flag, 1, array, &last); continue; } if (last && @@ -249,7 +250,7 @@ static void read_packed_refs(FILE *f, struct ref_array *array) void add_extra_ref(const char *name, const unsigned char *sha1, int flag) { - add_ref(name, sha1, flag, &extra_refs, NULL); + add_ref(name, sha1, flag, 0, &extra_refs, NULL); } void clear_extra_refs(void) @@ -333,12 +334,11 @@ static void get_ref_dir(const char *submodule, const char *base, hashclr(sha1); flag |= REF_ISBROKEN; } - } else - if (!resolve_ref(ref, sha1, 1, &flag)) { - hashclr(sha1); - flag |= REF_ISBROKEN; - } - add_ref(ref, sha1, flag, array, NULL); + } else if (!resolve_ref(ref, sha1, 1, &flag)) { + hashclr(sha1); + flag |= REF_ISBROKEN; + } + add_ref(ref, sha1, flag, 1, array, NULL); } free(ref); closedir(dir); diff --git a/sequencer.h b/sequencer.h index 905d295012..f435fdb4b1 100644 --- a/sequencer.h +++ b/sequencer.h @@ -13,7 +13,7 @@ * * With the aggressive flag, it additionally removes SEQ_OLD_DIR, * ignoring any errors. Inteded to be used by the sequencer's - * '--reset' subcommand. + * '--quit' subcommand. */ void remove_sequencer_state(int aggressive); diff --git a/sha1_file.c b/sha1_file.c index 833f5b9b58..956422ba4a 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -2617,7 +2617,7 @@ static int index_mem(unsigned char *sha1, void *buf, size_t size, if ((type == OBJ_BLOB) && path) { struct strbuf nbuf = STRBUF_INIT; if (convert_to_git(path, buf, size, &nbuf, - write_object ? safe_crlf : 0)) { + write_object ? safe_crlf : SAFE_CRLF_FALSE)) { buf = strbuf_detach(&nbuf, &size); re_allocated = 1; } diff --git a/submodule.c b/submodule.c index 0fd10a0fdb..52cdcc6a63 100644 --- a/submodule.c +++ b/submodule.c @@ -391,7 +391,7 @@ static void commit_need_pushing(struct commit *commit, struct commit_list *paren rev.diffopt.format_callback_data = needs_pushing; diff_tree_combined(commit->object.sha1, parents, n, 1, &rev); - free(parents); + free((void *)parents); } int check_submodule_needs_pushing(unsigned char new_sha1[20], const char *remotes_name) diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh index 2f5eada0d2..bc73c2099b 100755 --- a/t/t3200-branch.sh +++ b/t/t3200-branch.sh @@ -75,6 +75,11 @@ test_expect_success \ git branch l' test_expect_success \ + 'git branch -m dumps usage' \ + 'test_expect_code 129 git branch -m 2>err && + grep "[Uu]sage: git branch" err' + +test_expect_success \ 'git branch -m m m/m should work' \ 'git branch -l m && git branch -m m m/m && diff --git a/t/t3507-cherry-pick-conflict.sh b/t/t3507-cherry-pick-conflict.sh index cb45574a7b..ee1659c178 100755 --- a/t/t3507-cherry-pick-conflict.sh +++ b/t/t3507-cherry-pick-conflict.sh @@ -253,6 +253,60 @@ test_expect_success 'revert also handles conflicts sanely' ' test_cmp expected actual ' +test_expect_success 'failed revert sets REVERT_HEAD' ' + pristine_detach initial && + test_must_fail git revert picked && + test_cmp_rev picked REVERT_HEAD +' + +test_expect_success 'successful revert does not set REVERT_HEAD' ' + pristine_detach base && + git revert base && + test_must_fail git rev-parse --verify CHERRY_PICK_HEAD && + test_must_fail git rev-parse --verify REVERT_HEAD +' + +test_expect_success 'revert --no-commit sets REVERT_HEAD' ' + pristine_detach base && + git revert --no-commit base && + test_must_fail git rev-parse --verify CHERRY_PICK_HEAD && + test_cmp_rev base REVERT_HEAD +' + +test_expect_success 'revert w/dirty tree does not set REVERT_HEAD' ' + pristine_detach base && + echo foo > foo && + test_must_fail git revert base && + test_must_fail git rev-parse --verify CHERRY_PICK_HEAD && + test_must_fail git rev-parse --verify REVERT_HEAD +' + +test_expect_success 'GIT_CHERRY_PICK_HELP does not suppress REVERT_HEAD' ' + pristine_detach initial && + ( + GIT_CHERRY_PICK_HELP="and then do something else" && + GIT_REVERT_HELP="and then do something else, again" && + export GIT_CHERRY_PICK_HELP GIT_REVERT_HELP && + test_must_fail git revert picked + ) && + test_must_fail git rev-parse --verify CHERRY_PICK_HEAD && + test_cmp_rev picked REVERT_HEAD +' + +test_expect_success 'git reset clears REVERT_HEAD' ' + pristine_detach initial && + test_must_fail git revert picked && + git reset && + test_must_fail git rev-parse --verify REVERT_HEAD +' + +test_expect_success 'failed commit does not clear REVERT_HEAD' ' + pristine_detach initial && + test_must_fail git revert picked && + test_must_fail git commit && + test_cmp_rev picked REVERT_HEAD +' + test_expect_success 'revert conflict, diff3 -m style' ' pristine_detach initial && git config merge.conflictstyle diff3 && diff --git a/t/t3510-cherry-pick-sequence.sh b/t/t3510-cherry-pick-sequence.sh index 3bca2b3dd5..2c4c1c851d 100755 --- a/t/t3510-cherry-pick-sequence.sh +++ b/t/t3510-cherry-pick-sequence.sh @@ -2,6 +2,7 @@ test_description='Test cherry-pick continuation features + + yetanotherpick: rewrites foo to e + anotherpick: rewrites foo to d + picked: rewrites foo to c + unrelatedpick: rewrites unrelated to reallyunrelated @@ -13,12 +14,18 @@ test_description='Test cherry-pick continuation features . ./test-lib.sh pristine_detach () { - git cherry-pick --reset && + git cherry-pick --quit && git checkout -f "$1^0" && git read-tree -u --reset HEAD && git clean -d -f -f -q -x } +test_cmp_rev () { + git rev-parse --verify "$1" >expect.rev && + git rev-parse --verify "$2" >actual.rev && + test_cmp expect.rev actual.rev +} + test_expect_success setup ' echo unrelated >unrelated && git add unrelated && @@ -27,6 +34,7 @@ test_expect_success setup ' test_commit unrelatedpick unrelated reallyunrelated && test_commit picked foo c && test_commit anotherpick foo d && + test_commit yetanotherpick foo e && git config advice.detachedhead false ' @@ -70,18 +78,117 @@ test_expect_success 'cherry-pick cleans up sequencer state upon success' ' test_path_is_missing .git/sequencer ' -test_expect_success '--reset does not complain when no cherry-pick is in progress' ' +test_expect_success '--quit does not complain when no cherry-pick is in progress' ' pristine_detach initial && - git cherry-pick --reset + git cherry-pick --quit ' -test_expect_success '--reset cleans up sequencer state' ' +test_expect_success '--abort requires cherry-pick in progress' ' + pristine_detach initial && + test_must_fail git cherry-pick --abort +' + +test_expect_success '--quit cleans up sequencer state' ' pristine_detach initial && test_must_fail git cherry-pick base..picked && - git cherry-pick --reset && + git cherry-pick --quit && test_path_is_missing .git/sequencer ' +test_expect_success '--quit keeps HEAD and conflicted index intact' ' + pristine_detach initial && + cat >expect <<-\EOF && + OBJID + :100644 100644 OBJID OBJID M unrelated + OBJID + :000000 100644 OBJID OBJID A foo + :000000 100644 OBJID OBJID A unrelated + EOF + test_must_fail git cherry-pick base..picked && + git cherry-pick --quit && + test_path_is_missing .git/sequencer && + test_must_fail git update-index --refresh && + { + git rev-list HEAD | + git diff-tree --root --stdin | + sed "s/$_x40/OBJID/g" + } >actual && + test_cmp expect actual +' + +test_expect_success '--abort to cancel multiple cherry-pick' ' + pristine_detach initial && + test_must_fail git cherry-pick base..anotherpick && + git cherry-pick --abort && + test_path_is_missing .git/sequencer && + test_cmp_rev initial HEAD && + git update-index --refresh && + git diff-index --exit-code HEAD +' + +test_expect_success '--abort to cancel single cherry-pick' ' + pristine_detach initial && + test_must_fail git cherry-pick picked && + git cherry-pick --abort && + test_path_is_missing .git/sequencer && + test_cmp_rev initial HEAD && + git update-index --refresh && + git diff-index --exit-code HEAD +' + +test_expect_success 'cherry-pick --abort to cancel multiple revert' ' + pristine_detach anotherpick && + test_must_fail git revert base..picked && + git cherry-pick --abort && + test_path_is_missing .git/sequencer && + test_cmp_rev anotherpick HEAD && + git update-index --refresh && + git diff-index --exit-code HEAD +' + +test_expect_success 'revert --abort works, too' ' + pristine_detach anotherpick && + test_must_fail git revert base..picked && + git revert --abort && + test_path_is_missing .git/sequencer && + test_cmp_rev anotherpick HEAD +' + +test_expect_success '--abort to cancel single revert' ' + pristine_detach anotherpick && + test_must_fail git revert picked && + git revert --abort && + test_path_is_missing .git/sequencer && + test_cmp_rev anotherpick HEAD && + git update-index --refresh && + git diff-index --exit-code HEAD +' + +test_expect_success '--abort keeps unrelated change, easy case' ' + pristine_detach unrelatedpick && + echo changed >expect && + test_must_fail git cherry-pick picked..yetanotherpick && + echo changed >unrelated && + git cherry-pick --abort && + test_cmp expect unrelated +' + +test_expect_success '--abort refuses to clobber unrelated change, harder case' ' + pristine_detach initial && + echo changed >expect && + test_must_fail git cherry-pick base..anotherpick && + echo changed >unrelated && + test_must_fail git cherry-pick --abort && + test_cmp expect unrelated && + git rev-list HEAD >log && + test_line_count = 2 log && + test_must_fail git update-index --refresh && + + git checkout unrelated && + git cherry-pick --abort && + test_cmp_rev initial HEAD +' + test_expect_success 'cherry-pick cleans up sequencer state when one commit is left' ' pristine_detach initial && test_must_fail git cherry-pick base..picked && @@ -106,6 +213,16 @@ test_expect_success 'cherry-pick cleans up sequencer state when one commit is le test_cmp expect actual ' +test_expect_failure '--abort after last commit in sequence' ' + pristine_detach initial && + test_must_fail git cherry-pick base..picked && + git cherry-pick --abort && + test_path_is_missing .git/sequencer && + test_cmp_rev initial HEAD && + git update-index --refresh && + git diff-index --exit-code HEAD +' + test_expect_success 'cherry-pick does not implicitly stomp an existing operation' ' pristine_detach initial && test_must_fail git cherry-pick base..anotherpick && diff --git a/t/t5501-fetch-push-alternates.sh b/t/t5501-fetch-push-alternates.sh index b5ced8483a..1bc57ac03f 100755 --- a/t/t5501-fetch-push-alternates.sh +++ b/t/t5501-fetch-push-alternates.sh @@ -28,7 +28,7 @@ test_expect_success setup ' done ) && ( - git clone --reference=original "file:///$(pwd)/original" one && + git clone --reference=original "file://$(pwd)/original" one && cd one && echo Z >count && git add count && diff --git a/t/t5700-clone-reference.sh b/t/t5700-clone-reference.sh index 895f5595ae..c4c375ac04 100755 --- a/t/t5700-clone-reference.sh +++ b/t/t5700-clone-reference.sh @@ -146,4 +146,11 @@ test_expect_success 'cloning with reference being subset of source (-l -s)' \ cd "$base_dir" +test_expect_success 'clone with reference from a tagged repository' ' + ( + cd A && git tag -a -m 'tagged' HEAD + ) && + git clone --reference=A A I +' + test_done diff --git a/t/t6030-bisect-porcelain.sh b/t/t6030-bisect-porcelain.sh index c6f1f9f8ab..691e4a4481 100755 --- a/t/t6030-bisect-porcelain.sh +++ b/t/t6030-bisect-porcelain.sh @@ -164,7 +164,7 @@ test_expect_success 'bisect start: existing ".git/BISECT_START" not modified if cp .git/BISECT_START saved && test_must_fail git bisect start $HASH4 foo -- && git branch > branch.output && - grep "* (no branch)" branch.output > /dev/null && + test_i18ngrep "* (no branch)" branch.output > /dev/null && test_cmp saved .git/BISECT_START ' test_expect_success 'bisect start: no ".git/BISECT_START" if mistaken rev' ' diff --git a/t/t7106-reset-sequence.sh b/t/t7106-reset-sequence.sh index 4956caaf82..83f7ea59c9 100755 --- a/t/t7106-reset-sequence.sh +++ b/t/t7106-reset-sequence.sh @@ -12,7 +12,7 @@ test_description='Test interaction of reset --hard with sequencer . ./test-lib.sh pristine_detach () { - git cherry-pick --reset && + git cherry-pick --quit && git checkout -f "$1^0" && git read-tree -u --reset HEAD && git clean -d -f -f -q -x @@ -41,4 +41,12 @@ test_expect_success 'reset --hard cleans up sequencer state, providing one-level test_path_is_missing .git/sequencer-old ' +test_expect_success 'cherry-pick --abort does not leave sequencer-old dir' ' + pristine_detach initial && + test_must_fail git cherry-pick base..anotherpick && + git cherry-pick --abort && + test_path_is_missing .git/sequencer && + test_path_is_missing .git/sequencer-old +' + test_done diff --git a/t/t7508-status.sh b/t/t7508-status.sh index 905255adf0..fc57b135c5 100755 --- a/t/t7508-status.sh +++ b/t/t7508-status.sh @@ -189,7 +189,7 @@ test_expect_success 'status with gitignore' ' # untracked EOF git status --ignored >output && - test_cmp expect output + test_i18ncmp expect output ' test_expect_success 'status with gitignore (nothing untracked)' ' @@ -247,7 +247,7 @@ test_expect_success 'status with gitignore (nothing untracked)' ' # untracked EOF git status --ignored >output && - test_cmp expect output + test_i18ncmp expect output ' rm -f .gitignore diff --git a/t/t7511-status-index.sh b/t/t7511-status-index.sh new file mode 100755 index 0000000000..b5fdc048a5 --- /dev/null +++ b/t/t7511-status-index.sh @@ -0,0 +1,50 @@ +#!/bin/sh + +test_description='git status with certain file name lengths' + +. ./test-lib.sh + +files="0 1 2 3 4 5 6 7 8 9 a b c d e f g h i j k l m n o p q r s t u v w x y z" + +check() { + len=$1 + prefix=$2 + + for i in $files + do + : >$prefix$i + done + + test_expect_success "status, filename length $len" " + git add $prefix* && + git status + " + rm $prefix* .git/index +} + +check 1 +check 2 p +check 3 px +check 4 pre +check 5 pref +check 6 prefi +check 7 prefix +check 8 prefix- +check 9 prefix-p +check 10 prefix-pr +check 11 prefix-pre +check 12 prefix-pref +check 13 prefix-prefi +check 14 prefix-prefix +check 15 prefix-prefix- +check 16 prefix-prefix-p +check 17 prefix-prefix-pr +check 18 prefix-prefix-pre +check 19 prefix-prefix-pref +check 20 prefix-prefix-prefi +check 21 prefix-prefix-prefix +check 22 prefix-prefix-prefix- +check 23 prefix-prefix-prefix-p +check 24 prefix-prefix-prefix-pr + +test_done diff --git a/t/t8006-blame-textconv.sh b/t/t8006-blame-textconv.sh index 32ec82ad67..4ee42f12f0 100755 --- a/t/t8006-blame-textconv.sh +++ b/t/t8006-blame-textconv.sh @@ -15,6 +15,7 @@ EOF chmod +x helper test_expect_success 'setup ' ' + echo "bin: test number 0" >zero.bin && echo "bin: test 1" >one.bin && echo "bin: test number 2" >two.bin && if test_have_prereq SYMLINKS; then @@ -43,6 +44,7 @@ test_expect_success 'no filter specified' ' test_expect_success 'setup textconv filters' ' echo "*.bin diff=test" >.gitattributes && + echo "zero.bin eol=crlf" >>.gitattributes && git config diff.test.textconv ./helper && git config diff.test.cachetextconv false ' @@ -74,6 +76,15 @@ test_expect_success 'blame --textconv going through revisions' ' test_cmp expected result ' +test_expect_success 'blame --textconv with local changes' ' + test_when_finished "git checkout zero.bin" && + printf "bin: updated number 0\015" >zero.bin && + git blame --textconv zero.bin >blame && + expect="(Not Committed Yet ....-..-.. ..:..:.. +0000 1)" && + expect="$expect converted: updated number 0" && + expr "$(find_blame <blame)" : "^$expect" +' + test_expect_success 'setup +cachetextconv' ' git config diff.test.cachetextconv true ' diff --git a/t/t9802-git-p4-filetype.sh b/t/t9802-git-p4-filetype.sh index 3b358ef8d8..992bb8cf0b 100755 --- a/t/t9802-git-p4-filetype.sh +++ b/t/t9802-git-p4-filetype.sh @@ -101,6 +101,37 @@ test_expect_success 'keyword file test' ' ) ' +build_gendouble() { + cat >gendouble.py <<-\EOF + import sys + import struct + import array + + s = array.array("c", '\0' * 26) + struct.pack_into(">L", s, 0, 0x00051607) # AppleDouble + struct.pack_into(">L", s, 4, 0x00020000) # version 2 + s.tofile(sys.stdout) + EOF +} + +test_expect_success 'ignore apple' ' + test_when_finished rm -f gendouble.py && + build_gendouble && + ( + cd "$cli" && + test-genrandom apple 1024 >double.png && + "$PYTHON_PATH" "$TRASH_DIRECTORY/gendouble.py" >%double.png && + p4 add -t apple double.png && + p4 submit -d appledouble + ) && + test_when_finished cleanup_git && + "$GITP4" clone --dest="$git" //depot@all && + ( + cd "$git" && + test ! -f double.png + ) +' + test_expect_success 'kill p4d' ' kill_p4d ' |