completion: add new zsh completion

It seems there's always issues with zsh's bash completion emulation.
I've tried to fix as many as I could[1], and most of the fixes are already
in the latest version of zsh, but still, there are issues.

There is no point going through all that pain; the emulation is easy to
achieve, and this patch works better than zsh's bash completion
emulation.

[1] http://zsh.git.sourceforge.net/git/gitweb.cgi?p=zsh/zsh;a=commitdiff;h=23907bb840c80eef99eabba17e086e44c9b2d3fc

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
completion: start moving to the new zsh completion

Zsh's bash completion emulation is buggy, not properly maintained, and
we have some workarounds in place for different bugs that appeared in
various versions.

Since I'm the only one that has worked on that code lately[1], it might make
snese to use the code I wrote specifically for git.

The advantages are:

 1) Less workarounds

   * No need to hack __get_comp_words_by_ref
   * No need to hack IFS or words

 2) Improved features

   * 'git show master' now properly adds a space at the end (IFS bug)
   * 'git checkout --conflict=' now properly returns the sub-items
     (missing feature)

 3) Consolidated code

   * It's all now in a single chunk, and it's basically the same as
     git-completion.zsh

Since there's some interest in moving the zsh-specific code out of this
script, lets go ahead and warn the users that they should be using
git-completion.zsh.

[1] http://zsh.git.sourceforge.net/git/gitweb.cgi?p=zsh/zsh;a=history;f=Completion/bashcompinit

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
push: add advice for rejected tag reference

Advising the user to fetch and merge only makes sense if the rejected
reference is a branch.  If none of the rejections were for branches,
tell the user they need to force the update(s).

Signed-off-by: Chris Rorvick <chris@rorvick.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
push: keep track of "update" state separately

If the reference exists on the remote and the the update is not a
delete, then mark as an update.  This is in preparation for handling
tags and branches differently when pushing.

Signed-off-by: Chris Rorvick <chris@rorvick.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
push: flag updates that require force

Add a flag for indicating an update to a reference requires force.
Currently the nonfastforward flag of a ref is used for this when
generating status the status message.  A separate flag insulates the
status logic from the details of set_ref_status_for_push().

Signed-off-by: Chris Rorvick <chris@rorvick.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
push: update remote tags only with force

References are allowed to update from one commit-ish to another if the
former is a ancestor of the latter.  This behavior is oriented to
branches which are expected to move with commits.  Tag references are
expected to be static in a repository, though, thus an update to a
tag (lightweight and annotated) should be rejected unless the update is
forced.

To enable this functionality, the following checks have been added to
set_ref_status_for_push() for updating refs (i.e, not new or deletion)
to restrict fast-forwarding in pushes:

  1) The old and new references must be commits.  If this fails,
     it is not a valid update for a branch.

  2) The reference name cannot start with "refs/tags/".  This
     catches lightweight tags which (usually) point to commits
     and therefore would not be caught by (1).

If either of these checks fails, then it is flagged (by default) with a
status indicating the update is being rejected due to the reference
already existing in the remote.  This can be overridden by passing
--force to git push.

Signed-off-by: Chris Rorvick <chris@rorvick.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
pathspec: save the non-wildcard length part

We mark pathspec with wildcards with the field use_wildcard. We
could do better by saving the length of the non-wildcard part, which
can be used for optimizations such as f9f6e2c (exclude: do strcmp as
much as possible before fnmatch - 2012-06-07).

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
pathspec: do exact comparison on the leading non-wildcard part

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
pathspec: apply "*.c" optimization from exclude

When a pattern contains only a single asterisk, e.g. "foo*bar",
after literally comparing the leading part "foo" with the string, we
can compare the tail of the string and make sure it matches "bar",
instead of running fnmatch() on "*bar" against the remainder of the
string.

-O2 build on linux-2.6, without the patch:

$ time git rev-list --quiet HEAD -- '*.c'

real    0m40.770s
user    0m40.290s
sys     0m0.256s

With the patch

$ time ~/w/git/git rev-list --quiet HEAD -- '*.c'

real    0m34.288s
user    0m33.997s
sys     0m0.205s

The above command is not supposed to be widely popular. It's chosen
because it exercises pathspec matching a lot. The point is it cuts
down matching time for popular patterns like *.c, which could be used
as pathspec in other places.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
tree_entry_interesting: do basedir compare on wildcard patterns when possible

Currently we treat "*.c" and "path/to/*.c" the same way. Which means
we check all possible paths in repo against "path/to/*.c". One could
see that "path/elsewhere/foo.c" obviously cannot match "path/to/*.c"
and we only need to check all paths _inside_ "path/to/" against that
pattern.

This patch checks the leading fixed part of a pathspec against base
directory and exit early if possible. We could even optimize further
in "path/to/something*.c" case (i.e. check the fixed part against
name_entry as well) but that's more complicated and probably does not
gain us much.

-O2 build on linux-2.6, without and with this patch respectively:

$ time git rev-list --quiet HEAD -- 'drivers/*.c'

real    1m9.484s
user    1m9.128s
sys     0m0.181s

$ time ~/w/git/git rev-list --quiet HEAD -- 'drivers/*.c'

real    0m15.710s
user    0m15.564s
sys     0m0.107s

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Merge branch 'so/prompt-command' into jch

Updates __git_ps1 so that it can be used as $PROMPT_COMMAND,
instead of being used for command substitution in $PS1, to embed
color escape sequences in its output.

Will cook in 'next'.

* so/prompt-command:
  coloured git-prompt: paint detached HEAD marker in red
  Fix up colored git-prompt
  show color hints based on state of the git tree
  Allow __git_ps1 to be used in PROMPT_COMMAND
Merge branch 'nd/wildmatch' into jch

Allows pathname patterns in .gitignore and .gitattributes files
with double-asterisks "foo/**/bar" to match any number of directory
hierarchies.

I suspect that this needs to be plugged to pathspec matching code;
otherwise "git log -- 'Docum*/**/*.txt'" would not show the log for
commits that touch Documentation/git.txt, which would be confusing
to the users.

Will cook in 'next'.

* nd/wildmatch:
  Support "**" wildcard in .gitignore and .gitattributes
  wildmatch: make /**/ match zero or more directories
  wildmatch: adjust "**" behavior
  wildmatch: fix case-insensitive matching
  wildmatch: remove static variable force_lower_case
  wildmatch: make wildmatch's return value compatible with fnmatch
  t3070: disable unreliable fnmatch tests
  Integrate wildmatch to git
  wildmatch: follow Git's coding convention
  wildmatch: remove unnecessary functions
  Import wildmatch from rsync
  ctype: support iscntrl, ispunct, isxdigit and isprint
  ctype: make sane_ctype[] const array

Conflicts:
	Makefile
Merge branch 'wtk/submodule-doc-fixup' into jch

* wtk/submodule-doc-fixup:
  git-submodule: wrap branch option with "<>" in usage strings.

Conflicts:
	Documentation/git-submodule.txt
	git-submodule.sh
Merge branch 'jk/config-ignore-duplicates' into jch

Drop duplicate detection from git-config; this lets it
better match the internal config callbacks, which clears up
some corner cases with includes.

Will merge to 'master' in the sixth batch.

* jk/config-ignore-duplicates:
  builtin/config.c: Fix a sparse warning
  git-config: use git_config_with_options
  git-config: do not complain about duplicate entries
  git-config: collect values instead of immediately printing
  git-config: fix regexp memory leaks on error conditions
  git-config: remove memory leak of key regexp
  t1300: test "git config --get-all" more thoroughly
  t1300: remove redundant test
  t1300: style updates
Merge branch 'rc/maint-complete-git-p4' into jch

Comment from Pete will need to be addressed in a follow-up patch.

* rc/maint-complete-git-p4:
  Teach git-completion about git p4
Merge branch 'jk/maint-http-half-auth-fetch' into jch

Fixes fetch from servers that ask for auth only during the actual
packing phase. This is not really a recommended configuration, but it
cleans up the code at the same time.

Will merge to 'master' in the sixth batch.

* jk/maint-http-half-auth-fetch:
  remote-curl: retry failed requests for auth even with gzip
  remote-curl: hoist gzip buffer size to top of post_rpc

Conflicts:
	t/t5551-http-fetch.sh
Merge branch 'kb/preload-index-more' into jch

Use preloadindex in more places, which has a nice speedup on systems
with slow stat calls (and even on Linux).

Will merge to 'master' in the sixth batch.

* kb/preload-index-more:
  update-index/diff-index: use core.preloadindex to improve performance
Merge branch 'ta/doc-cleanup' into jch

Will merge to 'master' in the sixth batch.

* ta/doc-cleanup:
  Documentation: build html for all files in technical and howto
  Documentation/howto: convert plain text files to asciidoc
  Documentation/technical: convert plain text files to asciidoc
  Change headline of technical/send-pack-pipeline.txt to not confuse its content with content from git-send-pack.txt
  Shorten two over-long lines in git-bisect-lk2009.txt by abbreviating some sha1
  Split over-long synopsis in git-fetch-pack.txt into several lines
Merge branch 'mh/alt-odb-string-list-cleanup' into jch

Cleanups in the alternates code. Fixes a potential bug and makes the
code much cleaner.

Will merge to 'master' in the sixth batch.

* mh/alt-odb-string-list-cleanup:
  link_alt_odb_entries(): take (char *, len) rather than two pointers
  link_alt_odb_entries(): use string_list_split_in_place()
Merge branch 'pw/maint-p4-rcs-expansion-newline' into jch

I do not have p4 to play with, but looks obviously correct to me.

Will merge to 'master' in the sixth batch.

* pw/maint-p4-rcs-expansion-newline:
  git p4: RCS expansion should not span newlines