git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 0/3] Fixing volatile HEAD in push.default = current

From
Junio C Hamano <gitster@pobox.com>
Date
May 22, 2013, 17:11 UTC
Message-ID
<7vppwjj5ws.fsf@alter.siamese.dyndns.org>
In-Reply-To
<CALkWK0kXonM+J92KHs+dW31A_kZ8h9jNqwYn8AqT_V+GJhe_vg@mail.gmail.com>
Ramkumar Ramachandra <artagnon@gmail.com> writes:
Show 6 quoted lines
> Junio C Hamano wrote:
>> The patch may have been done by a wrong motivation, in that it does
>> not fundamentally "fix" the itch.  The particular "itch" is not
>> something we are going to promise to the end users, ever, anyway.
>
> Just out of curiosity, is it possible to write a correct fix at all?
Is there anything to "fix" in the first place, you have to wonder.
Your "git push there HEAD:master" would roughly do the following:
    (1) read HEAD to learn what commit you are pushing;
    (2) contact the other side and find where there tips are;
    (3) send a packfile that should be enough for the other side to
        have complete history leading to the commit you read in (1);
    (4) tell the other side to update its 'master' to the commit you
        read in (1).

If you drop step (1) and replace "the commit you read in (1)" in steps (3) and (4) with "the commit you see in HEAD at this point by re-reading HEAD", then such a "git push" that races with something else you do in your other terminal may break---you can cause it to see different commits at steps (3) and (4), potentially getting the other side out of sync (but the receiving end does an independent connectivity check so your push will likely to be rejected).

And the fix to such a breakage is to structure the code like the above four steps to make it race-free.

If I understand your example correctly, you are talking about a quite different thing. "git push there HEAD:master" racing with your other terminal that changes the HEAD sees different HEAD depending on the order:

    (a) if the other terminal changes the HEAD first, step (1) will
        see that updated HEAD; or
    (b) if the step (1) reads HEAD before you change it in the other
        terminal, it will see the original HEAD.

But that is very much to be expected, isn't it? It sounds similar to

    I have "largedir" I want to get rid of, but there is a directory
    I want to save, "largedir/precious", in it, so I do
        cp -R largedir/precious precious
    and then run 'rm -rf largedir' in another terminal in parallel.
Is there anything to fix?
Previous: Ramkumar RamachandraNext: Ramkumar Ramachandra
Message 12 of 17 in “Fixing volatile HEAD in push.default = current”
  1. 0/3 Fixing volatile HEAD in push.default = currentRamkumar Ramachandra, May 21, 2013
  2. 1/3 push: factor out the detached HEAD error messageRamkumar Ramachandra, May 21, 2013
  3. 2/3 push: fail early with detached HEAD and currentRamkumar Ramachandra, May 21, 2013
  4. 3/3 push: don't push the volatile HEAD with currentRamkumar Ramachandra, May 21, 2013
  5. Junio C HamanoMay 21, 2013
  6. Ramkumar RamachandraMay 21, 2013
  7. Junio C HamanoMay 21, 2013
  8. Junio C HamanoMay 21, 2013
  9. Ramkumar RamachandraMay 21, 2013
  10. Junio C HamanoMay 22, 2013
  11. Ramkumar RamachandraMay 22, 2013
  12. Junio C HamanoMay 22, 2013
  13. Ramkumar RamachandraMay 23, 2013
  14. Andreas KreyMay 23, 2013
  15. Junio C HamanoMay 23, 2013
  16. Andreas KreyMay 23, 2013
  17. Junio C HamanoMay 23, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.