2 // valac -o /tmp/ggit Git.vala --pkg libgit2-glib-1.0 --pkg libsoup-2.4
8 GLib.Log.set_handler(null,
9 GLib.LogLevelFlags.LEVEL_DEBUG | GLib.LogLevelFlags.LEVEL_WARNING | GLib.LogLevelFlags.LEVEL_INFO,
21 var a = new GitLive.Repo("/home/alan/gitlive/web.Texon");
29 public class Repo : Object {
34 public Repo(string path)
36 this.repo = Ggit.Repository.open(GLib.File.new_for_path(path));
37 this.callbacks = new Callbacks(this);
40 public void fetchAll()
42 // remotes probably will not work with http auth..
43 var ar = this.repo.list_remotes();
44 foreach(var n in ar) {
45 GLib.debug("got remote '%s'", n);
46 var r = this.repo.lookup_remote(n);
47 GLib.debug("connecting '%s'", r.get_url());
50 string[] h = { "a = 1" };
51 r.connect(Ggit.Direction.FETCH, this.callbacks, null, null);
54 GLib.debug("Got Error Message: %s", e.message);
57 GLib.debug("getting specs '%s'", n);
60 var far = r.get_fetch_specs();
62 foreach(var rs in far) {
63 GLib.debug("got remote spec: %s", rs);
66 var options = new Ggit.FetchOptions();
67 options.set_remote_callbacks(this.callbacks);
68 //yield Async.thread(() => {
70 r.download(far, options);
80 // remotes probably will not work with http auth..
81 var ar = this.repo.list_remotes();
82 foreach(var n in ar) {
83 GLib.debug("got remote '%s'", n);
84 var r = this.repo.lookup_remote(n);
85 GLib.debug("connecting '%s'", r.get_url());
88 string[] h = { "a = 1" };
89 r.connect(Ggit.Direction.PUSH, this.callbacks, null, null);
92 GLib.debug("Got Error Message: %s", e.message);
95 GLib.debug("getting specs '%s'", n);
98 var far = r.get_push_specs();
100 foreach(var rs in far) {
101 GLib.debug("got remote spec: %s", rs);
104 var popts = new Ggit.PushOptions();
106 r.upload(far, popts);
107 GLib.debug("Push done?");
121 private class Callbacks : Ggit.RemoteCallbacks
123 //private Remote d_remote;
124 private Ggit.RemoteCallbacks? d_proxy = null;
126 public delegate void TransferProgress(Ggit.TransferProgress stats);
127 //private TransferProgress? d_transfer_progress;
129 public Callbacks( Repo repo) //, Ggit.RemoteCallbacks? proxy) //,Remote remote, owned TransferProgress? transfer_progress)
133 //d_transfer_progress = (owned)transfer_progress;
136 protected override void progress(string message)
138 GLib.debug("progress");
141 d_proxy.progress(message);
145 protected override void transfer_progress(Ggit.TransferProgress stats)
147 GLib.debug("transfer_progress");
149 if (d_transfer_progress != null)
151 d_transfer_progress(stats);
156 d_proxy.transfer_progress(stats);
161 protected override void update_tips(string refname, Ggit.OId a, Ggit.OId b)
163 GLib.debug("update_tips");
164 //d_remote.tip_updated(refname, a, b);
168 d_proxy.update_tips(refname, a, b);
172 protected override void completion(Ggit.RemoteCompletionType type)
174 GLib.debug("completion");
177 d_proxy.completion(type);
181 protected override Ggit.Cred? credentials(string url, string? username_from_url, Ggit.Credtype allowed_types) throws Error
184 GLib.debug("get credentials %s UN=%s", url, username_from_url);
185 var uri = new Soup.URI(url);
188 var ret = this.netrc(uri.get_host());
193 //return new Ggit.CredPlaintext(username_from_url, "test");
196 /*var provider = d_remote.credentials_provider;
198 if (provider != null)
200 ret = provider.credentials(url, username_from_url, allowed_types);
203 if (ret == null && d_proxy != null)
205 ret = d_proxy.credentials(url, username_from_url, allowed_types);
211 public Ggit.Cred netrc(string domain)
214 GLib.FileUtils.get_contents(GLib.Environment.get_home_dir() + "/.netrc", out str);
215 var lines = str.split("\n");
216 for(var i=0; i< lines.length; i++) {
217 // assumes one line per entry.. if not we are buggered...
218 GLib.debug("got %s" , lines[i]);
220 var bits = Regex.split_simple ("[ \t]+", lines[i].strip());
221 if (bits.length < 6 || bits[0] != "machine" || bits[1] != domain) {
224 GLib.debug("found password?");
225 // we are gussing....
226 return new Ggit.CredPlaintext(bits[3], bits[5]);