Skip to contentSkip to conversation

hmm, can't we give the "root" a parent?

DISCUSSION Kay Sievers 4 participants 13 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

Can't we teach the git tools that a "root commit" (one without a any parent) is not visible as a "root", if let's say:
.git/parents/<root-commit-id> -> <fake-parent-id>

does connect a "fake" parent to the "root"? This way we could add any older Linux history to the current tree. Combined with "alternates" it could live in a complete different repository too.

Thanks,
Kay

#1 lore raw
Quoted 7 lines · Kay Sievers

Can't we teach the git tools that a "root commit" (one without a any parent) is not visible as a "root", if let's say:
.git/parents/<root-commit-id> -> <fake-parent-id>

does connect a "fake" parent to the "root"? This way we could add any older Linux history to the current tree. Combined with "alternates" it could live in a complete different repository too.

Already done. Search the following for "info/grafts".

http://www.kernel.org/pub/software/scm/git/docs/repository-layout.html

#2 lore raw
In reply to Kay Sievers
Quoted 8 lines · Kay Sievers

Can't we teach the git tools that a "root commit" (one without a any parent) is not visible as a "root", if let's say:
.git/parents/<root-commit-id> -> <fake-parent-id>

does connect a "fake" parent to the "root"? This way we could add any older Linux history to the current tree. Combined with "alternates" it could live in a complete different repository too.

Ehh.. That's exactly what "grafting" is about.

So just do

echo "<root-id> <grafted-parent-id>" >> .git/info/grafts

and it should all work.

Of course, anything that parses the commits by hand won't see it, but all the regular tools hopefully do.

Linus

#3 lore raw
Quoted 12 lines · Linus Torvalds
Quoted 8 lines · Kay Sievers

Can't we teach the git tools that a "root commit" (one without a any parent) is not visible as a "root", if let's say:
.git/parents/<root-commit-id> -> <fake-parent-id>

does connect a "fake" parent to the "root"? This way we could add any older Linux history to the current tree. Combined with "alternates" it could live in a complete different repository too.

Ehh.. That's exactly what "grafting" is about.

Quoted 8 lines

So just do

echo "<root-id> <grafted-parent-id>" >> .git/info/grafts

and it should all work.

Of course, anything that parses the commits by hand won't see it, but all the regular tools hopefully do.

Yup, tried it and works nicely with the history.git tree on kernel.org connected to your tree, replacing the initial commit.

And good to know about that, need to fix the "parent" link in gitweb to respect grafts.

Thanks,
Kay

#4 lore raw
Quoted 3 lines · Kay Sievers

And good to know about that, need to fix the "parent" link in gitweb to respect grafts.

Note that the simplest way to do this is to try to use "git-rev-list" as much as possible. The "--parents" flag makes the output have the parents (automatically _including_ any grafts) on the line that contains the commit ID.

That's especially true of any tools that use git-rev-list anyway for other reasons. Eg "gitk" could parse the parent stuff this way, and didn't need to know about the info/grafts file at all. I suspect the same should be true of gitweb.

(So instead of trying to parse the parent info from the header of the commit, just do "git-rev-list --pretty --parents" and parse that).

Linus

#5 lore raw
Quoted 10 lines · Linus Torvalds
Quoted 3 lines · Kay Sievers

And good to know about that, need to fix the "parent" link in gitweb to respect grafts.

Note that the simplest way to do this is to try to use "git-rev-list" as much as possible. The "--parents" flag makes the output have the parents (automatically _including_ any grafts) on the line that contains the commit ID.

Quoted 4 lines

That's especially true of any tools that use git-rev-list anyway for other reasons. Eg "gitk" could parse the parent stuff this way, and didn't need to know about the info/grafts file at all. I suspect the same should be true of gitweb.

Everthing that walk from one commit to another, uses git-rev-list, sure. But in the commit view, and the commitdiff the "parent" link and the parent that is passed to diff is read from the commit itself.

Quoted 2 lines

(So instead of trying to parse the parent info from the header of the commit, just do "git-rev-list --pretty --parents" and parse that).

I need only one parent:
git-rev-list --parents --max-count=1 <id>

Hmm, it's one more exec, but I don't need to look at the grafts file or whatever will make it into git the next time I will look at it. :)

Thanks,
Kay

#6 lore raw
Quoted 10 lines · Kay Sievers

Everthing that walk from one commit to another, uses git-rev-list, sure. But in the commit view, and the commitdiff the "parent" link and the parent that is passed to diff is read from the commit itself.

Quoted 2 lines

(So instead of trying to parse the parent info from the header of the commit, just do "git-rev-list --pretty --parents" and parse that).

I need only one parent:
git-rev-list --parents --max-count=1 <id>

Who don't you use that to show the comments too?

So instead of doing

git-cat-file commit <id>

(or whatever you do), just do

	git-rev-list --parents --pretty=raw --max-count=1 <id>

That way you don't get any extra fork/exec overhead - you get everything with one program.

Linus

#7 lore raw
Quoted 16 lines · Linus Torvalds
Quoted 10 lines · Kay Sievers

Everthing that walk from one commit to another, uses git-rev-list, sure. But in the commit view, and the commitdiff the "parent" link and the parent that is passed to diff is read from the commit itself.

Quoted 2 lines

(So instead of trying to parse the parent info from the header of the commit, just do "git-rev-list --pretty --parents" and parse that).

I need only one parent:
git-rev-list --parents --max-count=1 <id>

Who don't you use that to show the comments too?

Quoted 7 lines

So instead of doing

git-cat-file commit <id>

(or whatever you do), just do

	git-rev-list --parents --pretty=raw --max-count=1 <id>

That would be nice, if I could convert everthing to this output format.

But why does --pretty=raw mangle the text with spaces?
Well the output of this weird word combination may be "pretty" but definitely not "raw". :)

And I would prefer --pretty=raw with '\0' termination instead of '\n' so I can replace the output from --header with --pretty=raw and can still use the same parsing routine.

Thanks,
Kay

#8 lore raw
Quoted 4 lines · Kay Sievers

But why does --pretty=raw mangle the text with spaces?
Well the output of this weird word combination may be "pretty" but definitely not "raw". :)

git-rev-list always makes sure that the header is clearly separated. We could have a "really-raw" format, of course, but..

Quoted 3 lines

And I would prefer --pretty=raw with '\0' termination instead of '\n' so I can replace the output from --header with --pretty=raw and can still use the same parsing routine.

Dang. That's one of the few programs that don't take -z.

We could add it, but then you'd have to wait for that to percolate out again..

Linus

#9 lore raw
In reply to Kay Sievers
Quoted 4 lines · Kay Sievers

And I would prefer --pretty=raw with '\0' termination instead of '\n' so I can replace the output from --header with --pretty=raw and can still use the same parsing routine.

It struck me that "--header" works fine with "--parents".

So if you're currently already using "git-rev-list --header" and parsing that, just add "--parents" and off you go. That's basically the same as --pretty=raw + zero-termination.

Linus

#10 lore raw
Quoted 8 lines · Linus Torvalds
Quoted 4 lines · Kay Sievers

And I would prefer --pretty=raw with '\0' termination instead of '\n' so I can replace the output from --header with --pretty=raw and can still use the same parsing routine.

Quoted 5 lines

It struck me that "--header" works fine with "--parents".

So if you're currently already using "git-rev-list --header" and parsing that, just add "--parents" and off you go. That's basically the same as --pretty=raw + zero-termination.

Yeah, got the same idea. :) Have it already working. With the history tree plugged in after "Linux 2.6.12-rc2":
http://ehlo.org/~kay/?p=linux/kernel/git/torvalds/linux-2.6.git;a=shortlog;h=2d137c24e9f433e37ffd10b3d5f418157589a8d2

Grafting worked pretty nice by just doing:
echo "8d38eadb7a97f265f7b3a9e8a30df358c3a546c8 e7e173af42dbf37b1d946f9ee00219cb3b2bea6a" > $LOCALROOT/linux/kernel/git/torvalds/linux-2.6.git/info/grafts echo $LOCALROOT/linux/kernel/git/tglx/history.git/objects > $LOCALROOT/linux/kernel/git/torvalds/linux-2.6.git/objects/info/alternates

Thanks,
Kay

#11 lore raw

gitweb search in multi-headed tree

In reply to Kay Sievers

Kay,

My tree on kernel.org (.../aegl/linux-2.6.git) has two branches in refs/heads: release
and test. The HEAD symlink points to the release branch.

It seems that a search traverses from HEAD to root, so can only find things in the
release branch. I tried clicking on the "test" branch link at the foot of the top-level
page before doing the search ... but it still seems to search from HEAD.

Any syntax I'm missing for this search?

-Tony

#12 lore raw

Re: gitweb search in multi-headed tree

Quoted 6 lines · Tony Luck

Kay,

My tree on kernel.org (.../aegl/linux-2.6.git) has two branches in refs/heads: release
and test. The HEAD symlink points to the release branch.

Quoted 7 lines

It seems that a search traverses from HEAD to root, so can only find things in the
release branch. I tried clicking on the "test" branch link at the foot of the top-level
page before doing the search ... but it still seems to search from HEAD.

Any syntax I'm missing for this search?

You can only append "&h=test" to the search url now. I will change that with the next version of gitweb to let the search follow the current $hash.

Thanks,
Kay