[gitg/wip/albfan/filter-path] WIP: Filter by path



commit a9447f93bdb66f6bda204f1ffccf511caad64c3f
Author: Alberto Fanjul <albertofanjul gmail com>
Date:   Mon Jan 14 08:59:17 2019 +0100

    WIP: Filter by path

 gitg/gitg-dash-view.vala              | 20 ++++++++++++
 gitg/gitg-ui-elements.vala            | 12 ++++---
 gitg/gitg-window.vala                 | 30 ++++++++++++-----
 gitg/history/gitg-history.vala        | 11 +++++++
 gitg/resources/ui/gitg-window.ui      | 41 ++++++++++++++++++++---
 libgitg-ext/gitg-ext-searchable.vala  |  1 +
 libgitg/gitg-cell-renderer-lanes.vala | 11 ++++++-
 libgitg/gitg-commit-model.vala        | 61 +++++++++++++++++++++++++++++++++--
 libgitg/gitg-diff-view.vala           |  6 ++++
 libgitg/gitg-lane.vala                |  3 ++
 libgitg/gitg-lanes.vala               |  7 ++++
 meson.build                           |  2 +-
 12 files changed, 185 insertions(+), 20 deletions(-)
---
diff --git a/gitg/gitg-dash-view.vala b/gitg/gitg-dash-view.vala
index f6853edf..af084c97 100644
--- a/gitg/gitg-dash-view.vala
+++ b/gitg/gitg-dash-view.vala
@@ -127,6 +127,22 @@ class DashView : Gtk.Grid, GitgExt.UIElement, GitgExt.Activity, GitgExt.Selectab
                owned get { return null; }
        }
 
+       private string d_search_path;
+
+       public string search_path
+       {
+               owned get { return d_search_path; }
+
+               set
+               {
+                       if (d_search_path != value)
+                       {
+                               d_search_path = value;
+                               update_search_path();
+                       }
+               }
+       }
+
        private string d_search_text;
 
        public string search_text
@@ -150,6 +166,10 @@ class DashView : Gtk.Grid, GitgExt.UIElement, GitgExt.Activity, GitgExt.Selectab
 
        public bool search_visible { get; set; }
 
+       private void update_search_path()
+       {
+       }
+
        private void update_search_text()
        {
                if (d_repository_list_box != null)
diff --git a/gitg/gitg-ui-elements.vala b/gitg/gitg-ui-elements.vala
index 236a6e9b..bec9df69 100644
--- a/gitg/gitg-ui-elements.vala
+++ b/gitg/gitg-ui-elements.vala
@@ -294,7 +294,8 @@ public class UIElements<T> : Object
 
        public UIElements.with_builtin(T[] builtin,
                                       Peas.ExtensionSet extensions,
-                                      Gtk.Stack? stack = null)
+                                      Gtk.Stack? stack = null,
+                                      string? search_path = null)
        {
                d_extensions = extensions;
                d_stack = stack;
@@ -307,7 +308,10 @@ public class UIElements<T> : Object
                foreach (var b in builtin)
                {
                        GitgExt.UIElement elem = (GitgExt.UIElement)b;
-
+                       if (elem is Gitg.DiffView) {
+                               var diff_view =  elem as Gitg.DiffView;
+                               diff_view.search_path = search_path;
+                       }
                        d_builtin_elements[elem.id] = i++;
                        add_ui_element(elem);
                }
@@ -326,9 +330,9 @@ public class UIElements<T> : Object
        }
 
        public UIElements(Peas.ExtensionSet extensions,
-                         Gtk.Stack? stack = null)
+                         Gtk.Stack? stack = null, string? search_path = null)
        {
-               this.with_builtin(new T[] {}, extensions, stack);
+               this.with_builtin(new T[] {}, extensions, stack, search_path);
        }
 }
 
diff --git a/gitg/gitg-window.vala b/gitg/gitg-window.vala
index 36899c40..1d9d9da8 100644
--- a/gitg/gitg-window.vala
+++ b/gitg/gitg-window.vala
@@ -89,7 +89,9 @@ public class Window : Gtk.ApplicationWindow, GitgExt.Application, Initable
        [GtkChild]
        private Gtk.SearchBar d_search_bar;
        [GtkChild]
-       private Gtk.SearchEntry d_search_entry;
+       private Gtk.SearchEntry d_search_entry_text;
+       [GtkChild]
+       private Gtk.SearchEntry d_search_entry_path;
 
        [GtkChild]
        private Gtk.Stack d_main_stack;
@@ -241,11 +243,11 @@ public class Window : Gtk.ApplicationWindow, GitgExt.Application, Initable
 
                if (button.get_active())
                {
-                       d_search_entry.grab_focus();
+                       d_search_entry_text.grab_focus();
 
-                       d_search_entry.text = searchable.search_text;
+                       d_search_entry_text.text = searchable.search_text;
                        searchable.search_visible = true;
-                       searchable.search_entry = d_search_entry;
+                       searchable.search_entry = d_search_entry_text;
                }
                else
                {
@@ -255,7 +257,7 @@ public class Window : Gtk.ApplicationWindow, GitgExt.Application, Initable
        }
 
        [GtkCallback]
-       private void search_entry_changed(Gtk.Editable entry)
+       private void search_entry_text_changed(Gtk.Editable entry)
        {
                var searchable = current_activity as GitgExt.Searchable;
                var ntext = (entry as Gtk.Entry).text;
@@ -266,6 +268,18 @@ public class Window : Gtk.ApplicationWindow, GitgExt.Application, Initable
                }
        }
 
+       [GtkCallback]
+       private void search_entry_path_changed(Gtk.Editable entry)
+       {
+               var searchable = current_activity as GitgExt.Searchable;
+               var ntext = (entry as Gtk.Entry).text;
+
+               if (ntext != searchable.search_path)
+               {
+                       searchable.search_path = ntext;
+               }
+       }
+
        construct
        {
                if (Gitg.PlatformSupport.use_native_window_controls())
@@ -311,7 +325,7 @@ public class Window : Gtk.ApplicationWindow, GitgExt.Application, Initable
                d_activities_model = Builder.load_object<MenuModel>("ui/gitg-menus.ui", "win-menu-views");
 
                // search bar
-               d_search_bar.connect_entry(d_search_entry);
+               d_search_bar.connect_entry(d_search_entry_text);
                d_search_button.bind_property("active",
                                              d_search_bar,
                                              "search-mode-enabled",
@@ -771,7 +785,7 @@ public class Window : Gtk.ApplicationWindow, GitgExt.Application, Initable
                if (searchable != null)
                {
                        d_search_button.visible = true;
-                       d_search_entry.text = searchable.search_text;
+                       d_search_entry_text.text = searchable.search_text;
                        d_search_button.active = searchable.search_visible;
 
                        d_searchable_available_binding = searchable.bind_property("search-available",
@@ -785,7 +799,7 @@ public class Window : Gtk.ApplicationWindow, GitgExt.Application, Initable
                        d_search_button.visible = false;
                        d_search_button.active = false;
                        d_search_button.sensitive = false;
-                       d_search_entry.text = "";
+                       d_search_entry_text.text = "";
                }
 
                var selectable = (current as GitgExt.Selectable);
diff --git a/gitg/history/gitg-history.vala b/gitg/history/gitg-history.vala
index 6f091ef3..db9ec1db 100644
--- a/gitg/history/gitg-history.vala
+++ b/gitg/history/gitg-history.vala
@@ -1148,6 +1148,17 @@ namespace GitgHistory
                }
 
                public string search_text { owned get; set; default = ""; }
+               private string d_search_path;
+               public string search_path
+               {
+                       owned get { return d_search_path; }
+                       set
+                       {
+                               d_search_path = value;
+                               d_commit_list_model.search_path = d_search_path;
+                               d_commit_list_model.reload();
+                       }
+               }
                public bool search_visible { get; set; }
        }
 }
diff --git a/gitg/resources/ui/gitg-window.ui b/gitg/resources/ui/gitg-window.ui
index 115b957f..c7c6bf6d 100644
--- a/gitg/resources/ui/gitg-window.ui
+++ b/gitg/resources/ui/gitg-window.ui
@@ -243,11 +243,44 @@
                     <property name="can_focus">False</property>
                     <property name="show-close-button">False</property>
                     <child>
-                      <object class="GtkSearchEntry" id="d_search_entry">
+                      <object class="GtkBox" id="search_box">
                         <property name="visible">True</property>
-                        <property name="can_focus">True</property>
-                        <property name="width-request">500</property>
-                        <signal name="changed" handler="search_entry_changed" swapped="no"/>
+                        <property name="orientation">horizontal</property>
+                        <property name="spacing">6</property>
+                        <child>
+                          <object class="GtkLabel" id="label_text">
+                            <property name="label" translatable="yes">Text:</property>
+                            <property name="visible">True</property>
+                          </object>
+                          <packing>
+                            <property name="expand">False</property>
+                          </packing>
+                        </child>
+                        <child>
+                          <object class="GtkSearchEntry" id="d_search_entry_text">
+                            <property name="visible">True</property>
+                            <property name="can_focus">True</property>
+                            <property name="width-request">500</property>
+                            <signal name="changed" handler="search_entry_text_changed" swapped="no"/>
+                          </object>
+                        </child>
+                        <child>
+                          <object class="GtkLabel" id="label_path">
+                            <property name="label" translatable="yes">Path:</property>
+                            <property name="visible">True</property>
+                          </object>
+                          <packing>
+                            <property name="expand">False</property>
+                          </packing>
+                        </child>
+                        <child>
+                          <object class="GtkSearchEntry" id="d_search_entry_path">
+                            <property name="visible">True</property>
+                            <property name="can_focus">True</property>
+                            <property name="width-request">300</property>
+                            <signal name="changed" handler="search_entry_path_changed" swapped="no"/>
+                          </object>
+                        </child>
                       </object>
                     </child>
                   </object>
diff --git a/libgitg-ext/gitg-ext-searchable.vala b/libgitg-ext/gitg-ext-searchable.vala
index f49d5d6b..5e874b67 100644
--- a/libgitg-ext/gitg-ext-searchable.vala
+++ b/libgitg-ext/gitg-ext-searchable.vala
@@ -29,6 +29,7 @@ namespace GitgExt
 public interface Searchable : Object, Activity
 {
        public abstract string search_text { owned get; set; }
+       public abstract string search_path { owned get; set; }
        public abstract bool search_visible { get; set; }
        public abstract bool search_available { get; }
        public abstract Gtk.Entry? search_entry { set; }
diff --git a/libgitg/gitg-cell-renderer-lanes.vala b/libgitg/gitg-cell-renderer-lanes.vala
index 86f9c262..d37a20b1 100644
--- a/libgitg/gitg-cell-renderer-lanes.vala
+++ b/libgitg/gitg-cell-renderer-lanes.vala
@@ -104,6 +104,10 @@ namespace Gitg
 
                        foreach (var lane in commit.get_lanes())
                        {
+                               if (!lane.interesting)
+                               {
+                                       continue;
+                               }
                                var color = lane.color;
                                context.set_source_rgb(color.r, color.g, color.b);
 
@@ -137,6 +141,11 @@ namespace Gitg
 
                        foreach (var lane in commit.get_lanes())
                        {
+                               if (!lane.interesting)
+                               {
+                                       continue;
+                               }
+
                                if ((lane.tag & LaneTag.HIDDEN) != 0)
                                {
                                        ++to;
@@ -214,7 +223,7 @@ namespace Gitg
                        context.set_source_rgb(0, 0, 0);
                        context.stroke_preserve();
 
-                       if (commit.lane != null)
+                       if (commit.lane != null && commit.lane.interesting)
                        {
                                var color = commit.lane.color;
                                context.set_source_rgb(color.r, color.g, color.b);
diff --git a/libgitg/gitg-commit-model.vala b/libgitg/gitg-commit-model.vala
index 7964e51a..5141c95a 100644
--- a/libgitg/gitg-commit-model.vala
+++ b/libgitg/gitg-commit-model.vala
@@ -113,6 +113,7 @@ namespace Gitg
                        }
                }
 
+               public string search_path { get; set; default=""; }
                public Ggit.OId[] permanent_lanes { get; set; }
 
                public signal void started();
@@ -405,7 +406,63 @@ namespace Gitg
                                        int mylane;
                                        SList<Lane> lanes;
 
-                                       if (d_lanes.next(commit, out lanes, out mylane))
+                                       var interesting = true;
+                                       if (search_path != null && search_path != "")
+                                       {
+                                               interesting = false;
+                                               var tree = commit.get_tree();
+                                               Commit c = commit;
+                                               var opts = new Ggit.DiffOptions();
+                                               opts.flags |= Ggit.DiffOption.IGNORE_WHITESPACE;
+                                               opts.flags |= Ggit.DiffOption.PATIENCE;
+                                               opts.n_context_lines = 3;
+                                               opts.n_interhunk_lines = 3;
+                                               opts.flags |= Ggit.DiffOption.SHOW_BINARY;
+                                               var diff = c.get_diff(opts, 0);
+
+                                               var search_path_copy = search_path;
+                                               try {
+                                                       diff.foreach(
+                                                               (delta, progress) => {
+                                                                       var old_file_path = 
delta.get_old_file().get_path();
+                                                                       var new_file_path = 
delta.get_new_file().get_path();
+                                                                       if 
(new_file_path.contains(search_path_copy) || old_file_path.contains(search_path_copy)) {
+                                                                               return -7;
+                                                                       }
+                                                                       return 0;
+                                                               },
+
+                                                               (delta, binary) => {
+                                                                       return interesting ? -7: 0;
+                                                               },
+
+                                                               (delta, hunk) => {
+                                                                       return interesting ? -7: 0;
+                                                               },
+
+                                                               (delta, hunk, line) => {
+                                                                       return interesting ? -7: 0;
+                                                               }
+                                                       );
+
+                                                       /*
+                                                       tree.walk(Ggit.TreeWalkMode.PRE, (root, entry) => {
+                                                               var file = root.concat(entry.get_name());
+                                                               var found = file.contains(search_path);
+                                                               return found ? -7 : 0;
+                                                       });
+                                                       */
+                                               } catch (Error e) {
+                                                       interesting = e.code == -7;
+                                               }
+                                               /*
+                                               f (!interesting) {
+                                                       continue;
+                                               }
+                                               */
+                                       }
+
+                                       if (d_lanes.next(commit, interesting, out lanes, out mylane))
                                        {
                                                commit.update_lanes((owned)lanes, mylane);
 
@@ -519,7 +576,7 @@ namespace Gitg
                public Gtk.TreeModelFlags get_flags()
                {
                        return Gtk.TreeModelFlags.LIST_ONLY |
-                              Gtk.TreeModelFlags.ITERS_PERSIST;
+                                  Gtk.TreeModelFlags.ITERS_PERSIST;
                }
 
                public bool get_iter(out Gtk.TreeIter iter, Gtk.TreePath path)
diff --git a/libgitg/gitg-diff-view.vala b/libgitg/gitg-diff-view.vala
index f4076f5b..334c4b27 100644
--- a/libgitg/gitg-diff-view.vala
+++ b/libgitg/gitg-diff-view.vala
@@ -52,6 +52,7 @@ public class Gitg.DiffView : Gtk.Grid
        private uint d_reveal_options_timeout;
        private uint d_unreveal_options_timeout;
 
+       public string search_path { owned get; set; }
        private static Gee.HashSet<string> s_image_mime_types;
 
        public Ggit.DiffOptions options
@@ -467,6 +468,11 @@ public class Gitg.DiffView : Gtk.Grid
                                                return 1;
                                        }
 
+                                       var new_file = delta.get_new_file().get_path();
+                                       var old_file = delta.get_old_file().get_path();
+                                       if (search_path != null && search_path != "" && 
(!new_file.contains(search_path) || !old_file.contains(search_path))){
+                                               return 0;
+                                       }
                                        add_file();
 
                                        DiffViewFileInfo? info = null;
diff --git a/libgitg/gitg-lane.vala b/libgitg/gitg-lane.vala
index f73841be..69af7410 100644
--- a/libgitg/gitg-lane.vala
+++ b/libgitg/gitg-lane.vala
@@ -38,6 +38,7 @@ public class Lane : Object
        public SList<int> from;
        public LaneTag tag;
        public Ggit.OId? boundary_id;
+       public bool interesting {get; set;}
 
        public Lane()
        {
@@ -61,6 +62,7 @@ public class Lane : Object
                Lane ret = new Lane.with_color(color);
                ret.from = from.copy();
                ret.tag = tag;
+               ret.interesting = interesting;
                ret.boundary_id = boundary_id;
 
                return ret;
@@ -71,6 +73,7 @@ public class Lane : Object
                Lane ret = new Lane.with_color(color.copy());
                ret.from = from.copy();
                ret.tag = tag;
+               ret.interesting = interesting;
                ret.boundary_id = boundary_id;
 
                return ret;
diff --git a/libgitg/gitg-lanes.vala b/libgitg/gitg-lanes.vala
index d782bba9..df380914 100644
--- a/libgitg/gitg-lanes.vala
+++ b/libgitg/gitg-lanes.vala
@@ -36,6 +36,7 @@ public class Lanes : Object
        {
                public Lane lane;
                public int inactive;
+               public bool interesting {get; set; default=true; }
                public Ggit.OId? from;
                public Ggit.OId? to;
 
@@ -46,6 +47,7 @@ public class Lanes : Object
                        this.from = from;
                        this.to = to;
                        this.lane = new Lane.with_color(color);
+                       this.lane.interesting = interesting;
                        this.inactive = 0;
                }
 
@@ -62,6 +64,7 @@ public class Lanes : Object
 
                        lane.tag = LaneTag.NONE;
                        lane.from = new SList<int>();
+                       lane.interesting = interesting;
 
                        if (!hidden)
                        {
@@ -154,6 +157,7 @@ public class Lanes : Object
        }
 
        public bool next(Commit           next,
+                    bool            interesting,
                         out SList<Lane> lanes,
                         out int         nextpos)
        {
@@ -177,6 +181,7 @@ public class Lanes : Object
                {
                        // there is no lane reserved for this commit, add a new lane
                        mylane = new LaneContainer(myoid, null);
+                       mylane.interesting = interesting;
 
                        d_lanes.add(mylane);
                        nextpos = (int)d_lanes.size - 1;
@@ -185,6 +190,8 @@ public class Lanes : Object
                {
                        // copy the color here because the commit is a new stop
                        mylane.lane.color = mylane.lane.color.copy();
+                       mylane.lane.interesting = interesting;
+                       mylane.interesting = interesting;
 
                        mylane.to = null;
                        mylane.from = next.get_id();
diff --git a/meson.build b/meson.build
index 18433641..7d25284e 100644
--- a/meson.build
+++ b/meson.build
@@ -2,7 +2,7 @@ project(
   'gitg', ['c', 'vala'],
   version: '3.30.1',
   license: 'GPL2+',
-  default_options: 'buildtype=debugoptimized',
+  default_options: 'buildtype=debug',
   meson_version: '>= 0.48.0',
 )
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]