[gitg/vala] Added refs_for_id to repository
- From: Jesse van den Kieboom <jessevdk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gitg/vala] Added refs_for_id to repository
- Date: Sun, 22 Apr 2012 13:14:55 +0000 (UTC)
commit 57301f326f24d43fabcfc7e898b5e08f78857689
Author: Jesse van den Kieboom <jesse vandenkieboom epfl ch>
Date: Sun Apr 22 15:12:00 2012 +0200
Added refs_for_id to repository
libgitg/gitg-repository.vala | 58 ++++++++++++++++++++++++++++++++++++++++++
1 files changed, 58 insertions(+), 0 deletions(-)
---
diff --git a/libgitg/gitg-repository.vala b/libgitg/gitg-repository.vala
index 927f878..14acfd0 100644
--- a/libgitg/gitg-repository.vala
+++ b/libgitg/gitg-repository.vala
@@ -3,6 +3,8 @@ namespace Gitg
public class Repository : Ggit.Repository
{
+ private HashTable<Ggit.OId, SList<Gitg.Ref>> d_refs;
+
public Repository(File location, File? workdir) throws Error
{
Object(location: location,
@@ -11,6 +13,62 @@ public class Repository : Ggit.Repository
((Initable)this).init(null);
}
+ private void ensure_refs()
+ {
+ if (d_refs != null)
+ {
+ return;
+ }
+
+ d_refs = new HashTable<Ggit.OId, SList<Gitg.Ref>>(Ggit.OId.hash,
+ Ggit.OId.equal);
+
+ try
+ {
+ references_foreach(Ggit.RefType.LISTALL, (name) => {
+ Gitg.Ref? r;
+
+ try
+ {
+ r = lookup_reference(name);
+ }
+ catch { return 0; }
+
+ if (r != null)
+ {
+ Ggit.OId? id = r.get_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);
+ }
+ }
+ }
+
+ return 0;
+ });
+ }
+ catch {}
+ }
+
+ public unowned SList<Gitg.Ref> refs_for_id(Ggit.OId id)
+ {
+ ensure_refs();
+
+ return d_refs.lookup(id);
+ }
+
// Wrappers for Gitg.Ref
public new Ref lookup_reference(string name) throws Error
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]