Git.vala
[gitlive] / Git.vala
index da2c24a..74cfb6c 100644 (file)
--- a/Git.vala
+++ b/Git.vala
@@ -1,5 +1,5 @@
 
-// valac -o /tmp/ggit Git.vala --pkg libgit2-glib-1.0 --pkg libsoup-2.4 -g
+// valac -o /tmp/ggit Git.vala --pkg libgit2-glib-1.0 --pkg libsoup-2.4 -pkg gee-0.8 -g
 
 
 
@@ -20,6 +20,9 @@ void main()
        Ggit.init();
        
        var a = new GitLive.Repo("/home/alan/gitlive/gitlive");
+       a.loadBranches();
+       a.fetchAll();
+       //
        /*
        var a = new GitLive.Repo("/home/alan/git/test1-clone");
        //a.fetchAll();
@@ -65,17 +68,46 @@ namespace  GitLive {
                
                }
                
-               public Gee.ArrayList<Git.Branch> branches()
+           Gee.ArrayList<Ggit.Branch>          branches = null;
+               public void loadBranches()
                {
+                       this.branches =  new Gee.ArrayList<Ggit.Branch>();
                        var r = this.repo.enumerate_branches(Ggit.BranchType.LOCAL);
+                       
+                       
+                       
+                       
                        while (r.next()) {
-                               var gref = r.get();
-                               GLib.debug("got branch: name = %s ", gref.get_name());
+                               var br = r.get() as Ggit.Branch;
+                               var head = this.repo.revparse("refs/heads/" + br.get_name() ).get_id();
+                               var rhead = this.repo.revparse(br.get_upstream().get_name() ).get_id();
+                               GLib.debug("got branch: name = %s upstream = %s oid = %s ", 
+                                               br.get_name(), br.get_upstream().get_name(), 
+                                               head.to_string());
+                               this.branches.add(br);
+                               
+                       }
+                       
+                       
+               
+               }
+               Ggit.Branch? getBranch(string remote_name, string remote_branch_name)
+               {
+                       GLib.debug("lookup %s:%s", remote_name, remote_branch_name);
+                       foreach(var br in this.branches) {
+                               GLib.debug("test:%s", br.get_upstream().get_shorthand());
+                               if ("ref/heads/" + remote_name +  br.get_upstream().get_shorthand() == remote_branch_name) {
+                                       return br;
+                               }
                                
                        }
+                       GLib.debug("missing %s", remote_branch_name);                   
+                       return null;
                
                }
                
+               
+               
                public void fetchAll()
                {
                        // remotes probably will not work with http auth..
@@ -93,6 +125,21 @@ namespace  GitLive {
                                        GLib.debug("Got Error Message: %s", e.message);
                                        return;
                                }
+                               
+                               var heads = r.list();
+                               foreach(var rh in heads) {
+                                       var br = this.getBranch(n, rh.get_name());
+                               
+                                       GLib.debug("got heads: name=%s   rev=%s  localrev=%s",
+                                               rh.get_name(), 
+                                               rh.get_oid().to_string(),
+                                               br == null ? "?": this.repo.revparse(br.get_name() ).get_id().to_string()
+                                       );
+                               
+                               }
+                               
+                               
+                               
                                GLib.debug("getting specs '%s'", n);