fix empty log
[gitlive] / GitCallbacks.vala
1 public class GitCallbacks : Ggit.RemoteCallbacks
2 {
3         //private Remote d_remote;
4         private Ggit.RemoteCallbacks? d_proxy = null;
5
6         public delegate void TransferProgress(Ggit.TransferProgress stats);
7         //private TransferProgress? d_transfer_progress;
8
9         public GitCallbacks( GitRepo repo)  //, Ggit.RemoteCallbacks? proxy) //,Remote remote, owned TransferProgress? transfer_progress)
10         {
11                 //d_remote = remote;
12                 //d_proxy = proxy;
13                 //d_transfer_progress = (owned)transfer_progress;
14         }
15
16         protected override void progress(string message)
17         {
18                 GLib.debug("progress: %s", message);
19                 if (d_proxy != null)
20                 {
21                         d_proxy.progress(message);
22                 }
23         }
24
25         protected override void transfer_progress(Ggit.TransferProgress stats)
26         {
27                 GLib.debug("transfer_progress");
28                 /*
29                 if (d_transfer_progress != null)
30                 {
31                         d_transfer_progress(stats);
32                 }
33
34                 if (d_proxy != null)
35                 {
36                         d_proxy.transfer_progress(stats);
37                 }
38                 */
39         }
40
41         protected override void update_tips(string refname, Ggit.OId a, Ggit.OId b)
42         {
43                 GLib.debug("update_tips");
44                 //d_remote.tip_updated(refname, a, b);
45
46                 if (d_proxy != null)
47                 {
48                         d_proxy.update_tips(refname, a, b);
49                 }
50         }
51
52         protected override void completion(Ggit.RemoteCompletionType type)
53         {
54                 GLib.debug("completion");
55                 if (d_proxy != null)
56                 {
57                         d_proxy.completion(type);
58                 }
59         }
60
61         protected override Ggit.Cred? credentials(string url, string? username_from_url, Ggit.Credtype allowed_types) throws Error
62         {
63
64                 GLib.debug("get credentials %s  UN=%s", url, username_from_url);
65                 var uri = new Soup.URI(url);
66
67                 if (uri != null) {
68                         var ret = this.netrc(uri.get_host());
69                         if (ret != null) {
70                                 return ret;
71                         }
72                         
73                         //return new Ggit.CredPlaintext(username_from_url, "test");
74                 }
75                 return null;
76                 /*var provider = d_remote.credentials_provider;
77
78                 if (provider != null)
79                 {
80                         ret = provider.credentials(url, username_from_url, allowed_types);
81                 }
82
83                 if (ret == null && d_proxy != null)
84                 {
85                         ret = d_proxy.credentials(url, username_from_url, allowed_types);
86                 }
87                 
88                 return ret;
89                 */
90         }
91         public  Ggit.Cred netrc(string domain) 
92         {
93                 string str;
94                 GLib.FileUtils.get_contents(GLib.Environment.get_home_dir() + "/.netrc", out str);
95                 var lines = str.split("\n");
96                 for(var i=0; i< lines.length; i++) {
97                         // assumes one line per entry.. if not we are buggered...
98                         //GLib.debug("got %s" , lines[i]);
99                 
100                         var bits =  Regex.split_simple ("[ \t]+", lines[i].strip());
101                         if (bits.length < 6 || bits[0] != "machine" || bits[1] != domain) {
102                                 continue;
103                         }
104                         GLib.debug("found password?");
105                         // we are gussing.... 
106                         return new Ggit.CredPlaintext(bits[3], bits[5]);
107
108                 }
109                 return null;
110
111
112         
113         
114         }
115         
116 }