-
Notifications
You must be signed in to change notification settings - Fork 899
Remote LS able to handle Symbolic References #1132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2147,7 +2147,7 @@ public static IList<string> git_remote_list(RepositorySafeHandle repo) | |
} | ||
} | ||
|
||
public static IEnumerable<DirectReference> git_remote_ls(Repository repository, RemoteSafeHandle remote) | ||
public static IEnumerable<Reference> git_remote_ls(Repository repository, RemoteSafeHandle remote) | ||
{ | ||
IntPtr heads; | ||
UIntPtr count; | ||
|
@@ -2162,26 +2162,52 @@ public static IEnumerable<DirectReference> git_remote_ls(Repository repository, | |
throw new OverflowException(); | ||
} | ||
|
||
var refs = new List<DirectReference>(); | ||
var directRefs = new Dictionary<string, Reference>(); | ||
var symRefs = new Dictionary<string, string>(); | ||
|
||
IntPtr currentHead = heads; | ||
|
||
for (int i = 0; i < intCount; i++) | ||
{ | ||
var remoteHead = Marshal.ReadIntPtr(currentHead).MarshalAs<GitRemoteHead>(); | ||
|
||
string name = LaxUtf8Marshaler.FromNative(remoteHead.NamePtr); | ||
string symRefTarget = LaxUtf8Marshaler.FromNative(remoteHead.SymRefTargetPtr); | ||
|
||
// The name pointer should never be null - if it is, | ||
// this indicates a bug somewhere (libgit2, server, etc). | ||
if (remoteHead.NamePtr == IntPtr.Zero) | ||
if (string.IsNullOrEmpty(name)) | ||
{ | ||
throw new InvalidOperationException("Not expecting null value for reference name."); | ||
} | ||
|
||
string name = LaxUtf8Marshaler.FromNative(remoteHead.NamePtr); | ||
refs.Add(new DirectReference(name, repository, remoteHead.Oid)); | ||
if (!string.IsNullOrEmpty(symRefTarget)) | ||
{ | ||
symRefs.Add(name, symRefTarget); | ||
} | ||
else | ||
{ | ||
directRefs.Add(name, new DirectReference(name, repository, remoteHead.Oid)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One additional thought on representing tags, as originally mentioned in #1085
should these dereferenced tags be represented in the final output, possibly if (!string.IsNullOrEmpty(symRefTarget))
{
symRefs.Add(name, symRefTarget);
}
else if (Reference.IsValidName(name))
{ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @nulltoken Thoughts on this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd be 👍 to not extend the scope of this PR too much. How about logging a new issue to keep track of this and discuss about pros/cons there? |
||
} | ||
|
||
currentHead = IntPtr.Add(currentHead, IntPtr.Size); | ||
} | ||
|
||
for (int i = 0; i < symRefs.Count; i++) | ||
{ | ||
var symRef = symRefs.ElementAt(i); | ||
|
||
if (!directRefs.ContainsKey(symRef.Value)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Only direct references and There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's true of the base protocol, but there is an extension named This extension is mostly intended to let the client know which is the default branch in cases when there are multiple branches which point to the same commit as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As to the chain depth, there's no particular limit other than what the implementation is willing to accept before it decides to trigger its loop short-circuit code (which IIRC is 7 deep). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Upon further investigation, it looks like git won't actually add the symref list for anything other than HEAD, and it will resolve to the final reference, so you won't end up with chains. |
||
{ | ||
throw new InvalidOperationException("Symbolic reference target not found in direct reference results."); | ||
} | ||
|
||
directRefs.Add(symRef.Key, new SymbolicReference(repository, symRef.Key, symRef.Value, directRefs[symRef.Value])); | ||
} | ||
|
||
var refs = directRefs.Values.ToList(); | ||
refs.Sort((r1, r2) => String.CompareOrdinal(r1.CanonicalName, r2.CanonicalName)); | ||
|
||
return refs; | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Amended the PR to verify HEAD
References
asSymbolicReferences
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that HEAD is not always a symbolic reference.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out it goes then!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@psawey I think the
Assert
should stay.Indeed, in this* case,
HEAD
should actually be aSymboilcReference
.I think @carlosmn was hinting at the fact that would the
HEAD
be detached server-side, we should make sure the code still works.Do you think you could add some test coverage to assert this?
IIRC there's a test in
PushFixture
that leverages two repository through the local transport. Maybe could we do the same (setup a fake server, detach the HEAD, then invokeRetrieveRemoteReferences()
against it?)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nulltoken Spoke too soon, will take a look at adding test coverge. Have been trying to brainstorm some additional tests, hence the
Assert