Git.vala
[gitlive] / Git.vala
1
2 // valac -o /tmp/ggit Git.vala --pkg libgit2-glib-1.0 --pkg libglib
3
4
5 void main()
6 {
7          GLib.Log.set_handler(null, 
8             GLib.LogLevelFlags.LEVEL_DEBUG | GLib.LogLevelFlags.LEVEL_WARNING | GLib.LogLevelFlags.LEVEL_INFO, 
9             (dom, lvl, msg) => {
10                                         
11                                         
12                // should we debug..
13                                         
14                         
15                print("%s\n", msg);
16             }
17          ); 
18
19         Ggit.init();
20         var a = new Git.Repo("/home/alan/gitlive/web.Texon/.git");
21         a.test();
22 }
23  
24
25 namespace  Git {
26
27         public class Repo : Object {
28
29                 Ggit.Repository  repo;
30                 Callbacks callbacks;
31
32                 public Repo(string path)
33                 {
34                         this.repo = Ggit.Repository.open(GLib.File.new_for_path(path));
35                         this.callbacks = new Callbacks(this);
36                 
37                 }
38                 public void test()
39                 {
40                         var ar = this.repo.list_remotes();
41                         foreach(var n in ar) {
42                                 GLib.debug("got remote '%s'", n);
43                                 var r = this.repo.lookup_remote(n);
44                                 GLib.debug("connecting '%s'", r.get_url());
45                                  
46                                 try {
47                                         r.connect(Ggit.Direction.FETCH, null, null, null);
48                                 } catch (Error e) {
49                                         GLib.debug("Got Error Message: %s", e.message);
50                                         return;
51                                 }
52                                 GLib.debug("getting specs '%s'", n);
53                                 
54                                 var far = r.get_fetch_specs();
55                                 foreach(var rs in far) {
56                                         GLib.debug("got remote spec: %s", rs);
57                                 }
58                                 
59                                 
60                                 
61                                 //r.download(
62                         }
63                 
64                 }
65                 
66                 
67                 
68
69         }
70         
71         public class Callbacks : Ggit.RemoteCallbacks {
72         
73                 Repo repo;
74                 public Callbacks(Repo repo)
75                 {
76                         this.repo = repo;
77                         this.transfer_progress.connect(this.onTransferProgress);
78                 }
79         
80                 void onTransferProgress( Ggit.TransferProgress stats)
81                 {
82                         GLib.debug("got progress");
83                 }
84         }
85         
86         
87
88 }