Only wait for pack if we need it

Provide the git_remote_download function to instruct the library to
downlad the packfile and let the user know the temporary location.

Signed-off-by: Carlos Martín Nieto <carlos@cmartin.tk>
Use common capabilities

Signed-off-by: Carlos Martín Nieto <carlos@cmartin.tk>
Use strcpy+strcat as memcpy was overlapping

Signed-off-by: Carlos Martín Nieto <carlos@cmartin.tk>
Rethrow pack entry offset error

Signed-off-by: Carlos Martín Nieto <carlos@cmartin.tk>
Implement cooperative caching

When indexing a file with ref deltas, a temporary cache for the
offsets has to be built, as we don't have an index file yet. If the
user takes the responsiblity for filling the cache, the packing code
will look there first when it finds a ref delta.

Signed-off-by: Carlos Martín Nieto <carlos@cmartin.tk>
Add git_remote_update_tips

This function updates the references in the local reference storage to
match the ones in the remote.

Signed-off-by: Carlos Martín Nieto <carlos@cmartin.tk>
Don't try to download the packfile too early

Make sure we only try to download the pack if we find the pack header
in the stream, and not if the server takes a bit longer to send us the
last NAK.

Signed-off-by: Carlos Martín Nieto <carlos@cmartin.tk>
Assert a filename in indexer creation

Signed-off-by: Carlos Martín Nieto <carlos@cmartin.tk>
Remove enum git_whn

Instead, use flags inside the git_remote_head structure.

Signed-off-by: Carlos Martín Nieto <carlos@cmartin.tk>
Be smarter about selecting wants

There is no need to inspect what the local repository is like. Only
check whether the objects exist locally.

Signed-off-by: Carlos Martín Nieto <carlos@cmartin.tk>
Use time sorting in fetch

This is what the docs say tha we should use.

Signed-off-by: Carlos Martín Nieto <carlos@cmartin.tk>
Update transport lifetime documentation

The original was written before any code was written and had nothing
to do with the way things are actually done.

Signed-off-by: Carlos Martín Nieto <carlos@cmartin.tk>
Move negotiation to the transport

There are many ways how a transport might negotiate with the server,
so instead of making it fit into the smart protocol model, let the
transport do its thing. For now, the git protocol limits itself to
send only 160 "have" lines so we don't flood the server.

Signed-off-by: Carlos Martín Nieto <carlos@cmartin.tk>
Implement and bind local_send_wants

Signed-off-by: Carlos Martín Nieto <carlos@cmartin.tk>
Actually implement object negotiation

Only signal that we need a pack if we do need it and don't send a want
just because it's the first. If we don't need to download the pack,
then we can skip all of the negotiation and just return success.

Signed-off-by: Carlos Martín Nieto <carlos@cmartin.tk>
Keep sending want lines if the server doesn't anwer a flush

Some servers take a long time to answer and expect us to keep sending
want lines; otherwise they close the connection. Avoid this by waiting
for one second for the server to answer. If the timeout runs out,
treat is as a NAK and keep sending want lines.

Signed-off-by: Carlos Martín Nieto <carlos@cmartin.tk>
odb: Do not pass around a header when hashing
posix: Properly handle `snprintf` in all platforms
transport: Merge bitfield

I don't think MSVC merges these automatically.
Fix false positive -Wuninitialized warnings

GCC produces several -Wuninitialized warnings. Most of them can be fixed
if we make visible for gcc that git__throw() and git__rethrow() always
return first argument.

Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>