<feed xmlns='http://www.w3.org/2005/Atom'>
<title>git/git.c, branch v2.11.4</title>
<subtitle>Mirror of https://git.kernel.org/pub/scm/git/git.git/
</subtitle>
<id>https://www.git.shady.money/git/atom?h=v2.11.4</id>
<link rel='self' href='https://www.git.shady.money/git/atom?h=v2.11.4'/>
<link rel='alternate' type='text/html' href='https://www.git.shady.money/git/'/>
<updated>2017-01-09T21:41:40Z</updated>
<entry>
<title>execv_dashed_external: wait for child on signal death</title>
<updated>2017-01-09T21:41:40Z</updated>
<author>
<name>Jeff King</name>
<email>peff@peff.net</email>
</author>
<published>2017-01-07T01:22:23Z</published>
<link rel='alternate' type='text/html' href='https://www.git.shady.money/git/commit/?id=46df6906f3aaf74dafe2026b028c8c5c1a0d5f58'/>
<id>urn:sha1:46df6906f3aaf74dafe2026b028c8c5c1a0d5f58</id>
<content type='text'>
When you hit ^C to interrupt a git command going to a pager,
this usually leaves the pager running. But when a dashed
external is in use, the pager ends up in a funny state and
quits (but only after eating one more character from the
terminal!). This fixes it.

Explaining the reason will require a little background.

When git runs a pager, it's important for the git process to
hang around and wait for the pager to finish, even though it
has no more data to feed it. This is because git spawns the
pager as a child, and thus the git process is the session
leader on the terminal. After it dies, the pager will finish
its current read from the terminal (eating the one
character), and then get EIO trying to read again.

When you hit ^C, that sends SIGINT to git and to the pager,
and it's a similar situation.  The pager ignores it, but the
git process needs to hang around until the pager is done. We
addressed that long ago in a3da882120 (pager: do
wait_for_pager on signal death, 2009-01-22).

But when you have a dashed external (or an alias pointing to
a builtin, which will re-exec git for the builtin), there's
an extra process in the mix. For instance, running:

  $ git -c alias.l=log l

will end up with a process tree like:

  git (parent)
    \
     git-log (child)
      \
       less (pager)

If you hit ^C, SIGINT goes to all of them. The pager ignores
it, and the child git process will end up in wait_for_pager().
But the parent git process will die, and the usual EIO
trouble happens.

So we really want the parent git process to wait_for_pager(),
but of course it doesn't know anything about the pager at
all, since it was started by the child.  However, we can
have it wait on the git-log child, which in turn is waiting
on the pager. And that's what this patch does.

There are a few design decisions here worth explaining:

  1. The new feature is attached to run-command's
     clean_on_exit feature. Partly this is convenience,
     since that feature already has a signal handler that
     deals with child cleanup.

     But it's also a meaningful connection. The main reason
     that dashed externals use clean_on_exit is to bind the
     two processes together. If somebody kills the parent
     with a signal, we propagate that to the child (in this
     instance with SIGINT, we do propagate but it doesn't
     matter because the original signal went to the whole
     process group). Likewise, we do not want the parent
     to go away until the child has done so.

     In a traditional Unix world, we'd probably accomplish
     this binding by just having the parent execve() the
     child directly. But since that doesn't work on Windows,
     everything goes through run_command's more spawn-like
     interface.

  2. We do _not_ automatically waitpid() on any
     clean_on_exit children. For dashed externals this makes
     sense; we know that the parent is doing nothing but
     waiting for the child to exit anyway. But with other
     children, it's possible that the child, after getting
     the signal, could be waiting on the parent to do
     something (like closing a descriptor). If we were to
     wait on such a child, we'd end up in a deadlock. So
     this errs on the side of caution, and lets callers
     enable the feature explicitly.

  3. When we send children the cleanup signal, we send all
     the signals first, before waiting on any children. This
     is to avoid the case where one child might be waiting
     on another one to exit, causing a deadlock. We inform
     all of them that it's time to die before reaping any.

     In practice, there is only ever one dashed external run
     from a given process, so this doesn't matter much now.
     But it future-proofs us if other callers start using
     the wait_after_clean mechanism.

There's no automated test here, because it would end up racy
and unportable. But it's easy to reproduce the situation by
running the log command given above and hitting ^C.

Signed-off-by: Jeff King &lt;peff@peff.net&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>execv_dashed_external: stop exiting with negative code</title>
<updated>2017-01-09T21:41:35Z</updated>
<author>
<name>Jeff King</name>
<email>peff@peff.net</email>
</author>
<published>2017-01-07T01:17:48Z</published>
<link rel='alternate' type='text/html' href='https://www.git.shady.money/git/commit/?id=246f0edec0b789ccfeebcf7fef85417b7cb04425'/>
<id>urn:sha1:246f0edec0b789ccfeebcf7fef85417b7cb04425</id>
<content type='text'>
When we try to exec a git sub-command, we pass along the
status code from run_command(). But that may return -1 if we
ran into an error with pipe() or execve(). This tends to
work (and end up as 255 due to twos-complement wraparound
and truncation), but in general it's probably a good idea to
avoid negative exit codes for portability.

We can easily translate to the normal generic "128" code we
get when syscalls cause us to die.

Signed-off-by: Jeff King &lt;peff@peff.net&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>execv_dashed_external: use child_process struct</title>
<updated>2017-01-09T21:41:33Z</updated>
<author>
<name>Jeff King</name>
<email>peff@peff.net</email>
</author>
<published>2017-01-07T01:16:24Z</published>
<link rel='alternate' type='text/html' href='https://www.git.shady.money/git/commit/?id=2b296c93d49d65303a4ce291225c8755eeab1ff8'/>
<id>urn:sha1:2b296c93d49d65303a4ce291225c8755eeab1ff8</id>
<content type='text'>
When we run a dashed external, we use the one-liner
run_command_v_opt() to do so. Let's switch to using a
child_process struct, which has two advantages:

  1. We can drop all of the allocation and cleanup code for
     building our custom argv array, and just rely on the
     builtin argv_array (at the minor cost of doing a few
     extra mallocs).

  2. We have access to the complete range of child_process
     options, not just the ones that the "_opt()" form can
     forward.

Signed-off-by: Jeff King &lt;peff@peff.net&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>Merge branch 'jk/common-main'</title>
<updated>2016-11-29T20:22:13Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2016-11-29T20:22:13Z</published>
<link rel='alternate' type='text/html' href='https://www.git.shady.money/git/commit/?id=95c2b13a5fc06db6556def93843653e948e71e4b'/>
<id>urn:sha1:95c2b13a5fc06db6556def93843653e948e71e4b</id>
<content type='text'>
Fix for a small regression in a topic already in 'master'.

* jk/common-main:
  common-main: stop munging argv[0] path
</content>
</entry>
<entry>
<title>common-main: stop munging argv[0] path</title>
<updated>2016-11-29T19:01:48Z</updated>
<author>
<name>Jeff King</name>
<email>peff@peff.net</email>
</author>
<published>2016-11-27T04:31:13Z</published>
<link rel='alternate' type='text/html' href='https://www.git.shady.money/git/commit/?id=6854a8f5c9ecf32f5bd85020e77d48d3ffdf48fc'/>
<id>urn:sha1:6854a8f5c9ecf32f5bd85020e77d48d3ffdf48fc</id>
<content type='text'>
Since 650c44925 (common-main: call git_extract_argv0_path(),
2016-07-01), the argv[0] that is seen in cmd_main() of
individual programs is always the basename of the
executable, as common-main strips off the full path. This
can produce confusing results for git-daemon, which wants to
re-exec itself.

For instance, if the program was originally run as
"/usr/lib/git/git-daemon", it will try just re-execing
"git-daemon", which will find the first instance in $PATH.
If git's exec-path has not been prepended to $PATH, we may
find the git-daemon from a different version (or no
git-daemon at all).

Normally this isn't a problem. Git commands are run as "git
daemon", the git wrapper puts the exec-path at the front of
$PATH, and argv[0] is already "daemon" anyway. But running
git-daemon via its full exec-path, while not really a
recommended method, did work prior to 650c44925. Let's make
it work again.

The real goal of 650c44925 was not to munge argv[0], but to
reliably set the argv0_path global. The only reason it
munges at all is that one caller, the git.c wrapper,
piggy-backed on that computation to find the command
basename.  Instead, let's leave argv[0] untouched in
common-main, and have git.c do its own basename computation.

While we're at it, let's drop the return value from
git_extract_argv0_path(). It was only ever used in this one
callsite, and its dual purposes is what led to this
confusion in the first place.

Note that by changing the interface, the compiler can
confirm for us that there are no other callers storing the
return value. But the compiler can't tell us whether any of
the cmd_main() functions (besides git.c) were relying on the
basename munging. However, we can observe that prior to
650c44925, no other cmd_main() functions did that munging,
and no new cmd_main() functions have been introduced since
then. So we can't be regressing any of those cases.

Signed-off-by: Jeff King &lt;peff@peff.net&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>archive: read local configuration</title>
<updated>2016-11-22T21:55:20Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2016-11-22T21:37:04Z</published>
<link rel='alternate' type='text/html' href='https://www.git.shady.money/git/commit/?id=eb0224c617ba6b4299f2a9f85d6c4b3b5e10abc0'/>
<id>urn:sha1:eb0224c617ba6b4299f2a9f85d6c4b3b5e10abc0</id>
<content type='text'>
Since b9605bc4f2 ("config: only read .git/config from configured
repos", 2016-09-12), we do not read from ".git/config" unless we
know we are in a repository.  "git archive" however didn't do the
repository discovery and instead relied on the old behaviour.

Teach the command to run a "gentle" version of repository discovery
so that local configuration variables are honoured.

[jc: stole tests from peff]
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>mailinfo: read local configuration</title>
<updated>2016-11-22T21:13:16Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2016-11-22T21:13:16Z</published>
<link rel='alternate' type='text/html' href='https://www.git.shady.money/git/commit/?id=3f0ec0687d95e0f53c899f964d769ca1846874da'/>
<id>urn:sha1:3f0ec0687d95e0f53c899f964d769ca1846874da</id>
<content type='text'>
Since b9605bc4f2 ("config: only read .git/config from configured
repos", 2016-09-12), we do not read from ".git/config" unless we
know we are in a repository.  "git mailinfo" however didn't do the
repository discovery and instead relied on the old behaviour.  This
was mostly OK because it was merely run as a helper program by other
porcelain scripts that first chdir's up to the root of the working
tree.

Teach the command to run a "gentle" version of repository discovery
so that local configuration variables like mailinfo.scissors are
honoured.

Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>Merge branch 'jc/cocci-xstrdup-or-null'</title>
<updated>2016-10-26T20:14:45Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2016-10-26T20:14:45Z</published>
<link rel='alternate' type='text/html' href='https://www.git.shady.money/git/commit/?id=a03973893bdbc1a53c705daf70a73994ac46492f'/>
<id>urn:sha1:a03973893bdbc1a53c705daf70a73994ac46492f</id>
<content type='text'>
Code cleanup.

* jc/cocci-xstrdup-or-null:
  cocci: refactor common patterns to use xstrdup_or_null()
</content>
</entry>
<entry>
<title>Merge branch 'bw/ls-files-recurse-submodules'</title>
<updated>2016-10-26T20:14:44Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2016-10-26T20:14:44Z</published>
<link rel='alternate' type='text/html' href='https://www.git.shady.money/git/commit/?id=1c2b1f7018ba7d5f6a5d949e29e4eaeeef3261e2'/>
<id>urn:sha1:1c2b1f7018ba7d5f6a5d949e29e4eaeeef3261e2</id>
<content type='text'>
"git ls-files" learned "--recurse-submodules" option that can be
used to get a listing of tracked files across submodules (i.e. this
only works with "--cached" option, not for listing untracked or
ignored files).  This would be a useful tool to sit on the upstream
side of a pipe that is read with xargs to work on all working tree
files from the top-level superproject.

* bw/ls-files-recurse-submodules:
  ls-files: add pathspec matching for submodules
  ls-files: pass through safe options for --recurse-submodules
  ls-files: optionally recurse into submodules
  git: make super-prefix option
</content>
</entry>
<entry>
<title>cocci: refactor common patterns to use xstrdup_or_null()</title>
<updated>2016-10-12T18:22:10Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2016-10-12T18:20:23Z</published>
<link rel='alternate' type='text/html' href='https://www.git.shady.money/git/commit/?id=13092a916d7b8211fd828a6a7ee0d3cefff995e1'/>
<id>urn:sha1:13092a916d7b8211fd828a6a7ee0d3cefff995e1</id>
<content type='text'>
d64ea0f83b ("git-compat-util: add xstrdup_or_null helper",
2015-01-12) added a handy wrapper that allows us to get a duplicate
of a string or NULL if the original is NULL, but a handful of
codepath predate its introduction or just weren't aware of it.

Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
</feed>
