Partial Fix #5560 - Gitlive - branching wip
[gitlive] / old_seed_version / Merger.bjs
1 {
2  "name" : "Merger",
3  "parent" : "",
4  "title" : "",
5  "path" : "/home/alan/gitlive/gitlive/old_seed_version/Merger.bjs",
6  "permname" : "",
7  "modOrder" : "",
8  "build_module" : "",
9  "items" : [
10   {
11    "listeners" : {
12     "response" : "function (self, id) {\n  // hide\n     //if (id < 1) {\n        this.el.hide();\n        return;\n    //}\n    if (typeof(this.get('bug').getValue()) != 'object') {\n        print(\"ERROR\");\n        return;\n    }\n \n    this.el.hide();\n        \n    //var val = this.get('bug').getValue();\n     //   Seed.print(val);\n}",
13     "destroy_event" : "function (self, event) {\n     this.el.hide();\n                return false;\n}"
14    },
15    "default_width" : 800,
16    "id" : "Merger",
17    "$ deletable" : true,
18    "title" : "Merger",
19    "xtype" : "Dialog",
20    "default_height" : 700,
21    "$ show" : "function(c) {\n    \n    if (!this.el) {\n        this.init();\n    }\n    var _this = this;\n     \n      //this.el.set_title(\"Merger - ??? \");\n//   this.el.set_title(\"Merger - \" + this.repo.repopath);\n\n\n     Merger.loading = true; // stop change firing on combos.\n     /// load up branches\n     \n     this.get('/historyTreeStore').el.clear();\n     this.get('/changedFilesStore').el.clear();\n     this.get('/patchview').clear();\n    \n     \n     \n     this.get('/workingCombo').load(Merger.repo.branches);\n     \n     this.get('/releaseCombo').load(Merger.repo.branches);\n\n\n\n\n     Merger.loading = false;\n\n    this.el.show_all();\n    //this.get('/ok_button').el.set_sensitive(false);\n    \n    // block until we return.\n    var run_ret = this.el.run();\n    if (run_ret < 1 ) {\n        return  \"DONE\";\n    }\n    print(\"RUN RETURN : \" + run_ret);\n    return \"DONE\";\n    //print(JSON.stringify(this.get('bug').getValue()));\n   // return this.get('bug').getValue();\n    //this.success = c.success;\n}\n",
22    "$ xns" : "Gtk",
23    "border_width" : 3,
24    "items" : [
25     {
26      "xtype" : "VBox",
27      "$ pack" : " function(p,e) {\n        p.el.get_content_area().pack_start(e.el,true,true,0)\n    }\n",
28      "$ xns" : "Gtk",
29      "items" : [
30       {
31        "* pack" : "pack_start,false,true",
32        "xtype" : "HBox",
33        "$ xns" : "Gtk",
34        "items" : [
35         {
36          "label" : "Working Branch",
37          "xtype" : "Label",
38          "$ xns" : "Gtk"
39         },
40         {
41          "listeners" : {
42           "changed" : "function (self) {\n   this.get('/historyTreeStore').loadTree();\n}"
43          },
44          "id" : "workingCombo",
45          "* init" : "function() {\n    this.el = new Gtk.ComboBox.with_entry();\n    \n    \n    this.model  = new XObject(this.model);\n    this.model.init();\n    this.el.set_model(this.model.el);\n    this.el.set_entry_text_column (0);\n     XObject.prototype.init.call(this);\n    \n}\n",
46          "xtype" : "ComboBox",
47          "$ xns" : "Gtk",
48          "$ load" : "function(tr)\n{\n    //this.insert(citer,iter,0);\n    this.model.el.clear();\n    \n    var master = false;\n    var working = false;\n    \n    for(var i =0 ; i < tr.length; i++) {\n        if (!tr[i].name.length) {\n            continue;\n        }\n        var ret = {  };\n        this.model.el.append(ret);\n        //print(JSON.stringify(ret,null,4));\n        if (tr[i].name == 'master') {\n            master = i;\n        }\n        if (tr[i].name == 'working') {\n            working = i;\n        }          \n        this.model.el.set_value(ret.iter, 0, '' + tr[i].name );\n        this.model.el.set_value(ret.iter, 1, '' + tr[i].rev  );\n \n        \n    }     \n    if (master !== false) {\n        this.el.set_active(master);\n    }\n    if (working !== false) {\n        this.el.set_active(working);\n    }\n    \n}",
49          "items" : [
50           {
51            "* init" : "function() {\n    XObject.prototype.init.call(this);\n    this.el.set_column_types ( 3, [\n           GObject.TYPE_STRING, // file  \n          GObject.TYPE_STRING, // added\n          GObject.TYPE_STRING, // removed\n      ] );\n}\n",
52            "xtype" : "ListStore",
53            "$ xns" : "Gtk",
54            "* prop" : "model"
55           }
56          ]
57         },
58         {
59          "label" : "Release Branch",
60          "xtype" : "Label",
61          "$ xns" : "Gtk"
62         },
63         {
64          "listeners" : {
65           "changed" : "function (self) {\n   this.get('/historyTreeStore').loadTree();\n}"
66          },
67          "id" : "releaseCombo",
68          "* init" : "function() {\n    this.el = new Gtk.ComboBox.with_entry();\n    \n    \n    this.model  = new XObject(this.model);\n    this.model.init();\n    this.el.set_model(this.model.el);\n    this.el.set_entry_text_column (0);\n     XObject.prototype.init.call(this);\n    \n}\n",
69          "xtype" : "ComboBox",
70          "$ xns" : "Gtk",
71          "$ load" : "function(tr)\n{\n    //this.insert(citer,iter,0);\n    this.model.el.clear();\n    \n    var master = false;\n    var release = false;\n    \n    for(var i =0 ; i < tr.length; i++) {\n        var ret = {  };\n        if (!tr[i].name.length) {\n            continue;\n        }\n        \n        this.model.el.append(ret);\n        //print(JSON.stringify(ret,null,4));\n        if (tr[i].name == 'master') {\n            master = i;\n        }\n        if (tr[i].name == 'release') {\n            release = i;\n        }\n         \n        this.model.el.set_value(ret.iter, 0, '' + tr[i].name );\n        this.model.el.set_value(ret.iter, 1, '' + tr[i].rev  );\n \n        \n    }     \n    if (master !== false) {\n        this.el.set_active(master);\n    }\n    if (release !== false) {\n        this.el.set_active(release);\n    }\n    \n}",
72          "items" : [
73           {
74            "* init" : "function() {\n    XObject.prototype.init.call(this);\n    this.el.set_column_types ( 3, [\n           GObject.TYPE_STRING, // file  \n          GObject.TYPE_STRING, // added\n          GObject.TYPE_STRING, // removed\n      ] );\n}\n",
75            "xtype" : "ListStore",
76            "$ xns" : "Gtk",
77            "* prop" : "model"
78           }
79          ]
80         }
81        ]
82       },
83       {
84        "position" : 400,
85        "xtype" : "VPaned",
86        "* pack" : "pack_end,true,true,0",
87        "$ xns" : "Gtk",
88        "items" : [
89         {
90          "position" : 200,
91          "xtype" : "HPaned",
92          "* pack" : "add",
93          "$ xns" : "Gtk",
94          "items" : [
95           {
96            "* init" : "function() {\n    XObject.prototype.init.call(this);\n     this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)\n}\n",
97            "xtype" : "ScrolledWindow",
98            "$ xns" : "Gtk",
99            "items" : [
100             {
101              "listeners" : {
102               "cursor_changed" : "function (self) {\n\n    if (this.el.get_selection().count_selected_rows() < 1) {\n        //nothing?\n        return;\n    }\n    var model = this.get('/historyTreeStore');\n    var ret = {};        \n     var s = this.el.get_selection();\n    s.get_selected(ret);\n    \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    var Repo = imports.Scm.Git.Repo.Repo;\n    \n    \n   \n    if (model.release === false) {\n        return;\n    }\n    model.rev = value;\n   \n    var files = Merger.repo.changedFiles('/',   'rev', model.release + '..' + value);\n    this.get('/changedFilesStore').load(files);\n    return true;\n\n}"
103              },
104              "* init" : "function() {\n    XObject.prototype.init.call(this);\n        var description = new Pango.FontDescription.c_new();\n   description.set_size(8000);\n     this.el.modify_font(description);\n\n     this.selection = this.el.get_selection();\n      this.selection.set_mode( Gtk.SelectionMode.SINGLE);\n    var _this = this;\n    /*\n 780                                                                     \n 781                                                                         // is this really needed??\n 782                                                                         this.selection.signal['changed'].connect(function() {\n 783                                                                                 _this.get('/LeftTree.view').listeners.cursor_changed.apply(\n 784                                                                                     _this.get('/LeftTree.view'), [ _this.get('/LeftTree.view'), '']\n 785                                                                                 );\n 786                                                                         });\n 787                                                                         \n */\n }\n",
105              "* pack" : "add",
106              "xtype" : "TreeView",
107              "$ xns" : "Gtk",
108              "items" : [
109               {
110                "release" : false,
111                "id" : "historyTreeStore",
112                "* init" : "function() {\n    XObject.prototype.init.call(this);\n    this.el.set_column_types ( 3, [\n       GObject.TYPE_STRING, // title \n      GObject.TYPE_STRING, // rev \n  ] );\n}\n",
113                "* pack" : "set_model",
114                "xtype" : "TreeStore",
115                "$ xns" : "Gtk",
116                "$ load" : "function(tr,iter)\n{\n    //this.insert(citer,iter,0);\n    if (!iter) {\n        this.el.clear();\n    }\n    \n    for(var i =0 ; i < tr.length; i++) {\n        var ret = {  };\n        if (iter) {\n            this.el.insert(ret ,iter,-1);\n        } else {\n            this.el.append(ret);\n        }\n        //print(JSON.stringify(ret,null,4));\n         \n          \n        this.el.set_value(ret.iter, 0, ''  +  tr[i].text );\n        this.el.set_value(ret.iter, 1, '' + tr[i].rev  );\n \n        if (tr[i].children && tr[i].children.length) {\n            this.load(tr[i].children, ret.iter);\n        }\n    }     \n}",
117                "$ loadTree" : "function() {\n\n   this.working = false;\n   if (Merger.loading) {\n        return;\n   }\n   \n   \n   var wid = this.get('/workingCombo').el.get_active();\n   var rid = this.get('/releaseCombo').el.get_active();\n   if (wid < 0 || rid < 0 || rid == wid) {\n        return;\n   }\n   \n   var w = Merger.repo.branches[wid];\n   var r = Merger.repo.branches[rid];\n   \n\n\n    var rev = r.name + '..' + w.name;\n    this.release = r.name;\n    this.working = w.name;\n    \n    // this takes some time, lets. try and dialog it..\n\n    \n    \n    \n    var msg = new Gtk.MessageDialog( {\n        buttons : Gtk.ButtonsType.NONE,\n        text: \"Loading History\"\n        \n    });\n    \n    msg.set_transient_for(Merger.el);\n    msg.set_modal(true);\n    msg.show_all();\n\n    var hist = Merger.repo.dayTree('/', false, 'rev', rev);\n    msg.hide();\n    \n    this.load(hist);\n        \n       \n}\n"
118               },
119               {
120                "* init" : "function() {\n    XObject.prototype.init.call(this);\n    this.el.add_attribute(this.items[0].el , 'markup', 0 );\n\n}\n",
121                "xtype" : "TreeViewColumn",
122                "* pack" : "append_column",
123                "title" : "Changes",
124                "$ xns" : "Gtk",
125                "items" : [
126                 {
127                  "* pack" : "pack_start",
128                  "xtype" : "CellRendererText",
129                  "$ xns" : "Gtk"
130                 }
131                ]
132               }
133              ]
134             }
135            ]
136           },
137           {
138            "* init" : "function() {\n    XObject.prototype.init.call(this);\n      this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)\n}\n",
139            "xtype" : "ScrolledWindow",
140            "$ xns" : "Gtk",
141            "items" : [
142             {
143              "listeners" : {
144               "cursor_changed" : "function (self) {\n  // SEE SELECTION.CHANGED\n    var files = this.files();\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}"
145              },
146              "id" : "changedFilesView",
147              "$ files" : "function() {\n     if (this.el.get_selection().count_selected_rows() < 1) {\n        //nothing? - clea it?\n        return [];\n    }\n\n    var ret = {};         \n \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    return files;\n}\n",
148              "* init" : "function() {\n    XObject.prototype.init.call(this);\n        var description = new Pango.FontDescription.c_new();\n   description.set_size(8000);\n     this.el.modify_font(description);\n\n     this.selection = this.el.get_selection();\n      this.selection.set_mode( Gtk.SelectionMode.MULTIPLE);\n    var _this = this;\n  this.selection.signal['changed'].connect(function() {\n     _this.listeners.cursor_changed.apply(\n          _this, [ _this, '']\n       );\n             });\n  }\n",
149              "xtype" : "TreeView",
150              "* pack" : "add",
151              "$ xns" : "Gtk",
152              "items" : [
153               {
154                "id" : "changedFilesStore",
155                "* init" : "function() {\n    XObject.prototype.init.call(this);\n    this.el.set_column_types ( 3, [\n       GObject.TYPE_STRING, // file  \n      GObject.TYPE_STRING, // added\n      GObject.TYPE_STRING, // removed\n  ] );\n}\n",
156                "xtype" : "ListStore",
157                "* pack" : "set_model",
158                "$ xns" : "Gtk",
159                "$ load" : "function(tr)\n{\n    //this.insert(citer,iter,0);\n    this.el.clear();\n    for(var i =0 ; i < tr.length; i++) {\n        var ret = {  };\n       \n        this.el.append(ret);\n        \n        //print(JSON.stringify(ret,null,4));\n         \n          \n        this.el.set_value(ret.iter, 0, ''  +  tr[i].filename );\n        this.el.set_value(ret.iter, 1, '' + tr[i].added  );\n        this.el.set_value(ret.iter, 2, '' + tr[i].removed  );\n \n        \n    }     \n}"
160               },
161               {
162                "* init" : "function() {\n    XObject.prototype.init.call(this);\n    this.el.add_attribute(this.items[0].el , 'markup', 0 );\n\n}\n",
163                "* pack" : "append_column",
164                "title" : "Filename",
165                "xtype" : "TreeViewColumn",
166                "min_width" : 200,
167                "$ xns" : "Gtk",
168                "resizable" : true,
169                "items" : [
170                 {
171                  "* pack" : "pack_start",
172                  "xtype" : "CellRendererText",
173                  "$ xns" : "Gtk"
174                 }
175                ]
176               },
177               {
178                "* init" : "function() {\n    XObject.prototype.init.call(this);\n    this.el.add_attribute(this.items[0].el , 'markup', 1 );\n\n}\n",
179                "title" : "Added",
180                "* pack" : "append_column",
181                "xtype" : "TreeViewColumn",
182                "min_width" : 50,
183                "$ xns" : "Gtk",
184                "items" : [
185                 {
186                  "* pack" : "pack_start",
187                  "xtype" : "CellRendererText",
188                  "$ xns" : "Gtk"
189                 }
190                ]
191               },
192               {
193                "* init" : "function() {\n    XObject.prototype.init.call(this);\n    this.el.add_attribute(this.items[0].el , 'markup', 2 );\n\n}\n",
194                "title" : "Removed",
195                "* pack" : "append_column",
196                "xtype" : "TreeViewColumn",
197                "min_width" : 50,
198                "$ xns" : "Gtk",
199                "items" : [
200                 {
201                  "* pack" : "pack_start",
202                  "xtype" : "CellRendererText",
203                  "$ xns" : "Gtk"
204                 }
205                ]
206               }
207              ]
208             },
209             {
210              "* pack" : false,
211              "xtype" : "TreeView",
212              "$ xns" : "Gtk",
213              "items" : [
214               {
215                "* pack" : false,
216                "xtype" : "ListStore",
217                "$ xns" : "Gtk"
218               }
219              ]
220             }
221            ]
222           }
223          ]
224         },
225         {
226          "xtype" : "VBox",
227          "$ xns" : "Gtk",
228          "items" : [
229           {
230            "* pack" : "pack_start,false,false,0",
231            "xtype" : "HBox",
232            "$ xns" : "Gtk",
233            "items" : [
234             {
235              "listeners" : {
236               "clicked" : "function (self) {\n    \n     \n     var model = this.get('/historyTreeStore');\n    \n    if (model.release === false) {\n        return;\n    }\n    \n \n    var files = this.get('/changedFilesView').files();\n    \n     if (!files.length) {\n        return; // error.!\n    }\n    var diff = Merger.repo.diff(files, model.release, model.rev);\n   \n   \n   print(\"history?\");\n   \n    \n    var history =  Merger.repo.history(files, 1, 'rev', model.rev);\n    \n    print(\"History\" + JSON.stringify(history, null,4));\n    \n    Commit = imports.Commit.Commit;\n\n    Commit.el.set_modal(true);\n    Commit.el.set_transient_for(Merger.el);\n\n    var ce = Commit.show({\n        repo : Merger.repo,\n        files : files,\n        release : model.release,\n        rev : model.rev,\n        author : history[0].changeby,\n        changed : history[0].changed_raw\n        \n    \n    });\n    if (ce === false ) {\n        return;\n    }\n    \n    \n    var diff = Merger.repo.diff(files, model.release, model.rev);\n    \n    \n    print(JSON.stringify(ce,null,4));\n    //.... commit!!!\n    \n    imports.GitMonitor.GitMonitor.pause();\n    \n    \n    \n    var msg = new Gtk.MessageDialog( {\n        buttons : Gtk.ButtonsType.NONE,\n        text: \"Committing Changes\"\n    });\n    \n    msg.set_transient_for(Merger.el);\n    msg.set_modal(true);\n    msg.show_all();\n\n     \n    \n    try { \n        \n        Merger.repo.checkout(model.release);\n        \n        print(\"Call apply patch\");\n        \n        Merger.repo.applyPatch(diff);\n        \n        var author = Merger.repo.parseAuthor(ce.author);\n        \n        print(\"Add new files.\");\n        // add all the files..\n        Merger.repo.add(files);\n        \n        print(\"Commit changes.\");\n        Merger.repo.commit({\n            name    : author.name,\n            email   : author.email,\n            author  : ce.author,\n            changed : ce.changed,\n            reason  : ce.message,\n            files : files\n            \n        });\n        \n      \n    } catch (e) {\n     //message..\n        msg.hide();\n         \n        var emsg = new Gtk.MessageDialog({\n                message_type: Gtk.MessageType.ERROR, \n                buttons : Gtk.ButtonsType.OK, \n                text: e.message\n        });\n        emsg.set_transient_for(Merger.el);\n        emsg.set_modal(true);\n        emsg.run();\n        emsg.destroy();\n        Merger.repo.stash(); // revert change.. - so we can go back...\n    }\n    msg.show_all();\n    msg.set_markup(\"Changing to previous branch\");\n    Merger.repo.checkout(model.working);\n    \n    \n    // if gitlive was previously running warn the user that it is now paused..\n    /*\n    var cmsg = new Gtk.MessageDialog({\n            message_type: Gtk.MessageType.ERROR, \n            buttons : Gtk.ButtonsType.OK, \n            text: \"Git Live is now paused \"\n    });\n    cmsg.run();\n    cmsg.destroy();\n    */\n    var _t = this;\n    GLib.timeout_add_seconds(GLib.PRIORITY_DEFAULT, 5, function() {\n         imports.GitMonitor.GitMonitor.resume();\n         msg.hide();\n         msg.destroy();\n          _t.get('/historyTreeStore').loadTree();\n          _t.get('/changedFilesStore').el.clear();\n          _t.get('/patchview').showDiff(files); \n         return false; //only once.\n    });\n     \n    \n\n\n}   "
237              },
238              "label" : "Commit diff (no merge)",
239              "xtype" : "Button",
240              "$ xns" : "Gtk"
241             }
242            ]
243           },
244           {
245            "* init" : "function() {\n    XObject.prototype.init.call(this);\n      this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)\n}\n",
246            "* pack" : "pack_end,true,true,0",
247            "xtype" : "ScrolledWindow",
248            "$ xns" : "Gtk",
249            "items" : [
250             {
251              "$ clear" : "function() {\n    \n    \n    \n     \n   // remove..\n    var s  = \"document.body.textContent='';\"\n        \n    this.el.execute_script(s);\n        \n        \n    \n    \n    \n}\n",
252              "id" : "patchview",
253              "xtype" : "WebView",
254              "* pack" : "add",
255              "$ showDiff" : "function(files) {\n    this.clear();\n    \n    \n     var model = this.get('/historyTreeStore');\n    \n    if (model.release === false) {\n        return;\n    }\n    \n    var diff = Merger.repo.diff(files, model.release, model.rev);\n    \n   // remove..\n    var s  = \"var pre  = document.createElement('pre'); document.body.appendChild(pre);\";\n    s += \"pre.textContent =  \" +\n             JSON.stringify(Merger.repo.lastCmd + \"\\n\") + '+  ' + \n           JSON.stringify(diff) + \";\";\n    print(s);\n        \n    this.el.execute_script(s);\n        \n        \n    \n    \n    \n}\n",
256              "$ xns" : "WebKit"
257             }
258            ]
259           }
260          ]
261         }
262        ]
263       }
264      ]
265     },
266     {
267      "label" : "Close",
268      "id" : "ok_button",
269      "* pack" : "add_action_widget,1",
270      "xtype" : "Button",
271      "$ xns" : "Gtk"
272     }
273    ]
274   }
275  ]
276 }