gitweb.git
replace trivial malloc + sprintf / strcpy calls with... Jeff King Thu, 24 Sep 2015 21:07:03 +0000 (17:07 -0400)

replace trivial malloc + sprintf / strcpy calls with xstrfmt

It's a common pattern to do:

foo = xmalloc(strlen(one) + strlen(two) + 1 + 1);
sprintf(foo, "%s %s", one, two);

(or possibly some variant with strcpy()s or a more
complicated length computation). We can switch these to use
xstrfmt, which is shorter, involves less error-prone manual
computation, and removes many sprintf and strcpy calls which
make it harder to audit the code for real buffer overflows.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

receive-pack: convert strncpy to xsnprintfJeff King Thu, 24 Sep 2015 21:07:00 +0000 (17:07 -0400)

receive-pack: convert strncpy to xsnprintf

This strncpy is pointless; we pass the strlen() of the src
string, meaning that it works just like a memcpy. Worse,
though, is that the size has no relation to the destination
buffer, meaning it is a potential overflow. In practice,
it's not. We pass only short constant strings like
"warning: " and "error: ", which are much smaller than the
destination buffer.

We can make this much simpler by just using xsnprintf, which
will check for overflow and return the size for our next
vsnprintf, without us having to run a separate strlen().

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

http-push: replace strcat with xsnprintfJeff King Thu, 24 Sep 2015 21:06:58 +0000 (17:06 -0400)

http-push: replace strcat with xsnprintf

We account for these strcats in our initial allocation, but
the code is confusing to follow and verify. Let's remember
our original allocation length, and then xsnprintf can
verify that we don't exceed it.

Note that we can't just use xstrfmt here (which would be
even cleaner) because the code tries to grow the buffer only
when necessary.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

add_packed_git: convert strcpy into xsnprintfJeff King Thu, 24 Sep 2015 21:06:55 +0000 (17:06 -0400)

add_packed_git: convert strcpy into xsnprintf

We have the path "foo.idx", and we create a buffer big
enough to hold "foo.pack" and "foo.keep", and then strcpy
straight into it. This isn't a bug (we have enough space),
but it's very hard to tell from the strcpy that this is so.

Let's instead use strip_suffix to take off the ".idx",
record the size of our allocation, and use xsnprintf to make
sure we don't violate our assumptions.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

entry.c: convert strcpy to xsnprintfJeff King Thu, 24 Sep 2015 21:06:53 +0000 (17:06 -0400)

entry.c: convert strcpy to xsnprintf

This particular conversion is non-obvious, because nobody
has passed our function the length of the destination
buffer. However, the interface to checkout_entry specifies
that the buffer must be at least TEMPORARY_FILENAME_LENGTH
bytes long, so we can check that (meaning the existing code
was not buggy, but merely worrisome to somebody reading it).

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

grep: use xsnprintf to format failure messageJeff King Thu, 24 Sep 2015 21:06:51 +0000 (17:06 -0400)

grep: use xsnprintf to format failure message

This looks at first glance like the sprintf can overflow our
buffer, but it's actually fine; the p->origin string is
something constant and small, like "command line" or "-e
option".

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

compat/hstrerror: convert sprintf to snprintfJeff King Thu, 24 Sep 2015 21:06:48 +0000 (17:06 -0400)

compat/hstrerror: convert sprintf to snprintf

This is a trivially correct use of sprintf, as our error
number should not be excessively long. But it's still nice
to drop an sprintf call.

Note that we cannot use xsnprintf here, because this is
compat code which does not load git-compat-util.h.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

stop_progress_msg: convert sprintf to xsnprintfJeff King Thu, 24 Sep 2015 21:06:46 +0000 (17:06 -0400)

stop_progress_msg: convert sprintf to xsnprintf

The usual arguments for using xsnprintf over sprintf apply,
but this case is a little tricky. We print to a fixed-size
buffer if we have room, and otherwise to an allocated
buffer. So there should be no overflow here, but it is still
good to communicate our intention, as well as to check our
earlier math for how much space the string will need.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

find_short_object_filename: convert sprintf to xsnprintfJeff King Thu, 24 Sep 2015 21:06:44 +0000 (17:06 -0400)

find_short_object_filename: convert sprintf to xsnprintf

We use sprintf() to format some hex data into a buffer. The
buffer is clearly long enough, and using snprintf here is
not necessary. And in fact, it does not really make anything
easier to audit, as the size we feed to snprintf accounts
for the magic extra 42 bytes found in each alt->name field
of struct alternate_object_database (which is there exactly
to do this formatting).

Still, it is nice to remove an sprintf call and replace it
with an xsnprintf and explanatory comment, which makes it
easier to audit the code base for overflows.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

use xsnprintf for generating git object headersJeff King Thu, 24 Sep 2015 21:06:42 +0000 (17:06 -0400)

use xsnprintf for generating git object headers

We generally use 32-byte buffers to format git's "type size"
header fields. These should not generally overflow unless
you can produce some truly gigantic objects (and our types
come from our internal array of constant strings). But it is
a good idea to use xsnprintf to make sure this is the case.

Note that we slightly modify the interface to
write_sha1_file_prepare, which nows uses "hdrlen" as an "in"
parameter as well as an "out" (on the way in it stores the
allocated size of the header, and on the way out it returns
the ultimate size of the header).

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

archive-tar: use xsnprintf for trivial formattingJeff King Thu, 24 Sep 2015 21:06:24 +0000 (17:06 -0400)

archive-tar: use xsnprintf for trivial formatting

When we generate tar headers, we sprintf() values directly
into a struct with the fixed-size header values. For the
most part this is fine, as we are formatting small values
(e.g., the octal format of "mode & 0x7777" is of fixed
length). But it's still a good idea to use xsnprintf here.
It communicates to readers what our expectation is, and it
provides a run-time check that we are not overflowing the
buffers.

The one exception here is the mtime, which comes from the
epoch time of the commit we are archiving. For sane values,
this fits into the 12-byte value allocated in the header.
But since git can handle 64-bit times, if I claim to be a
visitor from the year 10,000 AD, I can overflow the buffer.
This turns out to be harmless, as we simply overflow into
the chksum field, which is then overwritten.

This case is also best as an xsnprintf. It should never come
up, short of extremely malformed dates, and in that case we
are probably better off dying than silently truncating the
date value (and we cannot expand the size of the buffer,
since it is dictated by the ustar format). Our friends in
the year 5138 (when we legitimately flip to a 12-digit
epoch) can deal with that problem then.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

convert trivial sprintf / strcpy calls to xsnprintfJeff King Thu, 24 Sep 2015 21:06:08 +0000 (17:06 -0400)

convert trivial sprintf / strcpy calls to xsnprintf

We sometimes sprintf into fixed-size buffers when we know
that the buffer is large enough to fit the input (either
because it's a constant, or because it's numeric input that
is bounded in size). Likewise with strcpy of constant
strings.

However, these sites make it hard to audit sprintf and
strcpy calls for buffer overflows, as a reader has to
cross-reference the size of the array with the input. Let's
use xsnprintf instead, which communicates to a reader that
we don't expect this to overflow (and catches the mistake in
case we do).

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

compat/inet_ntop: fix off-by-one in inet_ntop4Jeff King Thu, 24 Sep 2015 21:06:06 +0000 (17:06 -0400)

compat/inet_ntop: fix off-by-one in inet_ntop4

Our compat inet_ntop4 function writes to a temporary buffer
with snprintf, and then uses strcpy to put the result into
the final "dst" buffer. We check the return value of
snprintf against the size of "dst", but fail to account for
the NUL terminator. As a result, we may overflow "dst" with
a single NUL. In practice, this doesn't happen because the
output of inet_ntop is limited, and we provide buffers that
are way oversized.

We can fix the off-by-one check easily, but while we are
here let's also use strlcpy for increased safety, just in
case there are other bugs lurking.

As a side note, this compat code seems to be BSD-derived.
Searching for "vixie inet_ntop" turns up NetBSD's latest
version of the same code, which has an identical fix (and
switches to strlcpy, too!).

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

test-dump-cache-tree: avoid overflow of cache-tree... Jeff King Thu, 24 Sep 2015 21:06:03 +0000 (17:06 -0400)

test-dump-cache-tree: avoid overflow of cache-tree name

When dumping a cache-tree, we sprintf sub-tree names directly
into a fixed-size buffer, which can overflow. We can
trivially fix this by converting to xsnprintf to at least
notice and die.

This probably should handle arbitrary-sized names, but
there's not much point. It's used only by the test scripts,
so the trivial fix is enough.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

progress: store throughput display in a strbufJeff King Thu, 24 Sep 2015 21:05:57 +0000 (17:05 -0400)

progress: store throughput display in a strbuf

Coverity noticed that we strncpy() into a fixed-size buffer
without making sure that it actually ended up
NUL-terminated. This is unlikely to be a bug in practice,
since throughput strings rarely hit 32 characters, but it
would be nice to clean it up.

The most obvious way to do so is to add a NUL-terminator.
But instead, this patch switches the fixed-size buffer out
for a strbuf. At first glance this seems much less
efficient, until we realize that filling in the fixed-size
buffer is done by writing into a strbuf and copying the
result!

By writing straight to the buffer, we actually end up more
efficient:

1. We avoid an extra copy of the bytes.

2. Rather than malloc/free each time progress is shown, we
can strbuf_reset and use the same buffer each time.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

trace: use strbuf for quote_crnl outputJeff King Thu, 24 Sep 2015 21:05:54 +0000 (17:05 -0400)

trace: use strbuf for quote_crnl output

When we output GIT_TRACE_SETUP paths, we quote any
meta-characters. But our buffer to hold the result is only
PATH_MAX bytes, and we could double the size of the input
path (if every character needs quoting). We could use a
2*PATH_MAX buffer, if we assume the input will never be more
than PATH_MAX. But it's easier still to just switch to a
strbuf and not worry about whether the input can exceed
PATH_MAX or not.

The original copied the "p2" pointer to "p1", advancing
both. Since this gets rid of "p1", let's also drop "p2",
whose name is now confusing. We can just advance the
original "path" pointer.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

mailsplit: make PATH_MAX buffers dynamicJeff King Thu, 24 Sep 2015 21:05:51 +0000 (17:05 -0400)

mailsplit: make PATH_MAX buffers dynamic

There are several PATH_MAX-sized buffers in mailsplit, along
with some questionable uses of sprintf. These are not
really of security interest, as local mailsplit pathnames
are not typically under control of an attacker, and you
could generally only overflow a few numbers at the end of a
path that approaches PATH_MAX (a longer path would choke
mailsplit long before). But it does not hurt to be careful,
and as a bonus we lift some limits for systems with
too-small PATH_MAX varibles.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

fsck: use strbuf to generate alternate directoriesJeff King Thu, 24 Sep 2015 21:05:48 +0000 (17:05 -0400)

fsck: use strbuf to generate alternate directories

When fsck-ing alternates, we make a copy of the alternate
directory in a fixed PATH_MAX buffer. We memcpy directly,
without any check whether we are overflowing the buffer.
This is OK if PATH_MAX is a true representation of the
maximum path on the system, because any path here will have
already been vetted by the alternates subsystem. But that is
not true on every system, so we should be more careful.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

add reentrant variants of sha1_to_hex and find_unique_a... Jeff King Thu, 24 Sep 2015 21:05:45 +0000 (17:05 -0400)

add reentrant variants of sha1_to_hex and find_unique_abbrev

The sha1_to_hex and find_unique_abbrev functions always
write into reusable static buffers. There are a few problems
with this:

- future calls overwrite our result. This is especially
annoying with find_unique_abbrev, which does not have a
ring of buffers, so you cannot even printf() a result
that has two abbreviated sha1s.

- if you want to put the result into another buffer, we
often strcpy, which looks suspicious when auditing for
overflows.

This patch introduces sha1_to_hex_r and find_unique_abbrev_r,
which write into a user-provided buffer. Of course this is
just punting on the overflow-auditing, as the buffer
obviously needs to be GIT_SHA1_HEXSZ + 1 bytes. But it is
much easier to audit, since that is a well-known size.

We retain the non-reentrant forms, which just become thin
wrappers around the reentrant ones. This patch also adds a
strbuf variant of find_unique_abbrev, which will be handy in
later patches.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

strbuf: make strbuf_complete_line more genericJeff King Thu, 24 Sep 2015 21:05:43 +0000 (17:05 -0400)

strbuf: make strbuf_complete_line more generic

The strbuf_complete_line function makes sure that a buffer
ends in a newline. But we may want to do this for any
character (e.g., "/" on the end of a path). Let's factor out
a generic version, and keep strbuf_complete_line as a thin
wrapper.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

add git_path_buf helper functionJeff King Thu, 24 Sep 2015 21:05:40 +0000 (17:05 -0400)

add git_path_buf helper function

If you have a function that uses git_path a lot, but would
prefer to avoid the static buffers, it's useful to keep a
single scratch buffer locally and reuse it for each call.
You used to be able to do this with git_snpath:

char buf[PATH_MAX];

foo(git_snpath(buf, sizeof(buf), "foo"));
bar(git_snpath(buf, sizeof(buf), "bar"));

but since 1a83c24, git_snpath has been replaced with
strbuf_git_path. This is good, because it removes the
arbitrary PATH_MAX limit. But using strbuf_git_path is more
awkward for two reasons:

1. It adds to the buffer, rather than replacing it. This
is consistent with other strbuf functions, but makes
reuse of a single buffer more tedious.

2. It doesn't return the buffer, so you can't format
as part of a function's arguments.

The new git_path_buf solves both of these, so you can use it
like:

struct strbuf buf = STRBUF_INIT;

foo(git_path_buf(&buf, "foo"));
bar(git_path_buf(&buf, "bar"));

strbuf_release(&buf);

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

add xsnprintf helper functionJeff King Thu, 24 Sep 2015 21:05:37 +0000 (17:05 -0400)

add xsnprintf helper function

There are a number of places in the code where we call
sprintf(), with the assumption that the output will fit into
the buffer. In many cases this is true (e.g., formatting a
number into a large buffer), but it is hard to tell
immediately from looking at the code. It would be nice if we
had some run-time check to make sure that our assumption is
correct (and to communicate to readers of the code that we
are not blindly calling sprintf, but have actually thought
about this case).

This patch introduces xsnprintf, which behaves just like
snprintf, except that it dies whenever the output is
truncated. This acts as a sort of assert() for these cases,
which can help find places where the assumption is violated
(as opposed to truncating and proceeding, which may just
silently give a wrong answer).

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

fsck: don't fsck alternates for connectivity-only checkJeff King Thu, 24 Sep 2015 21:05:30 +0000 (17:05 -0400)

fsck: don't fsck alternates for connectivity-only check

Commit 02976bf (fsck: introduce `git fsck --connectivity-only`,
2015-06-22) recently gave fsck an option to perform only a
subset of the checks, by skipping the fsck_object_dir()
call. However, it does so only for the local object
directory, and we still do expensive checks on any alternate
repos. We should skip them in this case, too.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

archive-tar: fix minor indentation violationJeff King Thu, 24 Sep 2015 21:03:49 +0000 (17:03 -0400)

archive-tar: fix minor indentation violation

This looks like a simple omission from 8539070 (archive-tar:
unindent write_tar_entry by one level, 2012-05-03).

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

mailsplit: fix FILE* leak in split_maildirJeff King Thu, 24 Sep 2015 21:03:05 +0000 (17:03 -0400)

mailsplit: fix FILE* leak in split_maildir

If we encounter an error while splitting a maildir, we exit
the function early, leaking the open filehandle. This isn't
a big deal, since we exit the program soon after, but it's
easy enough to be careful.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

show-branch: avoid segfault with --reflog of unborn... Jeff King Thu, 24 Sep 2015 21:02:54 +0000 (17:02 -0400)

show-branch: avoid segfault with --reflog of unborn branch

When no branch is given to the "--reflog" option, we resolve
HEAD to get the default branch. However, if HEAD points to
an unborn branch, resolve_ref returns NULL, and we later
segfault trying to access it.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

connect: fix typo in result string of prot_name()Tobias Klauser Thu, 24 Sep 2015 12:44:49 +0000 (14:44 +0200)

connect: fix typo in result string of prot_name()

Replace 'unkown' with 'unknown'.

Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

branch: add '--points-at' optionKarthik Nayak Wed, 23 Sep 2015 18:11:13 +0000 (23:41 +0530)

branch: add '--points-at' option

Add the '--points-at' option provided by 'ref-filter'. The option lets
the user to list only branches which points at the given object.

Add documentation and tests for the same.

Mentored-by: Christian Couder <christian.couder@gmail.com>
Mentored-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr>
Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

branch.c: use 'ref-filter' APIsKarthik Nayak Wed, 23 Sep 2015 18:11:12 +0000 (23:41 +0530)

branch.c: use 'ref-filter' APIs

Make 'branch.c' use 'ref-filter' APIs for iterating through refs
sorting. This removes most of the code used in 'branch.c' replacing it
with calls to the 'ref-filter' library.

Make 'branch.c' use the 'filter_refs()' function provided by 'ref-filter'
to filter out tags based on the options set.

We provide a sorting option provided for 'branch.c' by using the
sorting options provided by 'ref-filter'. Also by default, we sort by
'refname'. Since 'HEAD' is alphabatically before 'refs/...' we end up
with an array consisting of the 'HEAD' ref then the local branches and
finally the remote-tracking branches.

Also remove the 'ignore' variable from ref_array_item as it was
previously used for the '--merged' option and now that is handled by
ref-filter.

Modify some of the tests in t1430 to check the stderr for a warning
regarding the broken ref. This is done as ref-filter throws a warning
for broken refs rather than directly printing them.

Add tests and documentation for the same.

Mentored-by: Christian Couder <christian.couder@gmail.com>
Mentored-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr>
Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

branch.c: use 'ref-filter' data structuresKarthik Nayak Wed, 23 Sep 2015 18:11:11 +0000 (23:41 +0530)

branch.c: use 'ref-filter' data structures

Make 'branch.c' use 'ref-filter' data structures and make changes to
support the new data structures. This is a part of the process of
porting 'branch.c' to use 'ref-filter' APIs.

This is a temporary step before porting 'branch.c' to use 'ref-filter'
completely. As this is a temporary step, most of the code introduced
here will be removed when 'branch.c' is ported over to use
'ref-filter' APIs.

Mentored-by: Christian Couder <christian.couder@gmail.com>
Mentored-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr>
Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

branch: drop non-commit error reportingKarthik Nayak Thu, 24 Sep 2015 18:09:08 +0000 (23:39 +0530)

branch: drop non-commit error reporting

Remove the error "branch '%s' does not point at a commit" in
append_ref(), which reports branch refs which do not point to
commits. Also remove the error "some refs could not be read" in
print_ref_list() which is triggered as a consequence of the first
error.

The purpose of these codepaths is not to diagnose and report a
repository corruption. If we care about such a corruption, we
should report it from fsck instead, which we already do.

This also helps in a smooth port of branch.c to use ref-filter APIs
over the following patches. On the other hand, ref-filter ignores refs
which do not point at commits silently.

Based-on-patch-by: Jeff King <peff@peff.net>
Helped-by: Junio C Hamano <gitster@pobox.com>
Mentored-by: Christian Couder <christian.couder@gmail.com>
Mentored-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr>
Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

t5561: get rid of racy appending to logfileStephan Beyer Thu, 24 Sep 2015 18:12:22 +0000 (20:12 +0200)

t5561: get rid of racy appending to logfile

The definition of log_div() appended information to the web server's
logfile to make the test more readable. However, log_div() was called
right after a request is served (which is done by git-http-backend);
the web server waits for the git-http-backend process to exit before
it writes to the log file. When the duration between serving a request
and exiting was long, the log_div() output was written before the last
request's log, and the test failed. (This duration could become
especially long for PROFILE=GEN builds.)

To get rid of this behavior, we should not change the logfile at all.
This commit removes log_div() and its calls. The additional information
is kept in the test (for readability reasons) but filtered out before
comparing it to the actual logfile.

Signed-off-by: Stephan Beyer <s-beyer@gmx.net>
Reviewed-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

fsck: exit with non-zero when problems are foundJunio C Hamano Wed, 23 Sep 2015 20:46:39 +0000 (13:46 -0700)

fsck: exit with non-zero when problems are found

After finding some problems (e.g. a ref refs/heads/X points at an
object that is not a commit) and issuing an error message, the
program failed to signal the fact that it found an error by a
non-zero exit status.

Signed-off-by: Junio C Hamano <gitster@pobox.com>

branch: move 'current' check down to the presentation... Karthik Nayak Wed, 23 Sep 2015 18:11:09 +0000 (23:41 +0530)

branch: move 'current' check down to the presentation layer

We check if given ref is the current branch in print_ref_list(). Move
this check to print_ref_item() where it is checked right before
printing. This enables a smooth transition to using ref-filter APIs,
as we can later replace the current check while printing to just check
for FILTER_REFS_DETACHED instead.

Based-on-patch-by: Jeff King <peff@peff.net>
Mentored-by: Christian Couder <christian.couder@gmail.com>
Mentored-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr>
Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

branch: roll show_detached HEAD into regular ref_listKarthik Nayak Wed, 23 Sep 2015 18:11:08 +0000 (23:41 +0530)

branch: roll show_detached HEAD into regular ref_list

Remove show_detached() and make detached HEAD to be rolled into
regular ref_list by adding REF_DETACHED_HEAD as a kind of branch and
supporting the same in append_ref(). This eliminates the need for an
extra function and helps in easier porting of branch.c to use
ref-filter APIs.

Before show_detached() used to check if the HEAD branch satisfies the
'--contains' option, now that is taken care by append_ref().

Based-on-patch-by: Jeff King <peff@peff.net>
Mentored-by: Christian Couder <christian.couder@gmail.com>
Mentored-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr>
Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

branch: bump get_head_description() to the topKarthik Nayak Wed, 23 Sep 2015 18:11:07 +0000 (23:41 +0530)

branch: bump get_head_description() to the top

This is a preperatory patch for 'roll show_detached HEAD into regular
ref_list'. This patch moves get_head_description() to the top so that
it can be used in print_ref_item().

Based-on-patch-by: Jeff King <peff@peff.net>
Mentored-by: Christian Couder <christian.couder@gmail.com>
Mentored-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr>
Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

branch: refactor width computationKarthik Nayak Wed, 23 Sep 2015 18:11:06 +0000 (23:41 +0530)

branch: refactor width computation

Remove unnecessary variables from ref_list and ref_item which were
used for width computation. This is to make ref_item similar to
ref-filter's ref_array_item. This will ensure a smooth port of
branch.c to use ref-filter APIs in further patches.

Previously the maxwidth was computed when inserting the refs into the
ref_list. Now, we obtain the entire ref_list and then compute
maxwidth.

Based-on-patch-by: Jeff King <peff@peff.net>
Mentored-by: Christian Couder <christian.couder@gmail.com>
Mentored-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr>
Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

submodule: allow only certain protocols for submodule... Jeff King Wed, 16 Sep 2015 17:13:12 +0000 (13:13 -0400)

submodule: allow only certain protocols for submodule fetches

Some protocols (like git-remote-ext) can execute arbitrary
code found in the URL. The URLs that submodules use may come
from arbitrary sources (e.g., .gitmodules files in a remote
repository). Let's restrict submodules to fetching from a
known-good subset of protocols.

Note that we apply this restriction to all submodule
commands, whether the URL comes from .gitmodules or not.
This is more restrictive than we need to be; for example, in
the tests we run:

git submodule add ext::...

which should be trusted, as the URL comes directly from the
command line provided by the user. But doing it this way is
simpler, and makes it much less likely that we would miss a
case. And since such protocols should be an exception
(especially because nobody who clones from them will be able
to update the submodules!), it's not likely to inconvenience
anyone in practice.

Reported-by: Blake Burkhart <bburky@bburky.com>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

transport: add a protocol-whitelist environment variableJeff King Wed, 16 Sep 2015 17:12:52 +0000 (13:12 -0400)

transport: add a protocol-whitelist environment variable

If we are cloning an untrusted remote repository into a
sandbox, we may also want to fetch remote submodules in
order to get the complete view as intended by the other
side. However, that opens us up to attacks where a malicious
user gets us to clone something they would not otherwise
have access to (this is not necessarily a problem by itself,
but we may then act on the cloned contents in a way that
exposes them to the attacker).

Ideally such a setup would sandbox git entirely away from
high-value items, but this is not always practical or easy
to set up (e.g., OS network controls may block multiple
protocols, and we would want to enable some but not others).

We can help this case by providing a way to restrict
particular protocols. We use a whitelist in the environment.
This is more annoying to set up than a blacklist, but
defaults to safety if the set of protocols git supports
grows). If no whitelist is specified, we continue to default
to allowing all protocols (this is an "unsafe" default, but
since the minority of users will want this sandboxing
effect, it is the only sensible one).

A note on the tests: ideally these would all be in a single
test file, but the git-daemon and httpd test infrastructure
is an all-or-nothing proposition rather than a test-by-test
prerequisite. By putting them all together, we would be
unable to test the file-local code on machines without
apache.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

notes: correct documentation of DWIMery for notes refer... Jacob Keller Tue, 22 Sep 2015 22:15:03 +0000 (15:15 -0700)

notes: correct documentation of DWIMery for notes references

expand_notes_ref is used by --ref from git-notes(1) and --notes from the
git log to find the full refname of a notes reference. Previously the
documentation of these options was not clear about what sorts of
expansions would be performed. Fix the documentation to clearly and
accurately describe the behavior of the expansions.

Add a test for this expansion when using git notes get-ref in order to
prevent future patches from changing this behavior.

Signed-off-by: Jacob Keller <jacob.keller@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

git-p4: handle "Translation of file content failed"Lars Schneider Mon, 21 Sep 2015 10:01:41 +0000 (12:01 +0200)

git-p4: handle "Translation of file content failed"

A P4 repository can get into a state where it contains a file with
type UTF-16 that does not contain a valid UTF-16 BOM. If git-p4
attempts to retrieve the file then the process crashes with a
"Translation of file content failed" error.

More info here: http://answers.perforce.com/articles/KB/3117

Fix this by detecting this error and retrieving the file as binary
instead. The result in Git is the same.

Known issue: This works only if git-p4 is executed in verbose mode.
In normal mode no exceptions are thrown and git-p4 just exits.

Signed-off-by: Lars Schneider <larsxschneider@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

git-p4: add test case for "Translation of file content... Lars Schneider Mon, 21 Sep 2015 10:01:40 +0000 (12:01 +0200)

git-p4: add test case for "Translation of file content failed" error

A P4 repository can get into a state where it contains a file with
type UTF-16 that does not contain a valid UTF-16 BOM. If git-p4
attempts to retrieve the file then the process crashes with a
"Translation of file content failed" error.

More info here: http://answers.perforce.com/articles/KB/3117

Signed-off-by: Lars Schneider <larsxschneider@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

filter-branch: make report-progress more readableJunio C Hamano Mon, 21 Sep 2015 22:16:20 +0000 (15:16 -0700)

filter-branch: make report-progress more readable

The name of some variables that are used very locally in this
function were overly long; they were making the lines harder to read
and the longer names didn't add much more information.

Signed-off-by: Junio C Hamano <gitster@pobox.com>

filter-branch: add passed/remaining seconds on progressGabor Bernat Mon, 7 Sep 2015 13:52:08 +0000 (15:52 +0200)

filter-branch: add passed/remaining seconds on progress

adds seconds progress and estimated seconds time if getting the current
timestamp is supported by the date +%s command

Signed-off-by: Gabor Bernat <gabor.bernat@gravityrd.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

Git 2.6-rc3 v2.6.0-rc3Junio C Hamano Mon, 21 Sep 2015 20:26:13 +0000 (13:26 -0700)

Git 2.6-rc3

Signed-off-by: Junio C Hamano <gitster@pobox.com>

git-p4: use replacement character for non UTF-8 charact... Lars Schneider Mon, 21 Sep 2015 08:49:18 +0000 (10:49 +0200)

git-p4: use replacement character for non UTF-8 characters in paths

If non UTF-8 characters are detected in paths then replace them with
a placeholder instead of throwing a UnicodeDecodeError
exception. This restores the original (implicit) implementation that
was broken in 00a9403.

Signed-off-by: Lars Schneider <larsxschneider@gmail.com>
Reviewed-by: Luke Diamand <luke@diamand.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

Merge branch 'rj/mailmap-ramsay'Junio C Hamano Mon, 21 Sep 2015 19:58:35 +0000 (12:58 -0700)

Merge branch 'rj/mailmap-ramsay'

* rj/mailmap-ramsay:
mailmap: update my entry with new email address

Merge branch 'bn/send-email-smtp-auth-error-message... Junio C Hamano Mon, 21 Sep 2015 19:27:15 +0000 (12:27 -0700)

Merge branch 'bn/send-email-smtp-auth-error-message-fix'

Fix a minor regression brought in to "git send-email" by a recent
addition of the "--smtp-auth" option.

* bn/send-email-smtp-auth-error-message-fix:
send-email: fix uninitialized var warning for $smtp_auth

dir.c: don't exclude whole dir prematurely if neg patte... Nguyễn Thái Ngọc Duy Mon, 21 Sep 2015 09:56:15 +0000 (16:56 +0700)

dir.c: don't exclude whole dir prematurely if neg pattern may match

If there is a pattern "!foo/bar", this patch makes it not exclude "foo"
right away. This gives us a chance to examine "foo" and re-include
"foo/bar".

In order for it to detect that the directory under examination should
not be excluded right away, in other words it is a parent directory of a
negative pattern, the "directory path" of the negative pattern must be
literal. Patterns like "!f?o/bar" can't stop "foo" from being excluded.

Basename matching (i.e. "no slashes in the pattern") or must-be-dir
matching (i.e. "trailing slash in the pattern") does not work well with
this. For example, if we descend in "foo" and are examining "foo/abc",
current code for "foo/" pattern will check if path "foo/abc", not "foo",
is a directory. The same problem with basename matching. These may need
big code reorg to make it work.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

dir.c: make last_exclude_matching_from_list() run til... Nguyễn Thái Ngọc Duy Mon, 21 Sep 2015 09:56:14 +0000 (16:56 +0700)

dir.c: make last_exclude_matching_from_list() run til the end

The next patch adds some post processing to the result value before it's
returned to the caller. Keep all branches reach the end of the function,
so we can do it all in one place.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

Merge tag 'l10n-2.6.0-rnd2+de' of git://github.com... Junio C Hamano Mon, 21 Sep 2015 17:54:07 +0000 (10:54 -0700)

Merge tag 'l10n-2.6.0-rnd2+de' of git://github.com/git-l10n/git-po

l10n-2.6.0-rnd2 plus de

* tag 'l10n-2.6.0-rnd2+de' of git://github.com/git-l10n/git-po: (25 commits)
l10n: de.po: better language for one string
l10n: de.po: translate 2 messages
l10n: Update and review Vietnamese translation (2440t)
l10n: fr.po v2.6.0 round 2 (2440t)
l10n: zh_CN: for git v2.6.0 l10n round 2
l10n: ca.po: update translation
l10n: git.pot: v2.6.0 round 2 (3 improvements)
l10n: de.po: translate 123 new messages
l10n: fr.po v2.6.0 round 1 (2441t)
l10n: sv.po: Update Swedish translation (2441t0f0u)
l10n: zh_CN: for git v2.6.0 l10n round 1
l10n: Updated Vietnamese translation (2441t)
l10n: git.pot: v2.6.0 round 1 (123 new, 41 removed)
l10n: zh_CN: Update Git Glossary: "commit message"
l10n: zh_CN: Update Git Glossary: pickaxe
l10n: zh_CN: Update Git Glossary: fork
l10n: zh_CN: Update Git Glossary: tag
l10n: zh_CN: Update Git Glossary: "dumb", "smart"
l10n: zh_CN: Update Git Glossary: SHA-1
l10n: zh_CN: Add Surrounding Spaces
...

send-email: fix uninitialized var warning for $smtp_authBrian Norris Fri, 18 Sep 2015 22:12:50 +0000 (15:12 -0700)

send-email: fix uninitialized var warning for $smtp_auth

On the latest version of git-send-email, I see this error just before
running SMTP auth (I didn't provide any --smtp-auth= parameter):

Use of uninitialized value $smtp_auth in pattern match (m//) at \
/home/briannorris/git/git/git-send-email.perl line 1139.

Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Reviewed-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

Documentation: explain optional arguments betterMatthieu Moy Sat, 19 Sep 2015 07:47:50 +0000 (09:47 +0200)

Documentation: explain optional arguments better

Improve the documentation of commands taking optional arguments in two
ways:

* Documents the behavior of '-O' (for grep) and '-S' (for commands
creating commits) when used without the optional argument.

* Document the syntax of these options.

For the second point, the behavior is documented in gitcli(7), but it is
easy for users to miss, and hard for the same user to understand why e.g.
"git status -u no" does not work.

Document this explicitly in the documentation of each short option having
an optional argument: they are the most error prone since there is no '='
sign between the option and its argument.

Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>
Reviewed-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

Documentation/grep: fix documentation of -OMatthieu Moy Sat, 19 Sep 2015 07:47:49 +0000 (09:47 +0200)

Documentation/grep: fix documentation of -O

Since the argument of -O, --open-file-in-pager is optional, it must be
stuck to the command. Reflect this in the documentation.

Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>
Reviewed-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

Documentation: use 'keyid' consistently, not 'key-id'Matthieu Moy Sat, 19 Sep 2015 07:47:48 +0000 (09:47 +0200)

Documentation: use 'keyid' consistently, not 'key-id'

Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>
Reviewed-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

gc: save log from daemonized gc --auto and print it... Nguyễn Thái Ngọc Duy Sat, 19 Sep 2015 05:13:23 +0000 (12:13 +0700)

gc: save log from daemonized gc --auto and print it next time

While commit 9f673f9 (gc: config option for running --auto in
background - 2014-02-08) helps reduce some complaints about 'gc
--auto' hogging the terminal, it creates another set of problems.

The latest in this set is, as the result of daemonizing, stderr is
closed and all warnings are lost. This warning at the end of cmd_gc()
is particularly important because it tells the user how to avoid "gc
--auto" running repeatedly. Because stderr is closed, the user does
not know, naturally they complain about 'gc --auto' wasting CPU.

Daemonized gc now saves stderr to $GIT_DIR/gc.log. Following gc --auto
will not run and gc.log printed out until the user removes gc.log.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

l10n: de.po: better language for one stringPhillip Sz Thu, 17 Sep 2015 15:50:32 +0000 (17:50 +0200)

l10n: de.po: better language for one string

Just one string I think we could translate better.

Signed-off-by: Phillip Sz <phillip.szelat@gmail.com>
Signed-off-by: Ralf Thielow <ralf.thielow@gmail.com>

l10n: de.po: translate 2 messagesRalf Thielow Wed, 16 Sep 2015 17:28:07 +0000 (19:28 +0200)

l10n: de.po: translate 2 messages

Translate 2 messages came from git.pot update in e447091
(l10n: git.pot: v2.6.0 round 2 (3 improvements)).

Signed-off-by: Ralf Thielow <ralf.thielow@gmail.com>
Acked-by: Phillip Sz <phillip.szelat@gmail.com>

l10n: Update and review Vietnamese translation (2440t)Tran Ngoc Quan Tue, 15 Sep 2015 00:17:53 +0000 (07:17 +0700)

l10n: Update and review Vietnamese translation (2440t)

Signed-off-by: Tran Ngoc Quan <vnwildman@gmail.com>

l10n: fr.po v2.6.0 round 2 (2440t)Jean-Noel Avila Tue, 15 Sep 2015 18:22:52 +0000 (20:22 +0200)

l10n: fr.po v2.6.0 round 2 (2440t)

Signed-off-by: Jean-Noel Avila <jn.avila@free.fr>

l10n: zh_CN: for git v2.6.0 l10n round 2Jiang Xin Tue, 15 Sep 2015 13:51:26 +0000 (21:51 +0800)

l10n: zh_CN: for git v2.6.0 l10n round 2

Update 2 translations (2440t0f0u) for git v2.6.0-rc2.

Signed-off-by: Jiang Xin <worldhello.net@gmail.com>

l10n: ca.po: update translationAlex Henrie Tue, 15 Sep 2015 03:05:50 +0000 (21:05 -0600)

l10n: ca.po: update translation

Signed-off-by: Alex Henrie <alexhenrie24@gmail.com>

l10n: git.pot: v2.6.0 round 2 (3 improvements)Jiang Xin Mon, 14 Sep 2015 22:57:19 +0000 (06:57 +0800)

l10n: git.pot: v2.6.0 round 2 (3 improvements)

Introduce three i18n improvements from the following commits:

* tag, update-ref: improve description of option "create-reflog"
* pull: don't mark values for option "rebase" for translation
* show-ref: place angle brackets around variables in usage string

Signed-off-by: Jiang Xin <worldhello.net@gmail.com>

Merge branch 'master' of git://github.com/git-l10n... Jiang Xin Mon, 14 Sep 2015 22:45:32 +0000 (06:45 +0800)

Merge branch 'master' of git://github.com/git-l10n/git-po

* 'master' of git://github.com/git-l10n/git-po:
l10n: de.po: translate 123 new messages
l10n: fr.po v2.6.0 round 1 (2441t)
l10n: sv.po: Update Swedish translation (2441t0f0u)
l10n: zh_CN: for git v2.6.0 l10n round 1
l10n: Updated Vietnamese translation (2441t)
l10n: git.pot: v2.6.0 round 1 (123 new, 41 removed)
l10n: zh_CN: Update Git Glossary: "commit message"
l10n: zh_CN: Update Git Glossary: pickaxe
l10n: zh_CN: Update Git Glossary: fork
l10n: zh_CN: Update Git Glossary: tag
l10n: zh_CN: Update Git Glossary: "dumb", "smart"
l10n: zh_CN: Update Git Glossary: SHA-1
l10n: zh_CN: Add Surrounding Spaces
l10n: zh_CN: Add translations for Git glossary
l10n: TEAMS: stash inactive zh_CN team members
l10n: zh_CN: Update Translation of "tag"
l10n: zh_CN: Unify Translation of "packfile"
l10n: zh_CN: Update Translation: "tag object"

Signed-off-by: Jiang Xin <worldhello.net@gmail.com>

l10n: de.po: translate 123 new messagesRalf Thielow Tue, 8 Sep 2015 07:31:34 +0000 (09:31 +0200)

l10n: de.po: translate 123 new messages

Translate 123 new messages came from git.pot update in df0617b
(l10n: git.pot: v2.6.0 round 1 (123 new, 41 removed)).

Signed-off-by: Ralf Thielow <ralf.thielow@gmail.com>
Acked-by: Phillip Sz <phillip.szelat@gmail.com>
Acked-by: Matthias Rüster <matthias.ruester@gmail.com>

l10n: fr.po v2.6.0 round 1 (2441t)Jean-Noel Avila Wed, 9 Sep 2015 20:55:10 +0000 (22:55 +0200)

l10n: fr.po v2.6.0 round 1 (2441t)

Signed-off-by: Jean-Noel Avila <jn.avila@free.fr>

Update RelNotes to 2.6Junio C Hamano Thu, 17 Sep 2015 19:32:58 +0000 (12:32 -0700)

Update RelNotes to 2.6

Signed-off-by: Junio C Hamano <gitster@pobox.com>

Sync with 2.5.3Junio C Hamano Thu, 17 Sep 2015 19:29:49 +0000 (12:29 -0700)

Sync with 2.5.3

* maint:
Git 2.5.3

Merge branch 'po/doc-branch-desc'Junio C Hamano Thu, 17 Sep 2015 19:29:03 +0000 (12:29 -0700)

Merge branch 'po/doc-branch-desc'

The branch descriptions that are set with "git branch --edit-description"
option were used in many places but they weren't clearly documented.

* po/doc-branch-desc:
doc: show usage of branch description

Merge branch 'et/win32-poll-timeout'Junio C Hamano Thu, 17 Sep 2015 19:29:02 +0000 (12:29 -0700)

Merge branch 'et/win32-poll-timeout'

* et/win32-poll-timeout:
poll: honor the timeout on Win32

Merge branch 'as/config-doc-markup-fix'Junio C Hamano Thu, 17 Sep 2015 19:29:01 +0000 (12:29 -0700)

Merge branch 'as/config-doc-markup-fix'

* as/config-doc-markup-fix:
Documentation/config: fix formatting for branch.*.rebase and pull.rebase

remote: add get-url subcommandBen Boeckel Wed, 16 Sep 2015 01:53:47 +0000 (21:53 -0400)

remote: add get-url subcommand

Expanding `insteadOf` is a part of ls-remote --url and there is no way
to expand `pushInsteadOf` as well. Add a get-url subcommand to be able
to query both as well as a way to get all configured urls.

Signed-off-by: Ben Boeckel <mathstuf@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

Git 2.5.3 v2.5.3Junio C Hamano Thu, 17 Sep 2015 19:16:10 +0000 (12:16 -0700)

Git 2.5.3

Signed-off-by: Junio C Hamano <gitster@pobox.com>

Merge branch 'dt/untracked-subdir' into maintJunio C Hamano Thu, 17 Sep 2015 19:12:29 +0000 (12:12 -0700)

Merge branch 'dt/untracked-subdir' into maint

The experimental untracked-cache feature were buggy when paths with
a few levels of subdirectories are involved.

* dt/untracked-subdir:
untracked cache: fix entry invalidation
untracked-cache: fix subdirectory handling
t7063: use --force-untracked-cache to speed up a bit
untracked-cache: support sparse checkout

Merge branch 'br/svn-doc-include-paths-config' into... Junio C Hamano Thu, 17 Sep 2015 19:11:46 +0000 (12:11 -0700)

Merge branch 'br/svn-doc-include-paths-config' into maint

* br/svn-doc-include-paths-config:
git-svn doc: mention "svn-remote.<name>.include-paths"

Merge branch 'ah/submodule-typofix-in-error' into maintJunio C Hamano Thu, 17 Sep 2015 19:11:06 +0000 (12:11 -0700)

Merge branch 'ah/submodule-typofix-in-error' into maint

Error string fix.

* ah/submodule-typofix-in-error:
git-submodule: remove extraneous space from error message

Merge branch 'js/maint-am-skip-performance-regression... Junio C Hamano Thu, 17 Sep 2015 19:03:02 +0000 (12:03 -0700)

Merge branch 'js/maint-am-skip-performance-regression' into maint

* js/maint-am-skip-performance-regression:
am --skip/--abort: merge HEAD/ORIG_HEAD tree into index

tag.c: implement '--merged' and '--no-merged' optionsKarthik Nayak Thu, 10 Sep 2015 16:22:49 +0000 (21:52 +0530)

tag.c: implement '--merged' and '--no-merged' options

Use 'ref-filter' APIs to implement the '--merged' and '--no-merged'
options into 'tag.c'. The '--merged' option lets the user to only list
tags merged into the named commit. The '--no-merged' option lets the
user to only list tags not merged into the named commit. If no object
is provided it assumes HEAD as the object.

Add documentation and tests for the same.

Mentored-by: Christian Couder <christian.couder@gmail.com>
Mentored-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr>
Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

tag.c: implement '--format' optionKarthik Nayak Fri, 11 Sep 2015 15:06:46 +0000 (20:36 +0530)

tag.c: implement '--format' option

Implement the '--format' option provided by 'ref-filter'.
This lets the user list tags as per desired format similar
to the implementation in 'git for-each-ref'.

Add tests and documentation for the same.

Mentored-by: Christian Couder <christian.couder@gmail.com>
Mentored-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr>
Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

tag.c: use 'ref-filter' APIsKarthik Nayak Fri, 11 Sep 2015 15:06:16 +0000 (20:36 +0530)

tag.c: use 'ref-filter' APIs

Make 'tag.c' use 'ref-filter' APIs for iterating through refs, sorting
and printing of refs. This removes most of the code used in 'tag.c'
replacing it with calls to the 'ref-filter' library.

Make 'tag.c' use the 'filter_refs()' function provided by 'ref-filter'
to filter out tags based on the options set.

For printing tags we use 'show_ref_array_item()' function provided by
'ref-filter'.

We improve the sorting option provided by 'tag.c' by using the sorting
options provided by 'ref-filter'. This causes the test 'invalid sort
parameter on command line' in t7004 to fail, as 'ref-filter' throws an
error for all sorting fields which are incorrect. The test is changed
to reflect the same.

Modify documentation for the same.

Mentored-by: Christian Couder <christian.couder@gmail.com>
Mentored-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr>
Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

tag.c: use 'ref-filter' data structuresKarthik Nayak Thu, 10 Sep 2015 15:48:27 +0000 (21:18 +0530)

tag.c: use 'ref-filter' data structures

Make 'tag.c' use 'ref-filter' data structures and make changes to
support the new data structures. This is a part of the process
of porting 'tag.c' to use 'ref-filter' APIs.

This is a temporary step before porting 'tag.c' to use 'ref-filter'
completely. As this is a temporary step, most of the code
introduced here will be removed when 'tag.c' is ported over to use
'ref-filter' APIs.

Mentored-by: Christian Couder <christian.couder@gmail.com>
Mentored-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr>
Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

ref-filter: add option to match literal patternKarthik Nayak Thu, 10 Sep 2015 15:48:26 +0000 (21:18 +0530)

ref-filter: add option to match literal pattern

Since 'ref-filter' only has an option to match path names add an
option for plain fnmatch pattern-matching.

This is to support the pattern matching options which are used in `git
tag -l` and `git branch -l` where we can match patterns like `git tag
-l foo*` which would match all tags which has a "foo*" pattern.

Mentored-by: Christian Couder <christian.couder@gmail.com>
Mentored-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr>
Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

ref-filter: add support to sort by versionKarthik Nayak Thu, 10 Sep 2015 15:48:25 +0000 (21:18 +0530)

ref-filter: add support to sort by version

Add support to sort by version using the "v:refname" and
"version:refname" option. This is achieved by using the 'versioncmp()'
function as the comparing function for qsort.

This option is included to support sorting by versions in `git tag -l`
which will eventually be ported to use ref-filter APIs.

Add documentation and tests for the same.

Mentored-by: Christian Couder <christian.couder@gmail.com>
Mentored-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr>
Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

ref-filter: add support for %(contents:lines=X)Karthik Nayak Fri, 11 Sep 2015 15:04:16 +0000 (20:34 +0530)

ref-filter: add support for %(contents:lines=X)

In 'tag.c' we can print N lines from the annotation of the tag using
the '-n<num>' option. Copy code from 'tag.c' to 'ref-filter' and
modify it to support appending of N lines from the annotation of tags
to the given strbuf.

Implement %(contents:lines=X) where X lines of the given object are
obtained.

While we're at it, remove unused "contents:<suboption>" atoms from
the `valid_atom` array.

Add documentation and test for the same.

Mentored-by: Christian Couder <christian.couder@gmail.com>
Mentored-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr>
Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

ref-filter: add option to filter out tags, branches... Karthik Nayak Thu, 10 Sep 2015 15:48:23 +0000 (21:18 +0530)

ref-filter: add option to filter out tags, branches and remotes

Add a function called 'for_each_fullref_in()' to refs.{c,h} which
iterates through each ref for the given path without trimming the path
and also accounting for broken refs, if mentioned.

Add 'filter_ref_kind()' in ref-filter.c to check the kind of ref being
handled and return the kind to 'ref_filter_handler()', where we
discard refs which we do not need and assign the kind to needed refs.

Mentored-by: Christian Couder <christian.couder@gmail.com>
Mentored-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr>
Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

ref-filter: implement an `align` atomKarthik Nayak Fri, 11 Sep 2015 15:03:07 +0000 (20:33 +0530)

ref-filter: implement an `align` atom

Implement an `align` atom which left-, middle-, or right-aligns the
content between %(align:...) and %(end).

The "align:" is followed by `<width>` and `<position>` in any order
separated by a comma, where the `<position>` is either left, right or
middle, default being left and `<width>` is the total length of the
content with alignment. If the contents length is more than the width
then no alignment is performed. e.g. to align a refname atom to the
middle with a total width of 40 we can do:
--format="%(align:middle,40)%(refname)%(end)".

We introduce an `at_end` function for each element of the stack which
is to be called when the `end` atom is encountered. Using this we
implement end_align_handler() for the `align` atom, this aligns the
final strbuf by calling `strbuf_utf8_align()` from utf8.c.

Ensure that quote formatting is performed on the whole of
%(align:...)...%(end) rather than individual atoms inside. We skip
quote formatting for individual atoms when the current stack element
is handling an %(align:...) atom and perform quote formatting at the
end when we encounter the %(end) atom of the second element of then
stack.

Add documentation and tests for the same.

Mentored-by: Christian Couder <christian.couder@gmail.com>
Mentored-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr>
Helped-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

ref-filter: introduce match_atom_name()Karthik Nayak Fri, 11 Sep 2015 14:59:47 +0000 (20:29 +0530)

ref-filter: introduce match_atom_name()

Introduce match_atom_name() which helps in checking if a particular
atom is the atom we're looking for and if it has a value attached to
it or not.

Use it instead of starts_with() for checking the value of %(color:...)
atom. Write a test for the same.

Mentored-by: Christian Couder <christian.couder@gmail.com>
Mentored-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr>
Thanks-to: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

ref-filter: introduce handler function for each atomKarthik Nayak Thu, 10 Sep 2015 15:48:20 +0000 (21:18 +0530)

ref-filter: introduce handler function for each atom

Introduce a handler function for each atom, which is called when the
atom is processed in show_ref_array_item().

In this context make append_atom() as the default handler function and
extract quote_formatting() out of append_atom(). Bump this to the top.

Mentored-by: Christian Couder <christian.couder@gmail.com>
Mentored-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr>
Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

utf8: add function to align a string into given strbufKarthik Nayak Thu, 10 Sep 2015 15:48:19 +0000 (21:18 +0530)

utf8: add function to align a string into given strbuf

Add strbuf_utf8_align() which will align a given string into a strbuf
as per given align_type and width. If the width is greater than the
string length then no alignment is performed.

Helped-by: Eric Sunshine <sunshine@sunshineco.com>
Mentored-by: Christian Couder <christian.couder@gmail.com>
Mentored-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr>
Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

ref-filter: introduce ref_formatting_state and ref_form... Karthik Nayak Thu, 10 Sep 2015 15:48:18 +0000 (21:18 +0530)

ref-filter: introduce ref_formatting_state and ref_formatting_stack

Introduce ref_formatting_state which will hold the formatted output
strbuf instead of directly printing to stdout. This will help us in
creating modifier atoms which modify the format specified before
printing to stdout.

Implement a stack machinery for ref_formatting_state, this allows us
to push and pop elements onto the stack. Whenever we pop an element
from the stack, the strbuf from that element is appended to the strbuf
of the next element on the stack, this will allow us to support
nesting of modifier atoms.

Rename some functions to reflect the changes made:
print_value() -> append_atom()
emit() -> append_literal()

Mentored-by: Christian Couder <christian.couder@gmail.com>
Mentored-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr>
Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

ref-filter: move `struct atom_value` to ref-filter.cKarthik Nayak Sat, 22 Aug 2015 03:39:37 +0000 (09:09 +0530)

ref-filter: move `struct atom_value` to ref-filter.c

Since atom_value is only required for the internal working of
ref-filter it doesn't belong in the public header.

Helped-by: Eric Sunshine <sunshine@sunshineco.com>
Mentored-by: Christian Couder <christian.couder@gmail.com>
Mentored-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr>
Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

strtoul_ui: reject negative valuesMatthieu Moy Thu, 17 Sep 2015 16:28:33 +0000 (18:28 +0200)

strtoul_ui: reject negative values

strtoul_ui uses strtoul to get a long unsigned, then checks that casting
to unsigned does not lose information and return the casted value.

On 64 bits architecture, checking that the cast does not change the value
catches most errors, but when sizeof(int) == sizeof(long) (e.g. i386),
the check does nothing. Unfortunately, strtoul silently accepts negative
values, and as a result strtoul_ui("-1", ...) raised no error.

This patch catches negative values before it's too late, i.e. before
calling strtoul.

Reported-by: Max Kirillov <max@max630.net>
Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

git-p4: improve path encoding verbose outputLars Schneider Wed, 16 Sep 2015 12:37:04 +0000 (14:37 +0200)

git-p4: improve path encoding verbose output

If a path with non-ASCII characters is detected then print the
encoding and the encoded string in verbose mode.

Signed-off-by: Lars Schneider <larsxschneider@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

blame: handle --first-parentJeff King Tue, 15 Sep 2015 10:05:39 +0000 (06:05 -0400)

blame: handle --first-parent

The revision.c options-parser will parse "--first-parent"
for us, but the blame code does not actually respect it, as
we simply iterate over the whole list returned by
first_scapegoat(). We can fix this by returning a
truncated parent list.

Note that we could technically also do so by limiting the
return value of num_scapegoats(), but that is less robust.
We would rely on nobody ever looking at the "next" pointer
from the returned list.

Combining "--reverse" with "--first-parent" is more
complicated, and will probably involve cooperation from
revision.c. Since the desired semantics are not even clear,
let's punt on this for now, but explicitly disallow it to
avoid confusing users (this is not really a regression,
since it did something nonsensical before).

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

mailmap: update my entry with new email addressRamsay Jones Tue, 1 Sep 2015 15:50:06 +0000 (16:50 +0100)

mailmap: update my entry with new email address

My 'demon' email address is no longer functional since, after 16+
years with demon, I have had to change my ISP. :(

Also, take the opportunity to remove my middle name, which I only
use on official documents (or in the GECOS field when creating a
user account on unix).

Signed-off-by: Ramsay Jones <ramsay@ramsayjones.plus.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

Update RelNotes to 2.6 to describe leftover bits since... Junio C Hamano Mon, 14 Sep 2015 22:00:41 +0000 (15:00 -0700)

Update RelNotes to 2.6 to describe leftover bits since -rc2

Signed-off-by: Junio C Hamano <gitster@pobox.com>

Merge branch 'js/maint-am-skip-performance-regression'Junio C Hamano Mon, 14 Sep 2015 21:59:07 +0000 (14:59 -0700)

Merge branch 'js/maint-am-skip-performance-regression'

Recent versions of scripted "git am" has a performance regression in
"git am --skip" codepath, which no longer exists in the built-in
version on the 'master' front. Fix the regression in the last
scripted version that appear in 2.5.x maintenance track and older.

* js/maint-am-skip-performance-regression:
am --skip/--abort: merge HEAD/ORIG_HEAD tree into index

Merge branch 'ah/show-ref-usage-string'Junio C Hamano Mon, 14 Sep 2015 21:59:06 +0000 (14:59 -0700)

Merge branch 'ah/show-ref-usage-string'

Both "git show-ref -h" and "git show-ref --help" illustrated that the
"--exclude-existing" option makes the command read list of refs
from its standard input. Change only the "show-ref -h" output to
have a pair of "<>" around the placeholder that designate an input
file, i.e. "git show-ref --exclude-existing < <ref-list>".

* ah/show-ref-usage-string:
show-ref: place angle brackets around variables in usage string

Merge branch 'sg/help-group'Junio C Hamano Mon, 14 Sep 2015 21:59:05 +0000 (14:59 -0700)

Merge branch 'sg/help-group'

* sg/help-group:
Makefile: use SHELL_PATH when running generate-cmdlist.sh

Merge branch 'rt/help-strings-fix'Junio C Hamano Mon, 14 Sep 2015 21:59:04 +0000 (14:59 -0700)

Merge branch 'rt/help-strings-fix'

* rt/help-strings-fix:
tag, update-ref: improve description of option "create-reflog"
pull: don't mark values for option "rebase" for translation