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

Re: Fake linear history in a deterministic manner.

From
Junio C Hamano <junkio@cox.net>
Date
Feb 13, 2006, 05:24 UTC
Message-ID
<7vk6bz3k7e.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<46a038f90602121746v5adb448ej73cc2be6dd3745ce@mail.gmail.com>
Martin Langhoff <martin.langhoff@gmail.com> writes:
Show 8 quoted lines
> I thought briefly about delaying the decision until I see the merge,
> and pick the leftmost, or rightmost, if there is some bias in
> git-merge or cg-merge on putting whatever origin has on a particular
> side. It'd mean running backwards through history and that the very
> last merge can flip the decision entirely. Hmmm... any strategy I can
> come up with means that each new merge throws the dice again entirely.
>
> Ideas?

When somebody pushes a ref to your existing commit ancestry graph, you can easily identify which commits are the new ones you see for the first time.

                A
           o---o
          /
     o---o---o---o---o B

Suppose you started from two branch repo A and B. Your sqlite database knows about all of these commits, and say you earlier have decided to treat A as a side branch, B as trunk.

Then somebody pushed a new B, making the ancestry graph like this:

                A
           o---o-------*---*---* B-new
          /           /     
     o---o---o---o---o B-old

When the update-hook runs, as you read in receive-pack.c, your refs have not been updated yet, so you can identify the commits marked with * with:

	git rev-list B-new $(git rev-parse --not --all)

I think you have to do this enumeration of new commits anyway, if you are keeping tabs on all commits in your database. And you check the chain * commits form, and work backwards. The topologically oldest ones determine what branch others belong to.

With CVS you cannot express a merge very well, so you now face a choice. Which parent to drop from the leftmost * commit in the above picture?

It has commits known to your sqlite database as its parents, and one of them, B (old), is on trunk; the other one is a side branch, so in this case the decision is clear. You leave the link from B-old and cut link from A. But this heuristics would not work very well if both are branches. Which one to prefer?

One approach would be to see the world with eyes of the person who did such a merge. Both git and cogito place the current branch as the first parent, so you can tell which one the person who did the merge had before that merge that way. Also in practice, in a normal branch, you would build sequence of small commits and occasionally merge from elsewhere, so the side with more difference tends to be a side branch from the point of view of the person who performs the merge.

However, this would not help much. There is no inherent distinction between trunk and branch in the distributed development. Although I treat my "next" branch as a side branch and "master" branch as the trunk, "next" sometimes needs to merge from "master", and by looking at only that merge, you cannot tell which one is the trunk. My merging "master" into "next" does not make my "next" the trunk.

Since the ordering is completely arbitrary, I think you can give preference to the ones you have found out about earlier. That is, suppose you already had this, and for some reason track B is the trunk and track A is a branch (say commits on B have 1.XX, the ones on A have 1.XX.1.YY where XX depends on which commits on B the branch was forked from). At this point, if you see a push to C:

                A
           o---o
          /
     o---o---o---o---o B
              \
               *---* C
you give 1.XX.2.YY to commits on C.

This may or may not match reality, and C may collect a lot of commits while B might stay dormant -- and you may regret that you picked B as the trunk. But the thing is, there is no inherent trunk or branch in the distributed world, so the cvs clients of your server needs to live with it. To you, you saw B first and people who track the project through your server also saw B first. Then you can have total ordering to side branches. When you see a merge, you arbitrarily but consistently pick which side to pick. The one that has smaller number at the third place (which I am using as "the branch number").

Just thinking out aloud again...
Previous: Martin LanghoffNext: Martin Langhoff
Message 2 of 7 in “Fake linear history in a deterministic manner.”
  1. Martin LanghoffFeb 13, 2006
  2. Junio C HamanoFeb 13, 2006
  3. Martin LanghoffFeb 13, 2006
  4. Linus TorvaldsFeb 13, 2006
  5. Eric WongFeb 16, 2006
  6. Martin LanghoffFeb 16, 2006
  7. Junio C HamanoFeb 16, 2006

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.