send-pack.c: add an --atomic-push command line argument

This adds support to send-pack to negotiate and use atomic pushes
iff the server supports it. Atomic pushes are activated by a new command
line flag --atomic-push.

In order to do this we also need to change the semantics for send_pack()
slightly. The existing send_pack() function actually don't sent all the
refs back to the server when multiple refs are involved, for example
when using --all. Several of the failure modes for pushes can already be
detected locally in the send_pack client based on the information from the
initial server side list of all the refs as generated by receive-pack.
Any such refs that we thus know would fail to push are thus pruned from
the list of refs we send to the server to update.

For atomic pushes, we have to deal thus with both failures that are detected
locally as well as failures that are reported back from the server. In order
to do so we treat all local failures as push failures too.

We introduce a new status code REF_STATUS_ATOMIC_PUSH_FAILED so we can
flag all refs that we would normally have tried to push to the server
but we did not due to local failures. This is to improve the error message
back to the end user to flag that "these refs failed to update since the
atomic push operation failed."

Change-Id: I1444d896f6bc6b6f1078b893b5a5b5186b445159
Signed-off-by: Ronnie Sahlberg <sahlberg@google.com>
receive-pack.c: use a single transaction when atomic-push is negotiated

Update receive-pack to use an atomic transaction iff the client negotiated
that it wanted atomic-push.
This leaves the default behavior to be the old non-atomic one ref at a
time update. This is to cause as little disruption as possible to existing
clients. It is unknown if there are client scripts that depend on the old
non-atomic behavior so we make it opt-in for now.

Later patch in this series also adds a configuration variable where you can
override the atomic push behavior on the receiving repo and force it
to use atomic updates always.

If it turns out over time that there are no client scripts that depend on the
old behavior we can change git to default to use atomic pushes and instead
offer an opt-out argument for people that do not want atomic pushes.

Change-Id: I233594fbff357383b794230672beab7933e3ce0f
Signed-off-by: Ronnie Sahlberg <sahlberg@google.com>
push.c: add an --atomic-push argument

Add a command line argument to the git push command to request atomic
pushes.

Change-Id: I2e17cbd4d53f7f8bd55f0477363af6173522e09a
Signed-off-by: Ronnie Sahlberg <sahlberg@google.com>
t5543-atomic-push.sh: add basic tests for atomic pushes

Change-Id: I16bb0b85a7f780e1e5b55b90d13784662d20e701
Signed-off-by: Ronnie Sahlberg <sahlberg@google.com>
refs.c: add an err argument to create_reflog

Add err argument to create_reflog that can explain the reason for a
failure. This then eliminates the need to manage errno through this
function since we can just add strerror(errno) to the err string when
meaningful. No callers relied on errno from this function for anything
else than the error message.

log_ref_write is a private function that calls create_reflog. Update
this function to also take an err argument and pass it back to the caller.
This again eliminates the need to manage errno in this function.

Update the private function write_sha1_update_reflog to also take an
err argument.

Change-Id: I0a69959b47f9261e77beac1d1923ad408eee48f9
Signed-off-by: Ronnie Sahlberg <sahlberg@google.com>
refs.c: add an err argument to create_symref

Change-Id: I581c35aee25daa93be47febddc0f5aca675d2d0c
Signed-off-by: Ronnie Sahlberg <sahlberg@google.com>
refs.c: create a public version of is_refname_available

Create a public version of is_refname_available that backends can provide.

Change-Id: I0f49bb8722eeb4cf9c65139fb3d6c7fd4cbd27b3
Signed-off-by: Ronnie Sahlberg <sahlberg@google.com>
refs-be-files.c: rename refs to refs-be-files

Rename refs.c to refs-be-files.c to indicate that this file now
holds the implementation for the files based refs backend.
A smaller portion of the code in this file is backend agnostic and will
be moved to a a new refs.c file that will hold all the common refs code
that is shared across all backends.

A second reason for first moving all the code to the new file and then move
the backend agnostic code back to refs.c instead of the other way around
is because the code that will eventually remain in this new refs-be-files.c
file is so entangled that it would then be very difficult to break the split
up into small independent patches/chunks.

Change-Id: I7a381773e24b1f54c8131f304c9b61b61a574e42
Signed-off-by: Ronnie Sahlberg <sahlberg@google.com>
refs.c: add a new refs.c file to hold all common refs code

Create a new refs.c file that will be used to hold all the refs
code that is backend agnostic and will be shared across all backends.

Change-Id: I1c04e9044f1101be9be6aa1618a0571b88ac1657
Signed-off-by: Ronnie Sahlberg <sahlberg@google.com>
refs.c: move update_ref to refs.c

This change moves update_ref() to the refs.c file since this function
does not contain any backend specific code.

Change-Id: I9477f508bcb50ce5e8e478633b5ffca654479961
Signed-off-by: Ronnie Sahlberg <sahlberg@google.com>
refs.c: move delete_ref to the common code

This change moves delete_ref() to the refs.c file since this function
does not contain any backend specific code.

Change-Id: I43e4eee700e87aa42e3627c7232878d9edbe39a0
Signed-off-by: Ronnie Sahlberg <sahlberg@google.com>
refs.c: make copy_reflog_into_strbuf a public function

Change-Id: I5f6a821b4d510c3b4ddc23923e0c6172f14500d5
Signed-off-by: Ronnie Sahlberg <sahlberg@google.com>
refs.c: move rename_ref to the common code

This change moves rename_ref() to the refs.c file since this function
does not contain any backend specific code.

Change-Id: I23ef0ca93c63916c57fc977747af915a4010e6b4
Signed-off-by: Ronnie Sahlberg <sahlberg@google.com>
refs.c: move read_ref_at to the common refs file

This change moves read_ref_at() to the refs.c file since this function
does not contain any backend specific code.

Change-Id: I081b736043420a9be229d104372a8dbe5536855a
Signed-off-by: Ronnie Sahlberg <sahlberg@google.com>
refs.c: move the hidden refs functions to the common code

This change moves the hidden refs functions to the refs.c file since
these functions do not contain any backend specific code.

Change-Id: I4ef2e6629a19fd93e927e9e983babfc5f2fd8662
Signed-off-by: Ronnie Sahlberg <sahlberg@google.com>
refs.c: move dwim and friend functions to the common refs code

These functions do not contain any backend specific code so we can move
them to the common code and share across all backends.

Change-Id: Id5341b917ad959c015bbf8b3664d94d43b7f6661
Signed-off-by: Ronnie Sahlberg <sahlberg@google.com>
refs.c: move warn_if_dangling_symref* to the common code

These functions do not use any backend specific code so we can move
them to the common code.

Change-Id: Ib64451ad56a48c60e14d5ddfc93dfab4679895c2
Signed-off-by: Ronnie Sahlberg <sahlberg@google.com>
refs.c: move read_ref, read_ref_full and ref_exists to the common code

These functions do not depend on the backend implementation so we
can move them to the common code.

Change-Id: If74ad16b71b5b3f65f39585dc573df044e061e35
Signed-off-by: Ronnie Sahlberg <sahlberg@google.com>
refs.c: move resolve_refdup to common

This function can be shared across all refs backends so move it
to the common code.

Change-Id: I4d6edb1127cb73d5b35fd30c6621cf3f6f602843
Signed-off-by: Ronnie Sahlberg <sahlberg@google.com>
refs.c: move check_refname_component to the common code

This function does not contain any backend specific code so we
can move it to the common code.

Change-Id: Iee542bfa4dab4e3a5a778d0b22da9fac25223413
Signed-off-by: Ronnie Sahlberg <sahlberg@google.com>