fast-import: Fix an gcc -Wuninitialized warning

Commit cbfd5e1c ("drop some obsolete "x = x" compiler warning hacks",
21-03-2013) removed a gcc hack that suppressed an "might be used
uninitialized" warning issued by older versions of gcc.

However, commit 3aa99df8 ('fast-import: clarify "inline" logic in
file_change_m', 21-03-2013) addresses an (almost) identical issue
(with very similar code), but includes additional code in it's
resolution. The solution used by this commit, unlike that used by
commit cbfd5e1c, also suppresses the -Wuninitialized warning on
older versions of gcc.

In order to suppress the warning (against the 'oe' symbol) in the
note_change_n() function, we adopt the same solution used by commit
3aa99df8.

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
cat-file: Fix an gcc -Wuninitialized warning

After commit cbfd5e1c ("drop some obsolete "x = x" compiler warning
hacks", 21-03-2013) removed a gcc specific hack, older versions of
gcc now issue an "'contents' might be used uninitialized" warning.
In order to suppress the warning, we simply initialize the variable
to NULL in it's declaration.

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Merge branch 'maint'

* maint:
  cat-file: Fix an gcc -Wuninitialized warning
  fast-import: Fix an gcc -Wuninitialized warning
refs: document flags constants REF_*

Document the bits that can appear in the "flags" parameter passed to
an each_ref_function and/or in the ref_entry::flag field.
refs: document do_for_each_ref() and do_one_ref()
refs: document how current_ref is used
refs: extract a function ref_is_broken()

It is a nice unit of work and soon will be needed from multiple
locations.
get_packed_ref(): return a ref_entry

Instead of copying the reference's SHA1 into a caller-supplied
variable, just return the ref_entry itself (or NULL if there is no
such entry).  This change will allow the function to be used from
elsewhere.
peel_ref(): use function get_packed_ref()
repack_without_ref(): use function get_packed_ref()
refs: extract function peel_object()

It is a nice, logical unit of work, and it is needed from two places
in peel_ref().  Soon it will also have other uses.
peel_ref(): fix return value for non-peelable, not-current reference

The old version returned 0 for any non-current reference with
REF_KNOWS_PEELED, regardless of whether the peeled value was in fact
non-null.  Change the behavior to be the same as that for current_ref:
only return 0 if the peeled value is non-null.  As a bonus, document
the function.

Current callers did not trigger the buggy behavior.
refs: extract a function peel_entry()

Peel the entry, and as a side effect store the peeled value in the
entry.  Use this function from two places in peel_ref(); a third
caller will be added soon.
refs: change the internal reference-iteration API

Establish an internal API for iterating over references, which gives
the callback functions direct access to the ref_entry structure
describing the reference.  (Do not change the iteration API that is
exposed outside of the module.)

Define a new internal callback signature

   int each_ref_entry_fn(struct ref_entry *entry, void *cb_data)

Change do_for_each_ref_in_dir() and do_for_each_ref_in_dirs() to
accept each_ref_entry_fn callbacks, and rename them to
do_for_each_entry_in_dir() and do_for_each_entry_in_dirs(),
respectively.  Adapt their callers accordingly.

Add a new function do_for_each_entry() analogous to do_for_each_ref()
but using the new callback style.

Change do_one_ref() into an each_ref_entry_fn that does some
bookkeeping and then calls a wrapped each_ref_fn.

Reimplement do_for_each_ref() in terms of do_for_each_entry(), using
do_one_ref() as an adapter.

Please note that the responsibility for setting current_ref remains in
do_one_ref(), which means that current_ref is *not* set when iterating
over references via the new internal API.  This is not a disadvantage,
because current_ref is not needed by callers of the internal API (they
receive a pointer to the current ref_entry anyway).  But more
importantly, this change prevents peel_ref() from returning invalid
results in the following scenario:

When iterating via the external API, the iteration always includes
both packed and loose references, and in particular never presents a
packed ref if there is a loose ref with the same name.  The internal
API, on the other hand, gives the option to iterate over only the
packed references.  During such an iteration, there is no check of
whether the packed ref might be hidden by a loose ref of the same
name.  But until now the packed ref was recorded in current_ref during
the iteration.  So if peel_ref() were called on the current ref, it
would return the peeled version of the packed ref even though there
might be a loose ref that peels to a different value.  This scenario
doesn't currently occur in the code, but fix it to prevent things from
breaking in a very confusing way in the future.
pack-refs: rename handle_one_ref() to pack_one_ref()

This code is about to be moved, so name the function more
distinctively.
pack-refs: merge code from pack-refs.{c,h} into refs.{c,h}

pack-refs.c doesn't contain much code, and the code it does contain is
closely related to reference handling.  Moreover, there is a lot of
duplication between pack_refs() and repack_without_ref().  Therefore,
merge pack-refs.c into refs.c and pack-refs.h into refs.h.

The code duplication will be addressed in future commits.
pack_one_ref(): rename "path" parameter to "refname"

Make this function conform to the naming convention established in
65385ef7d4 for the rest of the refs.c file.
refs: use same lock_file object for both ref-packing functions

Use a single struct lock_file for both of the reference-packing
functions (pack_refs() and repack_without_ref()).
pack_refs(): change to use do_for_each_entry()

pack_refs() was not using any of the extra features of for_each_ref(),
so change it to use do_for_each_entry().  This also gives it access to
the ref_entry and in particular its peeled field, which might come in
handy in a commit or two.
pack_one_ref(): use function peel_object()

Change pack_one_ref() to call peel_object() rather than using its own
code for peeling references.  Aside from sharing code, this lets it
take advantage of the optimization introduced by 6c4a060d7d.

Please note that a different alternative would be for pack_one_ref()
to call peel_entry().  This would allow it to use known peeled values
from the reference cache and thereby avoid object lookups.  But it
would also propagate any peeling errors across runs of "git
pack-refs".  So instead, re-peel references every time "git pack-refs"
is run to allow recovery from such errors; pack-refs isn't run often
enough that the performance cost is significant.