clear parsed flag when we free tree buffers

Many code paths will free a tree object's buffer and set it
to NULL after finishing with it in order to keep memory
usage down during a traversal. However, out of 8 sites that
do this, only one actually unsets the "parsed" flag back.
Those sites that don't are setting a trap for later users of
the tree object; even after calling parse_tree, the buffer
will remain NULL, causing potential segfaults.

It is not known whether this is triggerable in the current
code. Most commands do not do an in-memory traversal
followed by actually using the objects again. However, it
does not hurt to be safe for future callers.

In most cases, we can abstract this out to a
"free_tree_buffer" helper. However, there are two
exceptions:

  1. The fsck code relies on the parsed flag to know that we
     were able to parse the object at one point. We can
     switch this to using a flag in the "flags" field.

  2. The index-pack code sets the buffer to NULL but does
     not free it (it is freed by a caller). We should still
     unset the parsed flag here, but we cannot use our
     helper, as we do not want to free the buffer.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
remote-hg: support for notes

Keep track of Mercurial revisions as Git notes under the 'refs/notes/hg'
ref, this way, the user can easily see which Mercurial revision
correspond to certain Git commit.

Unfortunately, there's no way to efficiently update the notes after
doing an export (push), so they'll have to be updated when importing
(fetching).

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
contrib/remote-helpers: style updates for test scripts

During the review of the main series it was noticed that these test
scripts can use updates to conform to our coding style better, but
fixing the style should be done in a patch separate from the main
series.

This updates the test-*.sh scripts only for styles:

 * We do not leave SP between a redirection operator and the
   filename;

 * We change line before "then", "do", etc. rather than terminating
   the condition for "if"/"while" and list for "for" with a
   semicolon;

 * When HERE document does not use any expansion, we quote the end
   marker (e.g. "cat <<\EOF" not "cat <<EOF") to signal the readers
   that there is no funny substitution to worry about when reading
   the code.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
contrib/remote-helpers: quote variable references in redirection targets

Even though it is not required by POSIX to double-quote the
redirection target in a variable, our code does so because some
versions of bash issue a warning without the quotes.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
Merge branch 'jc/pager-configuration-doc' into pu

* jc/pager-configuration-doc:
  config: rewrite core.pager documentation
Merge branch 'np/pack-v4' into pu

* np/pack-v4: (23 commits)
  initial pack index v3 support on the read side
  pack v4: add progress display
  pack v4: normalize pack name to properly generate the pack index file name
  pack index v3
  pack v4: relax commit parsing a bit
  pack v4: honor pack.compression config option
  pack v4: load delta candidate for encoding tree objects
  pack v4: tree object delta encoding
  pack v4: object writing
  pack v4: object data copy
  pack v4: object headers
  pack v4: creation code
  pack v4: dictionary table output
  pack v4: tree object encoding
  pack v4: commit object encoding
  pack v4: basic references encoding
  pack v4: move to struct pack_idx_entry and get rid of our own struct idx_entry
  pack v4: split the object list and dictionary creation
  pack v4: add commit object parsing
  pack v4: add tree entry mode support to dictionary entries
  ...
Merge branch 'fc/contrib-bzr-hg-fixes' into pu

* fc/contrib-bzr-hg-fixes:
  contrib/remote-helpers: quote variable references in redirection targets
  contrib/remote-helpers: style updates for test scripts
  remote-hg: support for notes
  remote-helpers: cleanup more global variables
  remote-helpers: trivial style fixes
  remote-hg: improve basic test
  remote-hg: add missing &&s in the test
  remote-hg: fix test
  remote-bzr: make bzr branches configurable per-repo
  remote-bzr: fix export of utf-8 authors
Merge branch 'jk/free-tree-buffer' into pu

* jk/free-tree-buffer:
  clear parsed flag when we free tree buffers