X-Git-Url: http://git.roojs.org/?p=gitlive;a=blobdiff_plain;f=GitBranch.vala;h=a30808be43dba4807a3ba13e35fd978839d5dd79;hp=483c9fc37b72c79168a2ca4a1392ee658fd35cb4;hb=72a4edfbda67d0bf3eb93a91c28c4084945ddae5;hpb=66b8908954940fc322f94d3e0790bd04b462cbbe diff --git a/GitBranch.vala b/GitBranch.vala index 483c9fc3..a30808be 100644 --- a/GitBranch.vala +++ b/GitBranch.vala @@ -1,5 +1,27 @@ /** represent a git branch.. +Branching / Gitlive: + +Does repo require branching? - flag in config? +** list of repo's ?? with ability to turn on/off + +Start editing without branch? +-> show prompt to start branch +-> flag a ticket? optional ?? + +Once editing branch... +-> merge with squash / ticket... +** show list of repo's with 'working' branches? +** select some/all to merge with a issue fix.. + +?? closing ticket in system ?? +-> done by the ui? + +need to push all? / fetch all? + + +list of repo's + */ @@ -10,38 +32,142 @@ public class GitBranch : Object public bool active = false; public string lastrev = ""; public string name = ""; - public string remote = "": + public bool is_remote; + public string remote = ""; public string remoterev = ""; + public string toString() + { + return + "active: " + (active ? "true" : "false") + "\n" + + "is_remote: " + (is_remote ? "true" : "false") + "\n" + + "lastrev: " + lastrev + "\n" + + "name: " + name + "\n" + + "remote: " + remote + "\n" + + "remoterev: " + remoterev + "\n"; + } + + public GitBranch(GitRepo repo) { this.repo = repo; } - public bool parseBranchListItem(str) + public static void loadBranches(GitRepo repo) { - if (!str.length) { + repo.branches = new Gee.HashMap(); + + var branches = new Gee.HashMap(); + var local = new Gee.HashMap(); + var remotes = new Gee.HashMap(); + + // repo.git( { "fetch", "-a" } ); == done async before... + + string[] cmd = { "branch", "--no-color", "--verbose", "--no-abbrev" , "-a" }; + var res = repo.git( cmd ); + var lines = res.split("\n"); + for (var i = 0; i < lines.length ; i++) { + var br = new GitBranch(repo); + if (!br.parseBranchListItem(lines[i])) { + continue; + } + GLib.debug("add branch %s", br.realName()); + if (!br.is_remote) { + local.set(br.name, br); + } else { + remotes.set(br.remote, br); + } + + branches.set(br.realName(), br); + if (br.active) { + repo.currentBranch = br; + } + } + + var bl = repo.git({ + "for-each-ref", + "--format", "%(refname:short):remotes/%(upstream:short)", + "refs/heads" + }).split("\n"); + + foreach(var line in bl) { + if (line.length < 1) continue; + + var ar = line.split(":remotes/"); + var lname= ar[0]; + var rname = "remotes/" + ar[1]; + + //print(rname); + // we should always have a local version of it. + if (branches.has_key(lname)) { + branches.get(lname).remote = rname; + } + + if (!branches.has_key(rname)) { + continue; + } + branches.get(lname).remoterev = branches.get(rname).lastrev; + // flag it for not adding.. + + branches.get(rname).name = lname; + } + foreach(var br in local.values) { + GLib.debug("BRANCH:\n%s\n" , br.toString()); + } + + /* + this bit of the code tries to turn a local branch into a track of a remote one. + -- that's probably not a good idea. + var r_replace = new Regex("^remotes/"); + var o_replace = new Regex("^origin/"); + foreach(var r in remotes.values) { + if (r.name.length >0) { + return; + } + var name = r_replace.replace(r.name, r.name.length,0, ""); + name = o_replace.replace(name, name.length,0, ""); + name = name.replace("/", "."); + + } + */ + repo.branches = local; + + + + } + + + public bool parseBranchListItem(string str) + { + if (str.length < 1) { return false; } this.active = str[0] == '*'; - var bits = Regex.split_simple ("[ \t]+", str.substring(2).strip()); - if (bits[1] == "->") { // it's an alias.. eg. remotes/origin/HEAD -> origin/master.. + var parts = Regex.split_simple ("[ \t]+", str.substring(2).strip()); + if (parts[1] == "->") { // it's an alias.. eg. remotes/origin/HEAD -> origin/master.. return false; } - + this.is_remote = false; this.lastrev = parts[1]; if (parts[0].has_prefix("remotes/")) { + this.is_remote = true; this.remote = parts[0]; } else { this.name = parts[0]; } return true; } - function realName() + public string realName() { - return this.name = "" ? this.remote : this.name; + return this.is_remote ? this.remote : this.name; } + + public void create() + { + + } + } \ No newline at end of file