Skip to content

Commit

Permalink
pool manager: git box: add git add
Browse files Browse the repository at this point in the history
  • Loading branch information
carrotIndustries committed Mar 29, 2020
1 parent f0f18d4 commit ea5bcb4
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 6 deletions.
54 changes: 53 additions & 1 deletion src/pool-prj-mgr/pool-mgr/pool_git_box.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ PoolGitBox::PoolGitBox(BaseObjectType *cobject, const Glib::RefPtr<Gtk::Builder>
x->get_widget("checkbutton_git_diff_show_deleted", diff_show_deleted_checkbutton);
x->get_widget("checkbutton_git_diff_show_modified", diff_show_modified_checkbutton);
x->get_widget("git_diff_box", diff_box);
x->get_widget("git_add_with_deps_button", add_with_deps_button);
refresh_button->signal_clicked().connect(sigc::mem_fun(this, &PoolGitBox::refresh));
add_with_deps_button->signal_clicked().connect(sigc::mem_fun(this, &PoolGitBox::handle_add_with_deps));
status_treeview->get_selection()->signal_changed().connect(
[this] { add_with_deps_button->set_sensitive(status_treeview->get_selection()->count_selected_rows()); });

diff_show_deleted_checkbutton->signal_toggled().connect([this] { diff_store_filtered->refilter(); });
diff_show_modified_checkbutton->signal_toggled().connect([this] { diff_store_filtered->refilter(); });
Expand Down Expand Up @@ -283,11 +287,59 @@ void PoolGitBox::update_store_from_db(Glib::RefPtr<Gtk::ListStore> store)
notebook->pool.db.execute("DROP TABLE 'git_files'");
}

void PoolGitBox::handle_add_with_deps()
{
auto it = status_treeview->get_selection()->get_selected();
if (it) {
Gtk::TreeModel::Row row = *it;
UUID uu = row[list_columns.uuid];
ObjectType type = row[list_columns.type];
SQLite::Query q(notebook->pool.db,
"WITH RECURSIVE deps(typex, uuidx) AS "
"( SELECT ?, ? UNION "
"SELECT dep_type, dep_uuid FROM dependencies, deps "
"WHERE dependencies.type = deps.typex AND dependencies.uuid = deps.uuidx) "
", deps_sym(typey, uuidy) AS (SELECT * FROM deps UNION SELECT 'symbol', symbols.uuid FROM "
"symbols INNER JOIN deps ON (symbols.unit = uuidx AND typex = 'unit')) "
"SELECT filename FROM deps_sym INNER JOIN all_items_view "
"ON(all_items_view.type =deps_sym.typey AND all_items_view.uuid = deps_sym.uuidy) "
"UNION SELECT model_filename FROM models INNER JOIN deps "
"ON (deps.typex = 'package' AND deps.uuidx = models.package_uuid)");
q.bind(1, object_type_lut.lookup_reverse(type));
q.bind(2, uu);

autofree_ptr<git_repository> repo(git_repository_free);
if (git_repository_open(&repo.ptr, notebook->base_path.c_str()) != 0) {
throw std::runtime_error("error opening repo");
}

autofree_ptr<git_index> index(git_index_free);
if (git_repository_index(&index.ptr, repo) != 0) {
throw std::runtime_error("index error");
}

while (q.step()) {
std::string filename = q.get<std::string>(0);
if (git_index_add_bypath(index, filename.c_str()) != 0) {
auto last_error = giterr_last();
std::string err_str = last_error->message;
throw std::runtime_error("add error: " + err_str);
}
}

if (git_index_write(index) != 0) {
throw std::runtime_error("error saving index");
}

refresh();
}
}

PoolGitBox *PoolGitBox::create(PoolNotebook *nb)
{
PoolGitBox *w;
Glib::RefPtr<Gtk::Builder> x = Gtk::Builder::create();
std::vector<Glib::ustring> widgets = {"box_git"};
std::vector<Glib::ustring> widgets = {"box_git", "sg_git_header"};
x->add_from_resource("/org/horizon-eda/horizon/pool-prj-mgr/window.ui", widgets);
x->get_widget_derived("box_git", w, nb);
w->reference();
Expand Down
2 changes: 2 additions & 0 deletions src/pool-prj-mgr/pool-mgr/pool_git_box.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class PoolGitBox : public Gtk::Box {
Gtk::CheckButton *diff_show_deleted_checkbutton = nullptr;
Gtk::CheckButton *diff_show_modified_checkbutton = nullptr;
Gtk::Box *diff_box = nullptr;
Gtk::Button *add_with_deps_button = nullptr;

void make_treeview(Gtk::TreeView *treeview);

Expand Down Expand Up @@ -67,5 +68,6 @@ class PoolGitBox : public Gtk::Box {

void update_store_from_db_prepare();
void update_store_from_db(Glib::RefPtr<Gtk::ListStore> store);
void handle_add_with_deps();
};
} // namespace horizon
28 changes: 23 additions & 5 deletions src/pool-prj-mgr/window.ui
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@
<property name="orientation">vertical</property>
<property name="spacing">5</property>
<child>
<object class="GtkBox">
<object class="GtkBox" id="box3">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="spacing">5</property>
<property name="spacing">10</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
Expand Down Expand Up @@ -169,10 +169,10 @@
<property name="orientation">vertical</property>
<property name="spacing">5</property>
<child>
<object class="GtkBox">
<object class="GtkBox" id="box5">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="spacing">5</property>
<property name="spacing">10</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
Expand All @@ -189,7 +189,18 @@
</packing>
</child>
<child>
<placeholder/>
<object class="GtkButton" id="git_add_with_deps_button">
<property name="label" translatable="yes">git add with dependencies</property>
<property name="visible">True</property>
<property name="sensitive">False</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<placeholder/>
Expand Down Expand Up @@ -238,6 +249,13 @@
</packing>
</child>
</object>
<object class="GtkSizeGroup" id="sg_git_header">
<property name="mode">vertical</property>
<widgets>
<widget name="box3"/>
<widget name="box5"/>
</widgets>
</object>
<object class="GtkBox" id="box_remote">
<property name="visible">True</property>
<property name="can_focus">False</property>
Expand Down

0 comments on commit ea5bcb4

Please sign in to comment.