Commit graph

1992 commits

Author SHA1 Message Date
Jonathan Nieder 1e88f7a277 hooks/post-receive-email: use plumbing instead of git log/show
This way the hook doesn't have to keep being tweaked as porcelain
learns new features like color and pagination.

While at it, replace the "git rev-list | git shortlog" idiom with
plain "git shortlog" for simplicity.

Except for depending less on the value of settings like '[log]
abbrevCommit', no change in output intended.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-08-05 10:17:35 -07:00
Junio C Hamano d6cbf2fa7a Merge branch 'rj/cygwin-clarify-use-of-cheating-lstat'
Cygwin port added a "not quite correct but a lot faster and good
enough for many lstat() calls that are only used to see if the
working tree entity matches the index entry" lstat() emulation some
time ago, and it started biting us in places.  This removes it and
uses the standard lstat() that comes with Cygwin.

Recent topic that uses lstat on packed-refs file is broken when
this cheating lstat is used, and this is a simplest fix that is
also the cleanest direction to go in the long run.

* rj/cygwin-clarify-use-of-cheating-lstat:
  cygwin: Remove the Win32 l/stat() implementation
2013-08-02 11:01:01 -07:00
Junio C Hamano d50cb7569c Merge branch 'ob/typofixes'
* ob/typofixes:
  many small typofixes
2013-08-01 12:01:01 -07:00
Junio C Hamano 898bbe9664 Merge branch 'ms/subtree-install-fix'
* ms/subtree-install-fix:
  contrib/subtree: Fix make install target
2013-08-01 11:57:25 -07:00
Junio C Hamano a5203a3f04 Merge branch 'lf/echo-n-is-not-portable'
* lf/echo-n-is-not-portable:
  Avoid using `echo -n` anywhere
2013-08-01 11:52:43 -07:00
Junio C Hamano 400bf4c46b Merge branch 'ma/hg-to-git'
* ma/hg-to-git:
  hg-to-git: --allow-empty-message in git commit
2013-08-01 11:52:40 -07:00
Junio C Hamano 1ddc11a6fd Merge branch 'bc/completion-for-bash-3.0'
* bc/completion-for-bash-3.0:
  git-completion.bash: replace zsh notation that breaks bash 3.X
2013-07-30 09:16:37 -07:00
Michal Sojka 8e943c248a contrib/subtree: Fix make install target
If the libexec directory doesn't exist, git-subtree gets installed as
$prefix/share/libexec/git-core file. This patch creates the directory
before installing git-subtree file into it.

Signed-off-by: Michal Sojka <sojkam1@fel.cvut.cz>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-07-30 07:50:23 -07:00
Ondřej Bílka 98e023dea4 many small typofixes
Signed-off-by: Ondřej Bílka <neleai@seznam.cz>
Reviewed-by: Marc Branchaud <marcnarc@xiplink.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-07-29 12:32:25 -07:00
Lukas Fleischer 19c3c5fdcb Avoid using echo -n anywhere
`echo -n` is non-portable. The POSIX specification says:

    Conforming applications that wish to do prompting without <newline>
    characters or that could possibly be expecting to echo a -n, should
    use the printf utility derived from the Ninth Edition system.

Since all of the affected shell scripts use a POSIX shell shebang,
replace `echo -n` invocations with printf.

Signed-off-by: Lukas Fleischer <git@cryptocrack.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-07-29 09:56:58 -07:00
Junio C Hamano 9e8a901e6b Merge branch 'mh/multimail'
An enhanced "post-receive" hook to send e-mail messages.

* mh/multimail:
  post-receive-email: deprecate script in favor of git-multimail
  git-multimail: an improved replacement for post-receive-email
2013-07-24 19:23:03 -07:00
Junio C Hamano 4274cdf44a Merge branch 'es/contacts'
A helper to read from a set of format-patch output files or a range
of commits and find those who may have insights to the code that
the changes touch by running a series of "git blame" commands.

* es/contacts:
  contrib: contacts: add documentation
  contrib: contacts: add mailmap support
  contrib: contacts: interpret committish akin to format-patch
  contrib: contacts: add ability to parse from committish
  contrib: add git-contacts helper
2013-07-24 19:22:58 -07:00
Brandon Casey e78095c3d0 git-completion.bash: replace zsh notation that breaks bash 3.X
50c5885e (git-completion.bash: replace zsh notation that breaks bash
3.X, 2013-01-18) fixed a zsh-ism introduced earlier to append to an
array, which older versions of bash (3.0) did not grok.  This was
again broken by 734b2f05 (completion: synchronize zsh wrapper,
2013-05-08).

Cherry-pick the fix again to let those with older bash use the
completion script.

Signed-off-by: Brandon Casey <drafnel@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-07-24 08:45:49 -07:00
Maurício C Antunes 1611eed6e5 hg-to-git: --allow-empty-message in git commit
Do not fail to import mercurial commits with empty commit messages.

Signed-off-by: Maurício C Antunes <mauricio.antunes@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-07-23 12:17:23 -07:00
Michael Haggerty 1d25e7746d post-receive-email: deprecate script in favor of git-multimail
Add a notice to the top of post-receive-email explaining that the
script is no longer under active development and pointing the user to
git-multimail.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-07-22 21:20:28 -07:00
Junio C Hamano e683889b75 Merge branch 'es/check-mailmap'
A new command to allow scripts to query the mailmap information.

* es/check-mailmap:
  t4203: test check-mailmap command invocation
  builtin: add git-check-mailmap command
2013-07-22 11:24:14 -07:00
Eric Sunshine acb01a359b contrib: contacts: add documentation
Assuming that git-contacts may some day be promoted to a core git
command, the documentation is written and formatted as if it already
belongs in Documentation/ even though it presently resides in
contrib/contacts.

Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-07-21 15:15:20 -07:00
Eric Sunshine 7c6d6ff8f1 contrib: contacts: add mailmap support
The purpose of git-contacts is to determine a list of people who might
have some interest in a patch or set of changes. It can be used as
git-send-email's --cc-cmd argument or the computed list might be used to
ask for comments on a proposed change.  As such, it is important to
report up-to-date email addresses in the computed list rather than
potentially outdated ones recorded with commits.  Apply git's mailmap
functionality to the retrieved contacts in order to achieve this goal.

Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-07-21 15:14:43 -07:00
Eric Sunshine ccf6b45aff contrib: contacts: interpret committish akin to format-patch
As a convenience, accept the same style <since> committish as accepted
by git-format-patch. For example:

  % git contacts origin

will consider commits in the current branch built atop 'origin', just as
"git format-patch origin" will format commits built atop 'origin'.

Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-07-21 15:13:42 -07:00
Eric Sunshine 8e7c4a82ec contrib: contacts: add ability to parse from committish
For example:

  % git contacts R1..R2

Committishes and patch files can be mentioned in the same invocation:

  % git contacts R1..R2 extra/*.patch

Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-07-21 15:13:16 -07:00
Eric Sunshine 4d06402b1b contrib: add git-contacts helper
This script lists people that might be interested in a patch by going
back through the history for each patch hunk, and finding people that
reviewed, acknowledged, signed, authored, or were Cc:'d on the code the
patch is modifying.

It does this by running git-blame incrementally on each hunk and then
parsing the commit message. After gathering all participants, it
determines each person's relevance by considering how many commits
mentioned that person compared with the total number of commits under
consideration. The final output consists only of participants who pass a
minimum threshold of participation.

Several conditions controlling a person's significance are currently
hard-coded, such as minimum participation level, blame date-limiting,
and -C level for detecting moved and copied lines. In the future, these
conditions may become configurable.

For example:

  % git contacts 0001-remote-hg-trivial-cleanups.patch
  Felipe Contreras <felipe.contreras@gmail.com>
  Jeff King <peff@peff.net>
  Max Horn <max@quendi.de>
  Junio C Hamano <gitster@pobox.com>

Thus, it can be invoked as git-send-email's --cc-cmd option, among other
possible uses.

This is a Perl rewrite of Felipe Contreras' git-related patch series[1]
written in Ruby.

[1]: http://thread.gmane.org/gmane.comp.version-control.git/226065/

Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-07-21 15:12:30 -07:00
Junio C Hamano b12aecda2c Merge branch 'bp/mediawiki-preview'
Add a command to allow previewing the contents locally before
pushing it out, when working with a MediaWiki remote.

I personally do not think this belongs to Git.  If you are working
on a set of AsciiDoc source files, you sure do want to locally
format to preview what you will be pushing out, and if you are
working on a set of C or Java source files, you do want to test it
before pushing it out, too.  That kind of thing belongs to your
build script, not to your SCM.

But I'll let it pass, as this is only a contrib/ thing.

* bp/mediawiki-preview:
  git-remote-mediawiki: add preview subcommand into git mw
  git-remote-mediawiki: add git-mw command
  git-remote-mediawiki: factoring code between git-remote-mediawiki and Git::Mediawiki
  git-remote-mediawiki: update tests to run with the new bin-wrapper
  git-remote-mediawiki: add a git bin-wrapper for developement
  wrap-for-bin: make bin-wrappers chainable
  git-remote-mediawiki: introduction of Git::Mediawiki.pm
2013-07-18 12:59:34 -07:00
Ramsay Jones f66450ae94 cygwin: Remove the Win32 l/stat() implementation
Commit adbc0b6b ("cygwin: Use native Win32 API for stat", 30-09-2008)
added a Win32 specific implementation of the stat functions. In order
to handle absolute paths, cygwin mount points and symbolic links, this
implementation may fall back on the standard cygwin l/stat() functions.
Also, the choice of cygwin or Win32 functions is made lazily (by the
first call(s) to l/stat) based on the state of some config variables.

Unfortunately, this "schizophrenic stat" implementation has been the
source of many problems ever since. For example, see commits 7faee6b8,
79748439, 452993c2, 085479e7, b8a97333, 924aaf3e, 05bab3ea and 0117c2f0.

In order to avoid further problems, such as the issue raised by the new
reference handling API, remove the Win32 l/stat() implementation.

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-07-18 10:44:17 -07:00
Michael Haggerty bc501f69fc git-multimail: an improved replacement for post-receive-email
Add git-multimail, a tool for generating notification emails for
pushes to a Git repository.  It is largely plug-in compatible with
post-receive-email, and is proposed to eventually replace that script.
The advantages of git-multimail relative to post-receive-email are
described in README.migrate-from-post-receive-email.

git-multimail is organized in a directory contrib/hooks/multimail.
The directory contains:

* git_multimail.py -- a Python module that can generate notification
  emails for pushes to a Git repository.  The file can be used
  directly as a post-receive script (configured via git config
  settings), or it can be imported as a Python module and configured
  via arbitrary Python code.

* README -- user-level documentation for configuring and using
  git-multimail.

* post-receive -- an example of building a post-receive script that
  imports git_multimail.py as a Python module, with an example of how
  to change the email templates.

* README.migrate-from-post-receive-email -- documentation targeted at
  current users of post-receive-email, explaining the differences and
  how to migrate a post-receive-email configuration to git-multimail.

* migrate-mailhook-config -- a script that can migrate a user's
  post-receive-email configuration options to the equivalent
  git-multimail options.

* README.Git -- a short explanation of the relationship between
  git-multimail and the rest of the Git project, plus the exact date
  and revision when this version was taken from the upstream project.

All but the last file are taken verbatim from the upstream
git-multimail project.

git-multimail is originally derived from post-receive-email and also
incorporates suggestions from the mailing list as well as patches by
the people listed below.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Contributions-by: Matthieu Moy <Matthieu.Moy@imag.fr>
Contributions-by: Ramkumar Ramachandra <artagnon@gmail.com>
Contributions-by: Chris Hiestand <chrishiestand@gmail.com>
Contributions-by: Michiel Holtkamp <git@elfstone.nl>
Contributions-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-07-15 12:59:48 -07:00
Eric Sunshine 226ad3482a builtin: add git-check-mailmap command
Introduce command check-mailmap, similar to check-attr and check-ignore,
which allows direct testing of .mailmap configuration.

As plumbing accessible to scripts and other porcelain, check-mailmap
publishes the stable, well-tested .mailmap functionality employed by
built-in Git commands.  Consequently, script authors need not
re-implement .mailmap functionality manually, thus avoiding potential
quirks and behavioral differences.

Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-07-13 10:19:37 -07:00
Junio C Hamano 04ce89389d Merge branch 'jk/bash-completion'
* jk/bash-completion:
  completion: learn about --man-path
  completion: handle unstuck form of base git options
2013-07-11 13:05:28 -07:00
Benoit Person 0078a7fa05 git-remote-mediawiki: add preview subcommand into git mw
In the current state, a user of git-remote-mediawiki can edit the markup text
locally, but has to push to the remote wiki to see how the page is rendererd.
Add a new 'git mw preview' command that allows rendering the markup text on
the remote wiki without actually pushing any change on the wiki.

This uses Mediawiki's API to render the markup and inserts it in an actual
HTML page from the wiki so that CSS can be rendered properly. Most links
should work when the page exists on the remote.

Signed-off-by: Benoit Person <benoit.person@ensimag.fr>
Signed-off-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-07-08 08:56:14 -07:00
Benoit Person 07a263b905 git-remote-mediawiki: add git-mw command
For now, git-remote-mediawiki is only a remote-helper. This patch adds a new
toolset script in which we will be able to build new tools for
git-remote-mediawiki.

This toolset uses a subcommand-mechanism to launch the proper action. For now
only the 'help' subcommand is implemented. It also provides some generic code
for the verbose and help command line options.

Signed-off-by: Benoit Person <benoit.person@ensimag.fr>
Signed-off-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-07-08 08:56:08 -07:00
Benoit Person 192f7a0804 git-remote-mediawiki: factoring code between git-remote-mediawiki and Git::Mediawiki
For now, Git::Mediawiki contains nothing.

This first patch moves some of git-remote-mediawiki.perl's factorisable code
into Git::Mediawiki. In the same time, it removes the side effects of that code
and renames the fucntions and constants moved to expose a better API.

Signed-off-by: Benoit Person <benoit.person@ensimag.fr>
Signed-off-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-07-08 08:56:00 -07:00
Benoit Person c7956f9084 git-remote-mediawiki: update tests to run with the new bin-wrapper
Until now, if git-remote-mediawiki was not installed, the test suite
copied it to the toplevel directory. This solution pollutes the
directory with untracked files. Plus, we would need to copy the new
git-mw.perl file to test it too.

Signed-off-by: Benoit Person <benoit.person@ensimag.fr>
Signed-off-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-07-08 08:55:56 -07:00
Benoit Person 8a7c215140 git-remote-mediawiki: add a git bin-wrapper for developement
The introduction of the Git::Mediawiki package makes it impossible to test,
without installation, git-remote-mediawiki and git-mw.

Using a git bin-wrapper enables us to define proper $GITPERLLIB to force the
use of the developement version of the Git::Mediawiki package, bypassing its
installed version if any.

An alternate solution was to 'install' all the files required at each build
but it pollutes the toplevel with untracked files.

Signed-off-by: Benoit Person <benoit.person@ensimag.fr>
Signed-off-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-07-08 08:55:53 -07:00
Benoit Person e19189060f git-remote-mediawiki: introduction of Git::Mediawiki.pm
We would want to allow the user to preview what he has edited locally
before pushing it out (and thus creating a non-removable revision in
the mediawiki's history).

This patch introduces a new perl package in which we will be able to
share code between that new tool and the remote helper:
git-remote-mediawiki.perl.

A perl package offers the best way to handle such case: Each script
can select what should be imported in its namespace.  The package
namespacing limits the use of side effects in the shared code.

An alternate solution is to concatenate a "toolset" file with each
*.perl when 'make'-ing the project. In that scheme, everything is
imported in the script's namespace. Plus, files should be renamed in
order to chain to Git's toplevel makefile. Hence, this solution is not
acceptable.

Signed-off-by: Benoit Person <benoit.person@ensimag.fr>
Signed-off-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-07-08 08:55:21 -07:00
Junio C Hamano a256a58081 Merge branch 'dm/unbash-subtree' into maint
* dm/unbash-subtree:
  contrib/git-subtree: Use /bin/sh interpreter instead of /bin/bash
2013-07-03 15:39:37 -07:00
Matthieu Moy 0e7c41c0cd git-remote-mediawiki: un-brace file handles in binmode calls
Commit e83d36b66f turned "print STDOUT" into "print {*STDOUT}", as
suggested by perlcritic. Unfortunately, it also changed two "binmode
STDOUT" calls the same way, which does not work and yield a "Not a GLOB
reference" error.

Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-07-03 12:10:13 -07:00
Junio C Hamano 46b045917c Merge branch 'ed/color-prompt'
Code clean-up for in-prompt status script (in contrib/).

* ed/color-prompt:
  git-prompt.sh: add missing information in comments
  git-prompt.sh: do not print duplicate clean color code
  t9903: remove redundant tests
  git-prompt.sh: refactor colored prompt code
  t9903: add tests for git-prompt pcmode
2013-07-01 12:41:55 -07:00
John Keeping 66fb37d0c6 completion: learn about --man-path
Signed-off-by: John Keeping <john@keeping.me.uk>
Acked-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-06-30 15:59:10 -07:00
John Keeping 776009d1b2 completion: handle unstuck form of base git options
git-completion.bash's parsing of the command name relies on everything
preceding it starting with '-' unless it is the "-c" option.  This
allows users to use the stuck form of "--work-tree=<path>" and
"--namespace=<path>" but not the unstuck forms "--work-tree <path>" and
"--namespace <path>".  Fix this.

Similarly, the completion only handles the stuck form "--git-dir=<path>"
and not "--git-dir <path>", so fix this as well.

Signed-off-by: John Keeping <john@keeping.me.uk>
Acked-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-06-30 15:58:25 -07:00
Junio C Hamano c9cae1e28a Merge branch 'fc/show-branch-in-rebase-am' into maint
* fc/show-branch-in-rebase-am:
  prompt: fix for simple rebase
2013-06-27 14:38:16 -07:00
Junio C Hamano f79467ef36 Merge branch 'tg/maint-zsh-svn-remote-prompt' into maint
* tg/maint-zsh-svn-remote-prompt:
  prompt: fix show upstream with svn and zsh
2013-06-27 14:38:14 -07:00
Junio C Hamano 7f3447cce8 Merge branch 'jk/subtree-do-not-push-if-split-fails' into maint
* jk/subtree-do-not-push-if-split-fails:
  contrib/subtree: don't delete remote branches if split fails
2013-06-27 14:37:44 -07:00
Eduardo R. D'Avila cf4cac4cfc git-prompt.sh: add missing information in comments
Mention that the command below is needed for prompt
in ZSH with PS1:
  setopt PROMPT_SUBST

Rephrase some parts that mention only the "current branch name"
being displayed in the prompt. Replace it by stating that
the "repository status" is displayed.

Make it clear that colored prompt is only available
in PROMPT_COMMAND/precmd mode.

With-suggestions-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: Eduardo R. D'Avila <erdavila@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-06-26 13:03:01 -07:00
Eduardo R. D'Avila 15981f4eec git-prompt.sh: do not print duplicate clean color code
Do not print a duplicate clean color code when there
is no other indicators other than the current branch
in colored prompt.

Acked-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: Eduardo R. D'Avila <erdavila@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-06-26 13:03:01 -07:00
Eduardo R. D'Avila 7fe9031920 git-prompt.sh: refactor colored prompt code
__git_ps1_colorize_gitstring() sets color codes and
builds the prompt gitstring. It has duplicated code
to handle color codes for bash and zsh shells.
__git_ps1() also has duplicated logic to build the
prompt gitstring.

Remove duplication of logic to build gitstring in
__git_ps1_colorize_gitstring() and __git_ps1().

Leave in __git_ps1_colorize_gitstring() only logic
to set color codes.

Signed-off-by: Eduardo R. D'Avila <erdavila@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-06-26 13:02:57 -07:00
SZEDER Gábor a694258457 bash prompt: mention that PROMPT_COMMAND mode is faster
__git_ps1() is usually added to the prompt inside a command
substitution, imposing the overhead of fork()ing a subshell.  Using
__git_ps1() for $PROMPT_COMMAND is slightly faster, because it avoids
that command substitution.

Mention this in the comments about setting up the git prompt.

The whole series speeds up the bash prompt on Windows/MSysGit
considerably.  Here are some timing results in three scenarios, each
repeated 10 times:

At the top of the work tree, before:

    $ time for i in {0..9} ; do prompt="$(__git_ps1)" ; done

    real    0m1.716s
    user    0m0.301s
    sys     0m0.772s

  After:

    real    0m0.687s
    user    0m0.075s
    sys     0m0.396s

  After, from $PROMPT_COMMAND:

    $ time for i in {0..9} ; do __git_ps1 '\h:\w' '$ ' ; done

    real    0m0.546s
    user    0m0.075s
    sys     0m0.181s

At the top of the work tree, detached head, before:

    real    0m2.574s
    user    0m0.376s
    sys     0m1.207s

  After:

    real    0m1.139s
    user    0m0.151s
    sys     0m0.500s

  After, from $PROMPT_COMMAND:

    real    0m1.030s
    user    0m0.245s
    sys     0m0.336s

In a subdirectory, during rebase, stash status indicator enabled,
before:

    real    0m3.557s
    user    0m0.495s
    sys     0m1.767s

  After:

    real    0m0.717s
    user    0m0.120s
    sys     0m0.300s

  After, from $PROMPT_COMMAND:

    real    0m0.577s
    user    0m0.047s
    sys     0m0.258s

On Linux the speedup ratio is comparable to Windows, but overall it
was about an order of magnitude faster to begin with.  The last case
from above, repeated 100 times, before:

    $ time for i in {0..99} ; do prompt="$(__git_ps1)" ; done

    real    0m2.806s
    user    0m0.180s
    sys     0m0.264s

  After:

    real    0m0.857s
    user    0m0.020s
    sys     0m0.028s

Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
2013-06-24 18:03:37 +02:00
SZEDER Gábor 69a8141a5d bash prompt: avoid command substitution when finalizing gitstring
Before setting $PS1, __git_ps1() uses a command substitution to
redirect the output from a printf into a variable.  Spare the overhead
of fork()ing a subshell by using 'printf -v <var>' to directly assign
the output to that variable.

zsh's printf doesn't support the '-v <var>' option, so stick with the
command substitution when under zsh.

Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
2013-06-24 18:03:37 +02:00
SZEDER Gábor 14d7649748 bash prompt: avoid command substitution when checking for untracked files
When enabled, the bash prompt can indicate the presence of untracked
files with a '%' sign.  __git_ps1() checks for untracked files by running the
'$(git ls-files --others --exclude-standard)' command substitution,
and displays the indicator when there is no output.

Avoid this command substitution by additionally passing
'--error-unmatch *', and checking the command's return value.

Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
2013-06-24 18:03:37 +02:00
SZEDER Gábor dd0b72cbd9 bash prompt: use bash builtins to check stash state
When the environment variable $GIT_PS1_SHOWSTASHSTATE is set
__git_ps1() checks the presence of stashes by running 'git rev-parse
--verify refs/stash'.  This command not only checks that the
'refs/stash' ref exists but also, well, verifies that it's a valid
ref.

However, we don't need to be that thorough for the bash prompt.  We
can omit that verification and only check whether 'refs/stash' exists
or not.  Since 'git pack-refs' never packs 'refs/stash', it's a matter
of checking the existence of a ref file.  Perform this check using
only bash builtins to spare the overhead of fork()+exec()ing a git
process.

Also run 'git pack-refs --all' in the corresponding test to document
that the prompt script depends on 'git pack-refs' not packing
'refs/stash' and to catch possible breakages should this behavior ever
change.

Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
2013-06-24 18:03:37 +02:00
SZEDER Gábor 0f37c12581 bash prompt: use bash builtins to check for unborn branch for dirty state
When the dirty work tree and index status indicator is enabled,
__git_ps1() checks for changes in the index by running 'git diff-index
--cached --quiet HEAD --' and looking at its exit code.  However, that
makes sense only when HEAD points to a valid commit: on an unborn
branch the failure of said command would be caused by the invalid
HEAD, not by changes in the index.  Therefore, __git_ps1() first
checks for a valid HEAD by running 'git rev-parse --quiet --verify
HEAD'.

Since the previous patch we implicitly check HEAD's validity by
running 'git rev-parse ... --short HEAD', making the dirty status
indicator's 'git rev-parse' check redundant.  It's sufficient to check
for non-emptyness of the variable holding the abbreviated commit
object name, thereby sparing the overhead of fork()+exec()ing a git
process.

Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
2013-06-24 18:03:37 +02:00
SZEDER Gábor e3e0b9378b bash prompt: combine 'git rev-parse' for detached head
When describing a detached HEAD according to the $GIT_PS1_DESCRIBE
environment variable fails, __git_ps1() now runs the '$(git rev-parse
--short HEAD)' command substitution to get the abbreviated detached
HEAD commit object name.  This imposes the overhead of fork()ing a
subshell and fork()+exec()ing a git process.

Avoid this overhead by combining this command substitution with the
"main" 'git rev-parse' execution for getting the path to the .git
directory & co.  This means that we'll look for the abbreviated commit
object name even when it's not necessary, because we're on a branch or
the detached HEAD can be described.  It doesn't matter, however,
because once 'git rev-parse' is up and running to fulfill all those
other queries, the additional overhead of looking for the abbreviated
commit object name is not measurable because it's lost in the noise.

There is a caveat, however, when we are on an unborn branch, because
in that case HEAD doesn't point to a valid commit, hence the query for
the abbreviated commit object name fails.  Therefore, '--short HEAD'
must be the last options to 'git rev-parse' in order to get all the
other necessary information for the prompt even on an unborn branch.
Furthermore, in that case, and in that case only, 'git rev-parse'
doesn't output the last line containing the abbreviated commit object
name, obviously, so we have to take care to only parse it if 'git
rev-parse' exited without any error.

Although there are tests already excercising __git_ps1() on unborn
branches, they all do so implicitly.  Add a test that checks this
explicitly.

Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
2013-06-24 18:03:30 +02:00
SZEDER Gábor efaa0c1532 bash prompt: combine 'git rev-parse' executions in the main code path
There are a couple of '$(git rev-parse --<opt>)' command substitutions
in __git_ps1() and three of them are executed in the main code path:

 - the first to get the path to the .git directory ('--git-dir'),
 - the second to check whether we're inside the .git directory
   ('--is-inside-git-dir'),
 - and the last, depending on the results of the second, either
   * to check whether it's a bare repo ('--is-bare-repository'), or
   * to check whether inside a work tree ('--is-inside-work-tree').

Naturally, this imposes the overhead of fork()ing three subshells and
fork()+exec()ing three git commands.

Combine these four 'git rev-parse' queries into a single one and use
bash parameter expansions to parse the combined output, i.e. to
separate the path to the .git directory from the true/false of
'--is-inside-git-dir', etc.  This way we can eliminate two of the
three subshells and git commands.

Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
2013-06-24 17:22:10 +02:00