1 module clone; 2 3 import git.c; 4 5 import core.thread; 6 import std.concurrency; 7 import std..string; 8 import std.stdio; 9 10 import common; 11 12 void clone_thread() 13 { 14 git_repository* repo = null; 15 16 // Kick off the clone 17 clone_data.ret = git_clone(&repo, toStringz(clone_data.url), toStringz(clone_data.path), 18 &clone_data.fetch_stats, &clone_data.checkout_stats, 19 &clone_data.opts); 20 21 if (repo) 22 git_repository_free(repo); 23 24 clone_data.finished = 1; 25 } 26 27 int do_clone(git_repository* repo, int argc, string[] args) 28 { 29 // Validate args 30 if (argc < 3) 31 { 32 writefln("USAGE: %s <url> <path>\n", args[0]); 33 return -1; 34 } 35 36 // Data for background thread 37 clone_data.url = args[1]; 38 clone_data.path = args[2]; 39 clone_data.opts.disable_filters = 1; 40 writefln("Cloning '%s' to '%s'", clone_data.url, clone_data.path); 41 42 // Create the worker thread 43 spawn(&clone_thread); 44 45 // Watch for progress information 46 do { 47 Thread.sleep(dur!("msecs")(100)); 48 writefln("Fetch %s/%s – Checkout %s/%s", 49 clone_data.fetch_stats.processed, clone_data.fetch_stats.total, 50 clone_data.checkout_stats.processed, clone_data.checkout_stats.total); 51 } while (!clone_data.finished); 52 53 writefln("Fetch %s/%s – Checkout %s/%s", 54 clone_data.fetch_stats.processed, clone_data.fetch_stats.total, 55 clone_data.checkout_stats.processed, clone_data.checkout_stats.total); 56 57 return clone_data.ret; 58 }