From 128c96fc9db69baca7ba185e8a3def8fddff5f27 Mon Sep 17 00:00:00 2001 From: Alan Knowles Date: Thu, 21 Mar 2019 14:27:43 +0800 Subject: [PATCH] Uncommited changes synced --- Clones.bjs | 22 +++++++++++----------- Clones.vala | 10 +++++----- Git.vala | 3 ++- GitBranch.vala | 28 ++++++++++++++++++---------- GitRepo.vala | 22 ++++++++++++++++------ NewBranch.bjs | 1 + NewBranch.vala | 8 +++++--- StatusIcon.vala | 2 +- 8 files changed, 59 insertions(+), 37 deletions(-) diff --git a/Clones.bjs b/Clones.bjs index 9cebc87f..555a6b76 100644 --- a/Clones.bjs +++ b/Clones.bjs @@ -73,8 +73,8 @@ "cursor_changed" : "() => {\n // SEE SELECTION.CHANGED\n /*\n \n return;\n \n if (this.el.get_selection().count_selected_rows() < 1) {\n //nothing? - clea it?\n return;\n }\n var ret = {}; \n var model = this.get('/changedFilesStore');\n\n var s = this.el.get_selection();\n var files = [];\n s.selected_foreach(function(model,p,iter) {\n \n files.push( model.get_value(iter, 0).value.get_string());\n \n });\n this.get('/patchview').showDiff(files); \n //var value = ''+ ret.model.get_value(ret.iter, 1).value.get_string();\n //print(\"OUT?\" + value);// id..\n // load the list in the right grid..\n \n return true;\n*/\n}" }, "id" : "reposView", - "bool activate_on_single_click" : true, "* init" : " \n{\n var selection = this.el.get_selection();\n selection.set_mode( Gtk.SelectionMode.SINGLE);\n\n\n var description = new Pango.FontDescription();\n description.set_size(10000);\n this.el.override_font(description);\n \n}\n", + "bool activate_on_single_click" : true, "xtype" : "TreeView", "* pack" : "add", "int search_column" : 0, @@ -88,7 +88,7 @@ "$ pathToRepo" : "function(path) {\n\n var tr= this.repos;\n\n \n for(var i =0 ; i < tr.length; i++) {\n if (tr[i].repopath == path) {\n return tr[i];\n }\n } \n return false; \n}\n", "xtype" : "ListStore", "* pack" : "set_model", - "| void load" : "()\n{\n //this.insert(citer,iter,0);\n print(\"getting list\");\n var tr = GitRepo.list();\n \n this.el.clear();\n \n // fixme .. sort by last updated ...\n \n \n for(var i =0 ; i < tr.length; i++) {\n\t var repo = tr.index(i);\n\t // this is done before we display stuff...\n\t //repo.loadBranches();\n\t //repo.loadStatus();\n\t \n\t Gtk.TreeIter iter;\n\t this.el.append(out iter);\n \n //print(JSON.stringify(ret,null,4));\n //tr[i].getBranches();\n //tr[i].getStatus();\n //var hi;\n //try {\n //tr[i].debug=1;\n // hi = tr[i].history('/', 1, 'branch', tr[i].currentBranch.name );\n// print(JSON.stringify(hi,null,4));\n // } catch(e) { print(e);}\n \n this.el.set_value(iter, 0, repo.name );\n this.el.set_value( iter, 1, repo.currentBranch.name );\n this.el.set_value( iter, 2, repo.branchesToString() );\n// this.el.set_value(ret.iter, 2, '' + repo.branches.map(\n// function(e) { return e.name; \n// }).join(', ') \n // );\n// this.el.set_value(iter, 3, '' + (!hi ? '??' : hi[0].changed_raw)); \n this.el.set_value(iter, 4, repo.is_autocommit() ); \n this.el.set_value(iter, 5, repo.is_autopush() ); \n this.el.set_value(iter, 6, repo.git_working_dir ); \n // highlight color.\n var cb = repo.currentBranch;\n //print(JSON.stringify(cb,null,4));\n var col = \"#ffffff\";\n \n if (cb.lastrev != cb.remoterev) {\n col = \"#f2dede\";\n this.el.set_value( iter, 1, repo.currentBranch.name +\"\\n\" +\n \t(repo.ahead_or_behind == \"B\" ? \"Local is BEHIND remote\" : \"Local is AHEAD of remote\")\n \n );\n }\n if (repo.has_local_changes) {\n col = \"#d9edf7\";\n this.el.set_value( iter, 1, repo.currentBranch.name +\"\\nHas uncommitted changes\" );\n }\n if ((cb.lastrev != cb.remoterev) && (repo.has_local_changes)) {\n col = \"#fcf8e3\";\n this.el.set_value( iter, 1, repo.currentBranch.name +\"\\n\" + \n (repo.ahead_or_behind == \"B\" ? \"Local is BEHIND remote\" : \"Local is AHEAD of remote\") +\n \"\\nHas uncommitted changes\" ); \n }\n \n this.el.set_value(iter, 7, col ); \n var ticket = repo.activeTicket;\n \n this.el.set_value(iter, 8, repo.is_auto_branch() ); \n this.el.set_value(iter, 9, ticket == null ? \"\" : ticket.id ); \n \n \n } \n this.el.set_sort_column_id (0, Gtk.SortType.ASCENDING);\n} ", + "| void load" : "()\n{\n //this.insert(citer,iter,0);\n print(\"getting list\");\n var tr = GitRepo.list();\n \n this.el.clear();\n \n // fixme .. sort by last updated ...\n \n \n for(var i =0 ; i < tr.length; i++) {\n\t var repo = tr.index(i);\n\t // this is done before we display stuff...\n\t //repo.loadBranches();\n\t //repo.loadStatus();\n\t \n\t Gtk.TreeIter iter;\n\t this.el.append(out iter);\n \n //print(JSON.stringify(ret,null,4));\n //tr[i].getBranches();\n //tr[i].getStatus();\n //var hi;\n //try {\n //tr[i].debug=1;\n // hi = tr[i].history('/', 1, 'branch', tr[i].currentBranch.name );\n// print(JSON.stringify(hi,null,4));\n // } catch(e) { print(e);}\n \n this.el.set_value(iter, 0, repo.name );\n this.el.set_value( iter, 1, repo.getCurrentBranch().name );\n this.el.set_value( iter, 2, repo.branchesToString() );\n// this.el.set_value(ret.iter, 2, '' + repo.branches.map(\n// function(e) { return e.name; \n// }).join(', ') \n // );\n// this.el.set_value(iter, 3, '' + (!hi ? '??' : hi[0].changed_raw)); \n this.el.set_value(iter, 4, repo.is_autocommit() ); \n this.el.set_value(iter, 5, repo.is_autopush() ); \n this.el.set_value(iter, 6, repo.git_working_dir ); \n // highlight color.\n var cb = repo.getCurrentBranch();\n //print(JSON.stringify(cb,null,4));\n var col = \"#ffffff\";\n \n if (cb.lastrev != cb.remoterev) {\n col = \"#f2dede\";\n this.el.set_value( iter, 1, repo.getCurrentBranch().name +\"\\n\" +\n \t(repo.ahead_or_behind == \"B\" ? \"Local is BEHIND remote\" : \"Local is AHEAD of remote\")\n \n );\n }\n if (repo.has_local_changes) {\n col = \"#d9edf7\";\n this.el.set_value( iter, 1, repo.getCurrentBranch().name +\"\\nHas uncommitted changes\" );\n }\n if ((cb.lastrev != cb.remoterev) && (repo.has_local_changes)) {\n col = \"#fcf8e3\";\n this.el.set_value( iter, 1, repo.getCurrentBranch().name +\"\\n\" + \n (repo.ahead_or_behind == \"B\" ? \"Local is BEHIND remote\" : \"Local is AHEAD of remote\") +\n \"\\nHas uncommitted changes\" ); \n }\n \n this.el.set_value(iter, 7, col ); \n var ticket = repo.activeTicket;\n \n this.el.set_value(iter, 8, repo.is_auto_branch() ); \n this.el.set_value(iter, 9, ticket == null ? \"\" : ticket.id ); \n \n \n } \n this.el.set_sort_column_id (0, Gtk.SortType.ASCENDING);\n} ", "$ xns" : "Gtk" }, { @@ -105,8 +105,8 @@ "toggled" : " (self, path) => {\n \n \tGtk.TreeIter iter;\n \t_this.reposStore.el.get_iter_from_string(out iter, path);\n \t\n \tGLib.Value val;\n \tGLib.Value rval;\n \t_this.reposStore.el.get_value(iter, 4, out val);\n \t_this.reposStore.el.get_value(iter, 6, out rval);\n \t\n \tvar repopath = (string)rval;\n \tvar bval = (bool)val;\n \t_this.reposStore.el.set_value(iter, 4, !bval);\n \tGLib.debug(\"got repopath? %s\", repopath);\n \t\n \tvar repo = GitRepo.get_sync(repopath);\n \trepo.set_autocommit(!bval);\n \t \n \n}" }, "id" : "cr_autocommit", - "* pack" : "pack_start,false", "xtype" : "CellRendererToggle", + "* pack" : "pack_start,false", "$ xns" : "Gtk", "$ mode" : "Gtk.CellRendererMode.ACTIVATABLE" } @@ -126,8 +126,8 @@ "toggled" : " (self, path) => {\n \n \tGtk.TreeIter iter;\n \t_this.reposStore.el.get_iter_from_string(out iter, path);\n \t\n \tGLib.Value val;\n \tGLib.Value rval;\n \t_this.reposStore.el.get_value(iter, 5, out val);\n \t_this.reposStore.el.get_value(iter, 6, out rval);\n \t\n \tvar repopath = (string)rval;\n \tvar bval = (bool)val;\n \t_this.reposStore.el.set_value(iter, 5, !bval);\n \tvar repo = GitRepo.get_sync(repopath);\n \trepo.set_autopush(!bval);\n \t\n \t\n \t\n \n}" }, "id" : "cr_autopush", - "* pack" : "pack_start,false", "xtype" : "CellRendererToggle", + "* pack" : "pack_start,false", "$ xns" : "Gtk", "$ mode" : "Gtk.CellRendererMode.ACTIVATABLE" } @@ -147,8 +147,8 @@ "toggled" : " (self, path) => {\n \n \tGtk.TreeIter iter;\n \t_this.reposStore.el.get_iter_from_string(out iter, path);\n \t\n \tGLib.Value val;\n \tGLib.Value rval;\n \t_this.reposStore.el.get_value(iter, 8, out val);\n \t_this.reposStore.el.get_value(iter, 6, out rval);\n \t\n \tvar repopath = (string)rval;\n \tvar bval = (bool)val;\n \t_this.reposStore.el.set_value(iter, 8, !bval);\n \tvar repo = GitRepo.get_sync(repopath);\n \trepo.set_auto_branch(!bval);\n \t\n \t\n \t\n \n}" }, "id" : "cr_autobranch", - "xtype" : "CellRendererToggle", "* pack" : "pack_start,false", + "xtype" : "CellRendererToggle", "$ xns" : "Gtk", "$ mode" : "Gtk.CellRendererMode.ACTIVATABLE" } @@ -156,8 +156,8 @@ }, { "id" : "tv_repo", - "* init" : "\n this.el.add_attribute(_this.cr_repo.el , \"markup\", 0 );\n", "Gtk.SortType sort_order" : "Gtk.SortType.ASCENDING", + "* init" : "\n this.el.add_attribute(_this.cr_repo.el , \"markup\", 0 );\n", "title" : "Repo", "* pack" : "append_column", "xtype" : "TreeViewColumn", @@ -168,8 +168,8 @@ "items" : [ { "id" : "cr_repo", - "* pack" : "pack_start,false", "xtype" : "CellRendererText", + "* pack" : "pack_start,false", "$ xns" : "Gtk" } ] @@ -185,8 +185,8 @@ "items" : [ { "id" : "cr_active_ticket", - "xtype" : "CellRendererText", "* pack" : "pack_start,false", + "xtype" : "CellRendererText", "$ xns" : "Gtk" } ] @@ -202,8 +202,8 @@ "items" : [ { "id" : "cr_current_branch", - "* pack" : "pack_start,false", "xtype" : "CellRendererText", + "* pack" : "pack_start,false", "$ xns" : "Gtk" } ] @@ -219,8 +219,8 @@ "items" : [ { "id" : "cr_last_updated", - "* pack" : "pack_start,false", "xtype" : "CellRendererText", + "* pack" : "pack_start,false", "$ xns" : "Gtk" } ] @@ -237,8 +237,8 @@ "items" : [ { "id" : "cr_all_branches", - "* pack" : "pack_start,false", "xtype" : "CellRendererText", + "* pack" : "pack_start,false", "$ xns" : "Gtk" } ] diff --git a/Clones.vala b/Clones.vala index fba05f5c..d4c267b9 100644 --- a/Clones.vala +++ b/Clones.vala @@ -464,7 +464,7 @@ public class Clones : Object // } catch(e) { print(e);} this.el.set_value(iter, 0, repo.name ); - this.el.set_value( iter, 1, repo.currentBranch.name ); + this.el.set_value( iter, 1, repo.getCurrentBranch().name ); this.el.set_value( iter, 2, repo.branchesToString() ); // this.el.set_value(ret.iter, 2, '' + repo.branches.map( // function(e) { return e.name; @@ -475,24 +475,24 @@ public class Clones : Object this.el.set_value(iter, 5, repo.is_autopush() ); this.el.set_value(iter, 6, repo.git_working_dir ); // highlight color. - var cb = repo.currentBranch; + var cb = repo.getCurrentBranch(); //print(JSON.stringify(cb,null,4)); var col = "#ffffff"; if (cb.lastrev != cb.remoterev) { col = "#f2dede"; - this.el.set_value( iter, 1, repo.currentBranch.name +"\n" + + this.el.set_value( iter, 1, repo.getCurrentBranch().name +"\n" + (repo.ahead_or_behind == "B" ? "Local is BEHIND remote" : "Local is AHEAD of remote") ); } if (repo.has_local_changes) { col = "#d9edf7"; - this.el.set_value( iter, 1, repo.currentBranch.name +"\nHas uncommitted changes" ); + this.el.set_value( iter, 1, repo.getCurrentBranch().name +"\nHas uncommitted changes" ); } if ((cb.lastrev != cb.remoterev) && (repo.has_local_changes)) { col = "#fcf8e3"; - this.el.set_value( iter, 1, repo.currentBranch.name +"\n" + + this.el.set_value( iter, 1, repo.getCurrentBranch().name +"\n" + (repo.ahead_or_behind == "B" ? "Local is BEHIND remote" : "Local is AHEAD of remote") + "\nHas uncommitted changes" ); } diff --git a/Git.vala b/Git.vala index f8923461..63c03c7e 100644 --- a/Git.vala +++ b/Git.vala @@ -16,8 +16,9 @@ void main() } ); + Ggit.init(); - var a = new GitLive.Repo("/home/alan/gitlive/web.coba"); + var a = new GitLive.Repo("/home/alan/gitlive/web.Texon"); a.fetchAll(); return; /* diff --git a/GitBranch.vala b/GitBranch.vala index e9964922..c08721be 100644 --- a/GitBranch.vala +++ b/GitBranch.vala @@ -117,15 +117,22 @@ public class GitBranch : Object br.remoterev = remotes.get(rname).to_string(); remotes_used.set(rname,true); size_t ahead, behind; - repo.repo.get_ahead_behind( - gbr.get_target(), - remotes.get(rname), - out ahead, - out behind - ); - br.ahead = (int)ahead; - br.behind = (int) behind; + br.behind = 1; + + try { + repo.repo.get_ahead_behind( + gbr.get_target(), + remotes.get(rname), + out ahead, + out behind + ); + br.ahead = (int)ahead; + br.behind = (int) behind; + } catch(Error e) { + GLib.debug("we probably need to fetch... %s", repo.name); + } + } @@ -134,7 +141,7 @@ public class GitBranch : Object } if (br.active) { GLib.debug("repo: %s currentBranch = %s", repo.name, br.name); - repo.currentBranch = br; + repo._currentBranch = br; } } @@ -165,7 +172,8 @@ public class GitBranch : Object repo.branches.set(rn, br); } - if (repo.currentBranch == null) { + + if (repo._currentBranch == null) { GLib.error("could not find active Branch for %s", repo.name); } diff --git a/GitRepo.vala b/GitRepo.vala index 21cf4de4..73866d7a 100644 --- a/GitRepo.vala +++ b/GitRepo.vala @@ -26,7 +26,17 @@ public class GitRepo : Object public Gee.HashMap ignore_files; - public GitBranch currentBranch; + public GitBranch _currentBranch; + public GitBranch getCurrentBranch() { + if (this._currentBranch == null) { + this.loadBranches(); + } + if (this._currentBranch == null) { + GLib.error("could not work out current branch?"); + } + return this._currentBranch; + } + public Gee.HashMap branches; // accessed in GitBranch.. public RooTicket? activeTicket; @@ -222,7 +232,7 @@ public class GitRepo : Object public bool is_master_branch() { // special branches that do not allow autopushing now... - return this.currentBranch.name == "master" || this.currentBranch.name == "roojs"; + return this.getCurrentBranch().name == "master" || this.getCurrentBranch().name == "roojs"; } public void init_config() @@ -382,7 +392,7 @@ public class GitRepo : Object continue; } commitrevs += commitrevs.length > 0 ? " " : ""; - commitrevs += repo.currentBranch.lastrev; + commitrevs += repo.getCurrentBranch().lastrev; } } if (sucess && action == "CLOSE") { @@ -402,7 +412,7 @@ public class GitRepo : Object if (action == "CLOSE" || action == "LEAVE") { try { - var oldbranch = this.currentBranch.name; + var oldbranch = this.getCurrentBranch().name; this.setActiveTicket(null, master); string [] cmd = { "merge", "--squash", oldbranch }; this.git( cmd ); @@ -438,7 +448,7 @@ public class GitRepo : Object string[] cmd = { "merge", master}; this.git( cmd ); var notification = new Notify.Notification( - "Merged code from %s to %s".printf(master,this.currentBranch.name), + "Merged code from %s to %s".printf(master,this.getCurrentBranch().name), "", "dialog-information" @@ -454,7 +464,7 @@ public class GitRepo : Object } if (action == "EXIT") { try { - var oldbranch = this.currentBranch.name; + var oldbranch = this.getCurrentBranch().name; this.setActiveTicket(null, master); this.loadBranches(); var notification = new Notify.Notification( diff --git a/NewBranch.bjs b/NewBranch.bjs index 1fc586a5..57698fdd 100644 --- a/NewBranch.bjs +++ b/NewBranch.bjs @@ -28,6 +28,7 @@ "listeners" : { "switch_page" : "(page, page_num) => {\n\tGLib.debug(\"Switch to page: %d\", (int)page_num);\n\tswitch(page_num) {\n\t\tcase 0: \n\t\t\tbreak; // do nothing.. it's already loaded at start.\n\t\tcase 1: \n\t\t\t_this.create_ticket_tab.load_data();\n\t\t\tbreak;\n\t\tcase 2:\n\t\t\t_this.quick_commit_tab.load_data();\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tbreak;\n\t}\n}\n" }, + "id" : "notebook", "* pack" : "get_content_area().add", "xtype" : "Notebook", "$ xns" : "Gtk", diff --git a/NewBranch.vala b/NewBranch.vala index 9f4ac048..dd5200ee 100644 --- a/NewBranch.vala +++ b/NewBranch.vala @@ -12,6 +12,7 @@ public class NewBranch : Object } return _NewBranch; } + public Xcls_notebook notebook; public Xcls_label_select_ticket label_select_ticket; public Xcls_label_create_ticket label_create_ticket; public Xcls_label_quick_commit label_quick_commit; @@ -73,7 +74,7 @@ public class NewBranch : Object this.el.default_width = 500; this.el.deletable = true; this.el.modal = true; - var child_0 = new Xcls_Notebook2( _this ); + var child_0 = new Xcls_notebook( _this ); child_0.ref(); this.el.get_content_area().add ( child_0.el ); @@ -172,7 +173,7 @@ public class NewBranch : Object this.el.run(); } - public class Xcls_Notebook2 : Object + public class Xcls_notebook : Object { public Gtk.Notebook el; private NewBranch _this; @@ -181,9 +182,10 @@ public class NewBranch : Object // my vars (def) // ctor - public Xcls_Notebook2(NewBranch _owner ) + public Xcls_notebook(NewBranch _owner ) { _this = _owner; + _this.notebook = this; this.el = new Gtk.Notebook(); // my vars (dec) diff --git a/StatusIcon.vala b/StatusIcon.vala index 4363d8dd..7a2500a2 100644 --- a/StatusIcon.vala +++ b/StatusIcon.vala @@ -195,7 +195,7 @@ public class StatusIconA : StatusIcon { this.remove(m); } foreach(var r in GitRepo.singleton().cache.values ) { - GLib.debug("checking %s for branch = %s", r.name, r.currentBranch.name); + GLib.debug("checking %s for branch = %s", r.name, r.getCurrentBranch().name); if (r.is_master_branch()) { continue; } -- 2.39.2