Properly resolve tag objects that point to commits

This commit is contained in:
Jesse van den Kieboom 2012-07-06 19:36:47 +02:00
parent 74931433f6
commit 6a2410aadd
2 changed files with 71 additions and 22 deletions

View file

@ -32,6 +32,28 @@ public class Repository : Ggit.Repository
((Initable)this).init(null);
}
private void ensure_refs_add(Ggit.OId? id, Gitg.Ref r)
{
if (id == null)
{
return;
}
unowned SList<Gitg.Ref> refs;
if (d_refs.lookup_extended(id, null, out refs))
{
refs.append(r);
}
else
{
SList<Gitg.Ref> nrefs = new SList<Gitg.Ref>();
nrefs.append(r);
d_refs.insert(id, (owned)nrefs);
}
}
private void ensure_refs()
{
if (d_refs != null)
@ -53,27 +75,34 @@ public class Repository : Ggit.Repository
}
catch { return 0; }
if (r != null)
if (r == null)
{
Ggit.OId? id = r.get_id();
return 0;
}
Ggit.OId? id = r.get_id();
if (id == null)
{
return 0;
}
ensure_refs_add(id, r);
// if it's a 'real' tag, then we are also going to store
// a ref to the underlying commit the tag points to
try
{
var tag = lookup(id, typeof(Ggit.Tag)) as Ggit.Tag;
// get the target id
id = tag.get_target_id();
if (id != null)
{
unowned SList<Gitg.Ref> refs;
if (d_refs.lookup_extended(id, null, out refs))
{
refs.append(r);
}
else
{
SList<Gitg.Ref> nrefs = new SList<Gitg.Ref>();
nrefs.append(r);
d_refs.insert(id, (owned)nrefs);
}
ensure_refs_add(id, r);
}
}
} catch {}
return 0;
});

View file

@ -110,21 +110,41 @@ namespace GitgHistory
d_main = ret["scrolled_window_commit_list"] as Gtk.Widget;
}
private void update_walker(Ggit.Ref? head)
private void update_walker(Gitg.Ref? head)
{
Ggit.Ref? th = head;
Ggit.OId? id = null;
if (th == null && application.repository != null)
if (head != null && head.parsed_name.rtype == Gitg.RefType.TAG)
{
// See to resolve to the commit
try
{
var t = application.repository.lookup(head.get_id(), typeof(Ggit.Tag)) as Ggit.Tag;
id = t.get_target_id();
} catch {}
}
else if (head != null)
{
id = head.get_id();
}
if (id == null && application.repository != null)
{
try
{
th = application.repository.get_head();
Gitg.Ref? th = application.repository.get_head();
if (th != null)
{
id = th.get_id();
}
} catch {}
}
if (th != null)
if (id != null)
{
d_model.set_include(new Ggit.OId[] { th.get_id() });
d_model.set_include(new Ggit.OId[] { id });
}
d_model.reload();