Git.vala
[gitlive] / Git.vala
index d64b9d2..61d665b 100644 (file)
--- a/Git.vala
+++ b/Git.vala
@@ -20,7 +20,9 @@ void main()
        Ggit.init();
        
        var a = new GitLive.Repo("/home/alan/gitlive/gitlive");
-       a.branches();
+       a.loadBranches();
+       a.fetchAll();
+       //
        /*
        var a = new GitLive.Repo("/home/alan/git/test1-clone");
        //a.fetchAll();
@@ -66,20 +68,49 @@ namespace  GitLive {
                
                }
                
-               public Gee.ArrayList<Ggit.Branch> branches()
+           Gee.ArrayList<Ggit.Branch>          branches = null;
+               public void loadBranches()
                {
-                       var ret = new Gee.ArrayList<Ggit.Branch>();
+                       this.branches =  new Gee.ArrayList<Ggit.Branch>();
                        var r = this.repo.enumerate_branches(Ggit.BranchType.LOCAL);
                        
+                       
+                       
+                       
                        while (r.next()) {
                                var br = r.get() as Ggit.Branch;
-                               GLib.debug("got branch: name = %s upstream = %s oid = %s", br.get_name(), br.get_upstream().get_name(), br.to_string());
-                               //var head = this.repo.lookup_commit(br);
+                               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);
+                               
                        }
-                       return ret;
+                       
+                       
+               
+               }
+               Ggit.Branch? getBranch(string remote_name, string remote_branch_name)
+               {
+
+                        var target = remote_branch_name.replace("refs/heads/", remote_name+"/") .replace("refs/remotes/", "");
+
+                        
+                       foreach(var br in this.branches) {
+                               GLib.debug("test:%s=%s", br.get_upstream().get_shorthand() , target);
+                               if ( br.get_upstream().get_shorthand() == target) {
+                                       return br;
+                               }
+                               
+                       }
+                       //GLib.debug("missing %s", remote_branch_name);                 
+                       return null;
                
                }
                
+               
+               
                public void fetchAll()
                {
                        // remotes probably will not work with http auth..
@@ -97,6 +128,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);