Fix '\ No newline...' annotation in rewrite diffs

When a file that ends with an incomplete line is expressed as a
complete rewrite with the -B option, git diff incorrectly
appends the incomplete line indicator "\ No newline at end of
file" after such a line, rather than writing it on a line of its
own (the output codepath for normal output without -B does not
have this problem).  Add a LF after the incomplete line before
writing the "\ No newline ..." out to fix this.

Add a couple of tests to confirm that the indicator comment is
generated on its own line in both plain diff and rewrite mode.

Signed-off-by: Adam Butcher <dev.lists@jessamine.co.uk>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
terminal: seek when switching between reading and writing

When a stdio stream is opened in update mode (e.g., "w+"),
the C standard forbids switching between reading or writing
without an intervening positioning function. Many
implementations are lenient about this, but Solaris libc
will flush the recently-read contents to the output buffer.
In this instance, that meant writing the non-echoed password
that the user just typed to the terminal.

Fix it by inserting a no-op fseek between the read and
write.

The opposite direction (writing followed by reading) is also
disallowed, but our intervening fflush is an acceptable
positioning function for that alternative.

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

Now that git_terminal_prompt can cleanly interact with /dev/tty on
Solaris, enable HAVE_DEV_TTY so that this code path is used for
credential reading instead of relying on the crippled getpass().

Signed-off-by: Ben Walton <bwalton@artsci.utoronto.ca>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/t5400: demonstrate breakage caused by informational message from prune

When receive-pack triggers 'git gc --auto' and 'git prune' is called to
remove a stale temporary object, 'git prune' prints an informational
message to stdout about the file that it will remove.  Since this message
is written to stdout, it is sent back over the transport channel to the git
client which tries to interpret it as part of the pack protocol and then
promptly terminates with a complaint about a protocol error.

Introduce a test which exercises the auto-gc functionality of receive-pack
and demonstrates this breakage.

Signed-off-by: Brandon Casey <drafnel@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
receive-pack: do not leak output from auto-gc to standard output

The standard output channel of receive-pack is a structured protocol
channel, and subprocesses must never be allowed to leak anything
into it by writing to their standard output.

Use RUN_COMMAND_STDOUT_TO_STDERR option to run_command_v_opt() just
like we do when running hooks to prevent output from "gc" leaking to
the standard output.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
Merge branch 'bw/maint-1.7.9-solaris-getpass' into next

The recent update to terminal I/O interface to get passwords &c
interactively didn't quite work on Solaris.

Will merge by 1.7.12 final.

* bw/maint-1.7.9-solaris-getpass:
  Enable HAVE_DEV_TTY for Solaris
  terminal: seek when switching between reading and writing
Merge branch 'ab/diff-write-incomplete-line' into next

The output from "git diff -B" for a file that ends with an
incomplete line did not put "\ No newline..." on a line of its own.

* ab/diff-write-incomplete-line:
  Fix '\ No newline...' annotation in rewrite diffs
Merge branch 'bc/receive-pack-stdout-protection' into next

When "git push" triggered the automatic gc on the receiving end, a
message from "git prune" that said it was removing cruft leaked to
the standard output, breaking the communication protocol.

Not urgent (non regression).

* bc/receive-pack-stdout-protection:
  receive-pack: do not leak output from auto-gc to standard output
  t/t5400: demonstrate breakage caused by informational message from prune
Sync with 1.7.12-rc2
Merge branch 'jk/blame-tree' into HEAD

* jk/blame-tree:
  blame-tree wip
Merge branch 'jk/builtin-attr' into HEAD

* jk/builtin-attr:
  attr: map builtin userdiff drivers to well-known extensions
Merge branch 'jk/bundle-fetch' into HEAD

* jk/bundle-fetch:
  clone: give advice on how to resume a failed clone
  remote-curl: resume interrupted bundle transfers
  remote-curl: show progress for bundle downloads
  progress: allow pure-throughput progress meters
  remote-curl: try base $URL after $URL/info/refs
  remote-curl: auto-detect bundles when fetching refs
  remote-curl: free "discovery" object
  bundle: add is_bundle_buf helper
  transport: factor out bundle to ref list conversion
  remote-curl: use http callback for requesting refs
  http: add a public function for arbitrary-callback request
  http: refactor http_request function
  http: turn off curl signals
  t/lib-httpd: check for NO_CURL
Merge branch 'jk/cache-patch-id' into HEAD

* jk/cache-patch-id:
  cache patch ids on disk
  cherry: read default config
  implement metadata cache subsystem
  map: implement persistent maps
  decorate: use "map" for the underlying implementation
  fast-export: use object to uint32 map instead of "decorate"
  map: add helper functions for objects as keys
  implement generic key/value map
Merge branch 'jk/cache-renames' into HEAD

* jk/cache-renames:
  diff: optionally use rename cache
  implement rename cache

Conflicts:
	Makefile
	metadata-cache.c
	metadata-cache.h
Merge branch 'jk/check-docs' into HEAD

# By Jeff King (4) and Matthieu Moy (1)
* jk/check-docs:
  command-list: mention git-credential-* helpers
  command-list: add git-sh-i18n
  check-docs: update non-command documentation list
  check-docs: mention gitweb specially
  Documentation: list git-credential in plumbing commands
Merge branch 'jk/child-cleanup' into HEAD

* jk/child-cleanup:
  send-pack: kill pack-objects helper on signal or exit
Merge branch 'jk/clone-file-local' into HEAD

* jk/clone-file-local:
  clone: send diagnostic messages to stderr
Merge branch 'jk/config-sources' into HEAD

* jk/config-sources:
  show sources of config options (WIP)
Merge branch 'jk/deleted-branch-reflogs' into HEAD

* jk/deleted-branch-reflogs:
  add tests for reflogs of deleted refs
  teach sha1_name to look in graveyard reflogs
  retain reflogs for deleted refs
Merge branch 'jk/describe' into HEAD

* jk/describe:
  describe WIP