What's the definition of a valid Git symbolic reference?

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

What's the definition of a valid Git symbolic reference?

Emeric Fermas
Hello,

I'm one of the contributors of libgit2 (http://libgit2.github.com/).
I'm currently working on the handling of refs and I'd like to get a
better understanding of git symbolic references.

In order to avoid polluting this list with an easy to answer noob
question, I firsty asked this question on stackoverflow
(http://stackoverflow.com/q/4986000). However, I do not have the
feeling that I'm getting some definite "carved-in-stone" answers.
This explains why I'm posting it here today.

The following shell code correctly creates a chain of symbolic references

  git symbolic-ref "first" "refs/heads/master"
  git symbolic-ref "second" "first"
  git symbolic-ref "nested/third" "second"
  git symbolic-ref "refs/heads/fourth" "nested/third"

And the following shell code correctly resolves the latest created
symbolic reference to the tip of master.

  git show-ref "refs/heads/fourth"


None of these use cases are described in the official documentation
(git-symbolic-ref doc, git-show-ref doc).

However, the following doesn't work

  git check-ref-format --print "first"


So, my questions are:

 - Is it ok to store a symbolic reference within the refs/heads directory ?
 - Is it ok to chain symbolic references ?
 - As check-ref-format fails when being passed "first", does this mean
that it's not recommended to create a symbolic reference at the same
level than "HEAD"? Or maybe this command is not intended to deal with
symbolic links ?

My intent is to get a clear understanding of what is being supported
and that I'm not working around anything or benefiting from a bug.


Thanks in advance for any help you could provide me with.

Cheers,
Em.


Em.
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|

Re: What's the definition of a valid Git symbolic reference?

Kevin Ballard
On Feb 14, 2011, at 12:58 PM, Emeric Fermas wrote:

> - As check-ref-format fails when being passed "first", does this mean
> that it's not recommended to create a symbolic reference at the same
> level than "HEAD"? Or maybe this command is not intended to deal with
> symbolic links ?

I don't know about the rest of your question, but check-ref-format
explicitly states in the manpage that the refname must have at least
one /, to enforce the presence of a category (such as heads/) in the
refname.

-Kevin Ballard
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|

Re: What's the definition of a valid Git symbolic reference?

Emeric Fermas
Thanks a lot for this answer.

I've also read the man page of check-ref-format. However, there may be
some not up-to-date documentation or some "non guarded against"
command usage in git.

This explains the second part of my question ("Or maybe this command
(ie. check-ref-format) is not intended to deal with symbolic links
?").

Another possibility would be that only git internal symbolic
references are allowed to live under the ".git" dir (HEAD, FETCH_HEAD,
...) and that user defined symrefs should live under refs/. In this
case, maybe "git symbolic-ref" should also prevent the user from
creating a reference which doesn't contains a forward slash.

Once again, by reading at the code I can understand how those commands
currently work. What I'm trying to achieve is to understand what
should be their recommended usage.

Of course, I'll be glad to contribute any code/doc patch once the
"voice of the git community" has spoken :-)


Em.



On Tue, Feb 15, 2011 at 4:19 AM, Kevin Ballard <[hidden email]> wrote:

> On Feb 14, 2011, at 12:58 PM, Emeric Fermas wrote:
>
>> - As check-ref-format fails when being passed "first", does this mean
>> that it's not recommended to create a symbolic reference at the same
>> level than "HEAD"? Or maybe this command is not intended to deal with
>> symbolic links ?
>
> I don't know about the rest of your question, but check-ref-format
> explicitly states in the manpage that the refname must have at least
> one /, to enforce the presence of a category (such as heads/) in the
> refname.
>
> -Kevin Ballard
>
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|

Re: What's the definition of a valid Git symbolic reference?

Tomas Carnecky
  On 2/15/11 4:49 AM, Emeric Fermas wrote:
> Another possibility would be that only git internal symbolic
> references are allowed to live under the ".git" dir (HEAD, FETCH_HEAD,
> ...) and that user defined symrefs should live under refs/. In this

All refs should live under refs/ (except the special ones like HEAD
etc). It's usually a mistake if someone manages to create one outside of
refs/. The plumbing commands allow you to do that, but users usually
shouldn't use those.

tom

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|

Re: What's the definition of a valid Git symbolic reference?

Junio C Hamano
In reply to this post by Emeric Fermas
Emeric Fermas <[hidden email]> writes:

> Once again, by reading at the code I can understand how those commands
> currently work. What I'm trying to achieve is to understand what
> should be their recommended usage.

There are only two valid kinds of symrefs right now:

 - .git/HEAD, pointing at somewhere under refs/heads/ hierarchy;

 - .git/refs/remotes/<some remote name>/HEAD, pointing at somewhere under
   refs/remotes/<the same remote name>/ hierarchy.

The code may be prepared to resolve recursive symrefs, symrefs other than
the above two kinds, symrefs that point at elsewhere, but all of them are
outside of the design scope of what the mechanism was intended to support.
What the code do to them (without crashing) is not the design, but simply
an undefined behaviour.

This won't change very much if we decide to reorganize the remote tracking
hierarchies in 1.8.0.  The former won't change at all, and the latter will
start pointing at refs/remotes/<the same remote name>/heads hierarchy
instead.

I vaguely recall tg abused the symref mechanism to point .git/HEAD at
funny locations; it may still be doing so, and if that is the case we
should extend the above list to cover that usage.
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|

Re: What's the definition of a valid Git symbolic reference?

Emeric Fermas
Thanks a lot for this very clear explanation. All my questions have
found an answer.

Cheers,
Em.



On Tue, Feb 15, 2011 at 7:22 AM, Junio C Hamano <[hidden email]> wrote:

> Emeric Fermas <[hidden email]> writes:
>
>> Once again, by reading at the code I can understand how those commands
>> currently work. What I'm trying to achieve is to understand what
>> should be their recommended usage.
>
> There are only two valid kinds of symrefs right now:
>
>  - .git/HEAD, pointing at somewhere under refs/heads/ hierarchy;
>
>  - .git/refs/remotes/<some remote name>/HEAD, pointing at somewhere under
>   refs/remotes/<the same remote name>/ hierarchy.
>
> The code may be prepared to resolve recursive symrefs, symrefs other than
> the above two kinds, symrefs that point at elsewhere, but all of them are
> outside of the design scope of what the mechanism was intended to support.
> What the code do to them (without crashing) is not the design, but simply
> an undefined behaviour.
>
> This won't change very much if we decide to reorganize the remote tracking
> hierarchies in 1.8.0.  The former won't change at all, and the latter will
> start pointing at refs/remotes/<the same remote name>/heads hierarchy
> instead.
>
> I vaguely recall tg abused the symref mechanism to point .git/HEAD at
> funny locations; it may still be doing so, and if that is the case we
> should extend the above list to cover that usage.
>
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|

Re: What's the definition of a valid Git symbolic reference?

Jeff King
In reply to this post by Junio C Hamano
On Mon, Feb 14, 2011 at 10:22:55PM -0800, Junio C Hamano wrote:

> Emeric Fermas <[hidden email]> writes:
>
> > Once again, by reading at the code I can understand how those commands
> > currently work. What I'm trying to achieve is to understand what
> > should be their recommended usage.
>
> There are only two valid kinds of symrefs right now:
>
>  - .git/HEAD, pointing at somewhere under refs/heads/ hierarchy;
>
>  - .git/refs/remotes/<some remote name>/HEAD, pointing at somewhere under
>    refs/remotes/<the same remote name>/ hierarchy.

Nit: the notes merge code uses NOTES_MERGE_REF as a symref to a notes
ref. See the create_symref call in builtin/notes.c.

I don't think that changes your point much, though.

> The code may be prepared to resolve recursive symrefs, symrefs other than
> the above two kinds, symrefs that point at elsewhere, but all of them are
> outside of the design scope of what the mechanism was intended to support.
> What the code do to them (without crashing) is not the design, but simply
> an undefined behaviour.

I was always under the impression that you could generally use symbolic
refs to point wherever you wanted inside the refs hierarchy as a
replacement for symlinks (I don't know how the latter would deal with
ref packing, though). But I think that was just my assumption rather
than anything that was ever communicated officially.

-Peff
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|

Re: What's the definition of a valid Git symbolic reference?

Kevin P. Fleming-2
In reply to this post by Tomas Carnecky
On 02/14/2011 11:02 PM, Tomas Carnecky wrote:
> On 2/15/11 4:49 AM, Emeric Fermas wrote:
>> Another possibility would be that only git internal symbolic
>> references are allowed to live under the ".git" dir (HEAD, FETCH_HEAD,
>> ...) and that user defined symrefs should live under refs/. In this
>
> All refs should live under refs/ (except the special ones like HEAD
> etc). It's usually a mistake if someone manages to create one outside of
> refs/. The plumbing commands allow you to do that, but users usually
> shouldn't use those.

Being able to manually point HEAD at a ref is actually useful; when I've
created repos that start out with a 'vendor branch', I want to do the
initial import into a branch called 'upstream', not 'master'. Using 'git
symbolic-ref HEAD refs/heads/upstream' in a brand-new repo allows that
to happen, and works quite well.

Please don't take it away :-)

--
Kevin P. Fleming
Digium, Inc. | Director of Software Technologies
445 Jan Davis Drive NW - Huntsville, AL 35806 - USA
skype: kpfleming | jabber: [hidden email]
Check us out at www.digium.com & www.asterisk.org
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html