2 // valac -o /tmp/ggit Git.vala --pkg libgit2-glib-1.0 --pkg libsoup
8 GLib.Log.set_handler(null,
9 GLib.LogLevelFlags.LEVEL_DEBUG | GLib.LogLevelFlags.LEVEL_WARNING | GLib.LogLevelFlags.LEVEL_INFO,
21 var a = new Git.Repo("/home/alan/gitlive/web.Texon");
28 public class Repo : Object {
33 public Repo(string path)
35 this.repo = Ggit.Repository.open(GLib.File.new_for_path(path));
36 this.callbacks = new Callbacks(this);
39 public void fetchAll()
41 // remotes probably will not work with http auth..
42 var ar = this.repo.list_remotes();
43 foreach(var n in ar) {
44 GLib.debug("got remote '%s'", n);
45 var r = this.repo.lookup_remote(n);
46 GLib.debug("connecting '%s'", r.get_url());
49 string[] h = { "a = 1" };
50 r.connect(Ggit.Direction.FETCH, this.callbacks, null, null);
53 GLib.debug("Got Error Message: %s", e.message);
56 GLib.debug("getting specs '%s'", n);
59 var far = r.get_fetch_specs();
61 foreach(var rs in far) {
62 GLib.debug("got remote spec: %s", rs);
65 var options = new Ggit.FetchOptions();
66 options.set_remote_callbacks(this.callbacks);
67 r.download(far, options);
77 // remotes probably will not work with http auth..
78 var ar = this.repo.list_remotes();
79 foreach(var n in ar) {
80 GLib.debug("got remote '%s'", n);
81 var r = this.repo.lookup_remote(n);
82 GLib.debug("connecting '%s'", r.get_url());
85 string[] h = { "a = 1" };
86 r.connect(Ggit.Direction.PUSH, this.callbacks, null, null);
89 GLib.debug("Got Error Message: %s", e.message);
92 GLib.debug("getting specs '%s'", n);
95 var far = r.get_push_specs();
97 foreach(var rs in far) {
98 GLib.debug("got remote spec: %s", rs);
102 r.update_tips(this.callbacks, true,);
116 private class Callbacks : Ggit.RemoteCallbacks
118 //private Remote d_remote;
119 private Ggit.RemoteCallbacks? d_proxy = null;
121 public delegate void TransferProgress(Ggit.TransferProgress stats);
122 //private TransferProgress? d_transfer_progress;
124 public Callbacks( Repo repo) //, Ggit.RemoteCallbacks? proxy) //,Remote remote, owned TransferProgress? transfer_progress)
128 //d_transfer_progress = (owned)transfer_progress;
131 protected override void progress(string message)
133 GLib.debug("progress");
136 d_proxy.progress(message);
140 protected override void transfer_progress(Ggit.TransferProgress stats)
142 GLib.debug("transfer_progress");
144 if (d_transfer_progress != null)
146 d_transfer_progress(stats);
151 d_proxy.transfer_progress(stats);
156 protected override void update_tips(string refname, Ggit.OId a, Ggit.OId b)
158 GLib.debug("update_tips");
159 //d_remote.tip_updated(refname, a, b);
163 d_proxy.update_tips(refname, a, b);
167 protected override void completion(Ggit.RemoteCompletionType type)
169 GLib.debug("completion");
172 d_proxy.completion(type);
176 protected override Ggit.Cred? credentials(string url, string? username_from_url, Ggit.Credtype allowed_types) throws Error
179 GLib.debug("get credentials %s UN=%s", url, username_from_url);
180 var uri = new Soup.URI(url);
183 var ret = this.netrc(uri.get_host());
188 //return new Ggit.CredPlaintext(username_from_url, "test");
191 /*var provider = d_remote.credentials_provider;
193 if (provider != null)
195 ret = provider.credentials(url, username_from_url, allowed_types);
198 if (ret == null && d_proxy != null)
200 ret = d_proxy.credentials(url, username_from_url, allowed_types);
206 public Ggit.Cred netrc(string domain)
209 GLib.FileUtils.get_contents(GLib.Environment.get_home_dir() + "/.netrc", out str);
210 var lines = str.split("\n");
211 for(var i=0; i< lines.length; i++) {
212 // assumes one line per entry.. if not we are buggered...
213 GLib.debug("got %s" , lines[i]);
215 var bits = Regex.split_simple ("[ \t]+", lines[i].strip());
216 if (bits.length < 6 || bits[0] != "machine" || bits[1] != domain) {
219 GLib.debug("found password?");
220 // we are gussing....
221 return new Ggit.CredPlaintext(bits[3], bits[5]);