[gitg/wip/albfan/three-way] Three way diff




commit 9b283d04ae847e3d77f4f608adcf892f88e1a910
Author: Alberto Fanjul <albertofanjul gmail com>
Date:   Mon Dec 27 11:06:25 2021 +0100

    Three way diff
    
    Diff view using left/base/right

 .../gitg-diff-view-file-renderer-text-three.vala   | 158 +++++++++++++++++++++
 libgitg/gitg-diff-view-file.vala                   |  10 +-
 libgitg/gitg-diff-view.vala                        |  10 +-
 libgitg/meson.build                                |   2 +
 libgitg/resources/resources.xml                    |   1 +
 .../ui/gitg-diff-view-file-renderer-text-three.ui  |  44 ++++++
 6 files changed, 219 insertions(+), 6 deletions(-)
---
diff --git a/libgitg/gitg-diff-view-file-renderer-text-three.vala 
b/libgitg/gitg-diff-view-file-renderer-text-three.vala
new file mode 100644
index 00000000..755ba10b
--- /dev/null
+++ b/libgitg/gitg-diff-view-file-renderer-text-three.vala
@@ -0,0 +1,158 @@
+/*
+ * This file is part of gitg
+ *
+ * Copyright (C) 2016 - Jesse van den Kieboom
+ *
+ * gitg is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * gitg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with gitg. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+[GtkTemplate (ui = "/org/gnome/gitg/ui/gitg-diff-view-file-renderer-text-three.ui")]
+class Gitg.DiffViewFileRendererTextThree : Gtk.Box, DiffSelectable, DiffViewFileRenderer, 
DiffViewFileRendererTextable
+{
+       [GtkChild( name = "scroll_left" )]
+       private unowned Gtk.ScrolledWindow d_scroll_left;
+       [GtkChild( name = "scroll_center" )]
+       private unowned Gtk.ScrolledWindow d_scroll_center;
+       [GtkChild( name = "scroll_right" )]
+       private unowned Gtk.ScrolledWindow d_scroll_right;
+
+
+       private Gitg.DiffViewFileRendererText d_renderer_left;
+       private Gitg.DiffViewFileRendererText d_renderer_center;
+       private Gitg.DiffViewFileRendererText d_renderer_right;
+
+       public DiffViewFileInfo info { get; construct set; }
+
+       public Ggit.DiffDelta? delta
+       {
+               get { return info.delta; }
+       }
+
+       public Repository? repository
+       {
+               get { return info.repository; }
+       }
+
+       public bool wrap_lines
+       {
+               get { return d_renderer_left.wrap_mode != Gtk.WrapMode.NONE; }
+               set
+               {
+                       if (value)
+                       {
+                               d_renderer_left.wrap_mode = Gtk.WrapMode.WORD_CHAR;
+                               d_renderer_center.wrap_mode = Gtk.WrapMode.WORD_CHAR;
+                               d_renderer_right.wrap_mode = Gtk.WrapMode.WORD_CHAR;
+                       }
+                       else
+                       {
+                               d_renderer_left.wrap_mode = Gtk.WrapMode.NONE;
+                               d_renderer_center.wrap_mode = Gtk.WrapMode.NONE;
+                               d_renderer_right.wrap_mode = Gtk.WrapMode.NONE;
+                       }
+               }
+       }
+
+       public new int tab_width
+       {
+               get
+               {
+                       return (int)d_renderer_left.get_tab_width();
+               }
+               set
+               {
+                       d_renderer_left.set_tab_width((uint)value);
+                       d_renderer_center.set_tab_width((uint)value);
+                       d_renderer_right.set_tab_width((uint)value);
+               }
+       }
+
+       public int maxlines
+       {
+               get
+               {
+                       return (int)d_renderer_left.maxlines;
+               }
+               set
+               {
+                       d_renderer_left.maxlines = value;
+                       d_renderer_center.maxlines = value;
+                       d_renderer_right.maxlines = value;
+               }
+       }
+
+       public bool highlight
+       {
+               get { return d_renderer_left.highlight; }
+
+               construct set
+               {
+                       if (highlight != value)
+                       {
+                               d_renderer_left.highlight = value;
+                               d_renderer_center.highlight = value;
+                               d_renderer_right.highlight = value;
+                       }
+               }
+       }
+
+       public DiffViewFileRendererTextThree(DiffViewFileInfo info, bool handle_selection)
+       {
+               Object(info: info);
+               d_renderer_left = new Gitg.DiffViewFileRendererText(info, handle_selection, 
DiffViewFileRendererText.Style.OLD);
+               d_renderer_center = new Gitg.DiffViewFileRendererText(info, handle_selection, 
DiffViewFileRendererText.Style.ONE);
+               d_renderer_right = new Gitg.DiffViewFileRendererText(info, handle_selection, 
DiffViewFileRendererText.Style.NEW);
+               d_scroll_left.add(d_renderer_left);
+               d_scroll_center.add(d_renderer_center);
+               d_scroll_right.add(d_renderer_right);
+       }
+
+       construct
+       {
+       }
+
+       public void add_hunk(Ggit.DiffHunk hunk, Gee.ArrayList<Ggit.DiffLine> lines)
+       {
+               can_select = false;
+               d_renderer_left.add_hunk(hunk, lines);
+               d_renderer_center.add_hunk(hunk, lines);
+               d_renderer_right.add_hunk(hunk, lines);
+       }
+
+       public bool has_selection
+       {
+               get
+               {
+                       //return d_renderer_left.has_selection() || d_renderer_right.has_selection() || 
d_renderer_center.has_selection();
+                       return false;
+               }
+       }
+
+       public bool can_select { get; construct set; }
+
+       public PatchSet selection
+       {
+               owned get
+               {
+                       /*if (d_renderer_left.has_selection())
+                               return d_renderer_left.get_selection();
+                       if (d_renderer_center.has_selection())
+                               return d_renderer_center.get_selection();
+                       if (d_renderer_right.has_selection())
+                               return d_renderer_right.get_selection();
+                       */
+                       return new PatchSet();
+               }
+       }
+}
diff --git a/libgitg/gitg-diff-view-file.vala b/libgitg/gitg-diff-view-file.vala
index 62a5fff4..b7b9331e 100644
--- a/libgitg/gitg-diff-view-file.vala
+++ b/libgitg/gitg-diff-view-file.vala
@@ -131,7 +131,7 @@ class Gitg.DiffViewFile : Gtk.Grid
                d_stack_switcher.set_visible(visible);
        }
 
-       public void add_text_renderer(bool handle_selection)
+       public void add_text_renderer(bool handle_selection, uint num_parents)
        {
                var renderer = new DiffViewFileRendererText(info, handle_selection, 
DiffViewFileRendererText.Style.ONE);
                renderer.show();
@@ -147,6 +147,14 @@ class Gitg.DiffViewFile : Gtk.Grid
                var renderer_split = new DiffViewFileRendererTextSplit(info, handle_selection);
                renderer_split.show();
                add_renderer(renderer_split, renderer_split, "splittext", _("Split"), true);
+
+               if (num_parents > 1)
+               {
+                       var renderer_three = new DiffViewFileRendererTextThree(info, handle_selection);
+                       renderer_three.show();
+                       add_renderer(renderer_three, renderer_three, "threetext", _("Merge"), true);
+               }
+
        }
 
        public void add_binary_renderer()
diff --git a/libgitg/gitg-diff-view.vala b/libgitg/gitg-diff-view.vala
index e84b1b96..9e182fb1 100644
--- a/libgitg/gitg-diff-view.vala
+++ b/libgitg/gitg-diff-view.vala
@@ -590,7 +590,7 @@ public class Gitg.DiffView : Gtk.Grid
 
                if (d_diff != null)
                {
-                       update_diff(d_diff, preserve_expanded, d_cancellable);
+                       update_diff(d_diff, preserve_expanded, d_cancellable, d_commit.get_parents().size);
                }
        }
 
@@ -693,7 +693,7 @@ public class Gitg.DiffView : Gtk.Grid
                return "";
        }
 
-       private void update_diff(Ggit.Diff diff, bool preserve_expanded, Cancellable? cancellable)
+       private void update_diff(Ggit.Diff diff, bool preserve_expanded, Cancellable? cancellable, uint 
num_parents)
        {
                var nqueries = 0;
                var finished = false;
@@ -703,7 +703,7 @@ public class Gitg.DiffView : Gtk.Grid
                        if (nqueries == 0 && finished && (cancellable == null || !cancellable.is_cancelled()))
                        {
                                finished = false;
-                               update_diff_hunks(diff, preserve_expanded, infomap, cancellable);
+                               update_diff_hunks(diff, preserve_expanded, infomap, cancellable, num_parents);
                        }
                };
 
@@ -730,7 +730,7 @@ public class Gitg.DiffView : Gtk.Grid
                check_finish();
        }
 
-       private void update_diff_hunks(Ggit.Diff diff, bool preserve_expanded, Gee.HashMap<string, 
DiffViewFileInfo> infomap, Cancellable? cancellable)
+       private void update_diff_hunks(Ggit.Diff diff, bool preserve_expanded, Gee.HashMap<string, 
DiffViewFileInfo> infomap, Cancellable? cancellable, uint num_parents)
        {
                var files = new Gee.ArrayList<Gitg.DiffViewFile>();
 
@@ -834,7 +834,7 @@ public class Gitg.DiffView : Gtk.Grid
                                        }
                                        if (can_diff_as_text)
                                        {
-                                               current_file.add_text_renderer(handle_selection);
+                                               current_file.add_text_renderer(handle_selection, num_parents);
                                                var renderer_list = current_file.renderer_list;
                                                foreach (DiffViewFileRenderer renderer in renderer_list)
                                                {
diff --git a/libgitg/meson.build b/libgitg/meson.build
index 6356a0de..56105239 100644
--- a/libgitg/meson.build
+++ b/libgitg/meson.build
@@ -45,6 +45,7 @@ sources = files(
   'gitg-diff-view-file-renderer-text.vala',
   'gitg-diff-view-file-renderer-textable.vala',
   'gitg-diff-view-file-renderer-text-split.vala',
+  'gitg-diff-view-file-renderer-text-three.vala',
   'gitg-diff-view-file-renderer.vala',
   'gitg-diff-view-file-selectable.vala',
   'gitg-diff-view-file.vala',
@@ -79,6 +80,7 @@ resource_data = files(
   'resources/ui/gitg-diff-view-file-renderer-image.ui',
   'resources/ui/gitg-diff-view-file-renderer-text.ui',
   'resources/ui/gitg-diff-view-file-renderer-text-split.ui',
+  'resources/ui/gitg-diff-view-file-renderer-text-three.ui',
   'resources/ui/gitg-diff-view-file.ui',
   'resources/ui/gitg-diff-view-options-spacing.ui',
   'resources/ui/gitg-diff-view-options.ui',
diff --git a/libgitg/resources/resources.xml b/libgitg/resources/resources.xml
index c1eb1ec8..87a4f333 100644
--- a/libgitg/resources/resources.xml
+++ b/libgitg/resources/resources.xml
@@ -9,6 +9,7 @@
     <file compressed="true" preprocess="xml-stripblanks">ui/gitg-diff-view-file-renderer-text.ui</file>
     <file compressed="true" preprocess="xml-stripblanks">ui/gitg-diff-view-file-renderer-binary.ui</file>
     <file compressed="true" preprocess="xml-stripblanks">ui/gitg-diff-view-file-renderer-text-split.ui</file>
+    <file compressed="true" preprocess="xml-stripblanks">ui/gitg-diff-view-file-renderer-text-three.ui</file>
     <file compressed="true" preprocess="xml-stripblanks">ui/gitg-diff-view-options.ui</file>
     <file compressed="true" preprocess="xml-stripblanks">ui/gitg-diff-view-options-spacing.ui</file>
     <file compressed="true" preprocess="xml-stripblanks">ui/gitg-diff-view-commit-details.ui</file>
diff --git a/libgitg/resources/ui/gitg-diff-view-file-renderer-text-three.ui 
b/libgitg/resources/ui/gitg-diff-view-file-renderer-text-three.ui
new file mode 100644
index 00000000..a3f7772d
--- /dev/null
+++ b/libgitg/resources/ui/gitg-diff-view-file-renderer-text-three.ui
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.19.0 -->
+<interface>
+  <requires lib="gtk+" version="3.16"/>
+  <template class="GitgDiffViewFileRendererTextThree" parent="GtkBox">
+    <property name="visible">True</property>
+    <property name="can_focus">False</property>
+    <property name="homogeneous">False</property>
+    <property name="orientation">horizontal</property>
+    <child>
+      <object class="GtkScrolledWindow" id="scroll_left">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="hexpand">True</property>
+        <property name="vexpand">True</property>
+       <property name="vscrollbar-policy">never</property>
+      </object>
+      <packing>
+        <property name="pack-type">start</property>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkScrolledWindow" id="scroll_center">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="hexpand">True</property>
+        <property name="vexpand">True</property>
+       <property name="vscrollbar-policy">never</property>
+      </object>
+    </child>
+    <child>
+      <object class="GtkScrolledWindow" id="scroll_right">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="hexpand">True</property>
+        <property name="vexpand">True</property>
+       <property name="vscrollbar-policy">never</property>
+      </object>
+      <packing>
+        <property name="pack-type">end</property>
+      </packing>
+    </child>
+  </template>
+</interface>


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