X-Git-Url: http://git.roojs.org/?p=gitlive;a=blobdiff_plain;f=GitCallbacks.vala;fp=GitCallbacks.vala;h=55de1b254f6c6fc73fa5eacde34accabb29d8cc3;hp=0000000000000000000000000000000000000000;hb=c245640608475ef3270eb6a48c9af03b274d9996;hpb=1b65514c93e260c86b738acbb13cf8ec2a39d596 diff --git a/GitCallbacks.vala b/GitCallbacks.vala new file mode 100644 index 00000000..55de1b25 --- /dev/null +++ b/GitCallbacks.vala @@ -0,0 +1,116 @@ +public class GitCallbacks : Ggit.RemoteCallbacks +{ + //private Remote d_remote; + private Ggit.RemoteCallbacks? d_proxy = null; + + public delegate void TransferProgress(Ggit.TransferProgress stats); + //private TransferProgress? d_transfer_progress; + + public GitCallbacks( GitRepo repo) //, Ggit.RemoteCallbacks? proxy) //,Remote remote, owned TransferProgress? transfer_progress) + { + //d_remote = remote; + //d_proxy = proxy; + //d_transfer_progress = (owned)transfer_progress; + } + + protected override void progress(string message) + { + GLib.debug("progress: %s", message); + if (d_proxy != null) + { + d_proxy.progress(message); + } + } + + protected override void transfer_progress(Ggit.TransferProgress stats) + { + GLib.debug("transfer_progress"); + /* + if (d_transfer_progress != null) + { + d_transfer_progress(stats); + } + + if (d_proxy != null) + { + d_proxy.transfer_progress(stats); + } + */ + } + + protected override void update_tips(string refname, Ggit.OId a, Ggit.OId b) + { + GLib.debug("update_tips"); + //d_remote.tip_updated(refname, a, b); + + if (d_proxy != null) + { + d_proxy.update_tips(refname, a, b); + } + } + + protected override void completion(Ggit.RemoteCompletionType type) + { + GLib.debug("completion"); + if (d_proxy != null) + { + d_proxy.completion(type); + } + } + + protected override Ggit.Cred? credentials(string url, string? username_from_url, Ggit.Credtype allowed_types) throws Error + { + + GLib.debug("get credentials %s UN=%s", url, username_from_url); + var uri = new Soup.URI(url); + + if (uri != null) { + var ret = this.netrc(uri.get_host()); + if (ret != null) { + return ret; + } + + //return new Ggit.CredPlaintext(username_from_url, "test"); + } + return null; + /*var provider = d_remote.credentials_provider; + + if (provider != null) + { + ret = provider.credentials(url, username_from_url, allowed_types); + } + + if (ret == null && d_proxy != null) + { + ret = d_proxy.credentials(url, username_from_url, allowed_types); + } + + return ret; + */ + } + public Ggit.Cred netrc(string domain) + { + string str; + GLib.FileUtils.get_contents(GLib.Environment.get_home_dir() + "/.netrc", out str); + var lines = str.split("\n"); + for(var i=0; i< lines.length; i++) { + // assumes one line per entry.. if not we are buggered... + //GLib.debug("got %s" , lines[i]); + + var bits = Regex.split_simple ("[ \t]+", lines[i].strip()); + if (bits.length < 6 || bits[0] != "machine" || bits[1] != domain) { + continue; + } + GLib.debug("found password?"); + // we are gussing.... + return new Ggit.CredPlaintext(bits[3], bits[5]); + + } + return null; + + + + + } + +} \ No newline at end of file