peel_entry(): use the ref_entry's peeled field

If the peeled field is already set, use the existing value instead of
looking up the object again.  If we have to peel the reference, write
the result to the peeled field for future use.
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: extract function peel_object()

It is a nice, logical unit of work, and it is needed from two places
in peel_ref().
Use peel_object() in implementation of peel_entry()

Aside from sharing code, this lets peel_entry() take advantage of the
optimization introduced by 6c4a060d7d.
Change search_ref_dir() to return an index

Change search_ref_dir() to return the index of the sought entry (or -1
on error).  This will make it possible to use the function for
removing an entry from the list.
Allow packed refs to be removed without discarding cache

Add a function remove_ref(), which removes a single entry from a
reference cache.

Use this function to reimplement repack_without_ref().  The old
version iterated over all refs, packing all of them except for the one
to be deleted, then discarded the entire packed reference cache.  The
new version deletes the doomed reference *before* iterating.

This has two advantages: (1) the code for writing packed-refs becomes
simpler, because it doesn't have to exclude one of the references.
(2) it is no longer necessary for repack_without_ref() to discard the
packed refs cache (symbolic refs cannot be packed, so packed
references cannot depend on each other, so the rest of the packed refs
cache remains valid after a reference is deleted).
refs: define constants PEELED_LINE_LENGTH and PACKED_REFS_HEADER

In a moment we will use them from another function, too.
repack_without_ref(): write peeled refs in the rewritten file

When a reference that existed in the packed-refs file is deleted, the
packed-refs file must be rewritten.  Previously, the file was
rewritten without any peeled refs, even if the file contained peeled
refs when it was read.  Teach repack_without_ref() to write peeled
refs to the file, just like pack_refs() does.

If the peeled value of a reference is already known (e.g., because it
was read from the old version of the packed-refs file), then that
value is output again without any checks.  This is the usual code path
and should not introduce any noticeable overhead.

If the peeled value of a reference is not already known, then we
attempt to look it up.  This will cost some extra time, but should
only happen the first time the packed-refs file is touched by a
version of Git that knows about the "fully-peeled" attribute.

But please note that there is a subtlety here.  A packed reference
might be overridden by a loose reference and therefore obsolete.  In
this case the object that it refers to might not even exist anymore.
In this case, if we try to peel the reference, parse_object() fails
and we write the reference but no peeled value to the packed-refs
file.