[gitg] Show diff stat in commit dialog
- From: Jesse van den Kieboom <jessevdk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gitg] Show diff stat in commit dialog
- Date: Mon, 8 Jul 2013 11:47:28 +0000 (UTC)
commit 456271a4e8dffc59bd226a31cd9d14696412c472
Author: Jesse van den Kieboom <jessevdk gmail com>
Date: Mon Jul 8 13:47:09 2013 +0200
Show diff stat in commit dialog
gitg/commit/gitg-commit-dialog.vala | 67 ++++++++++++++++++++++++++++++-
gitg/commit/gitg-commit.vala | 55 +++++++++++++++++++++++++-
gitg/resources/ui/gitg-commit-dialog.ui | 32 ++++++++++++++-
3 files changed, 149 insertions(+), 5 deletions(-)
---
diff --git a/gitg/commit/gitg-commit-dialog.vala b/gitg/commit/gitg-commit-dialog.vala
index 9384afe..20469c0 100644
--- a/gitg/commit/gitg-commit-dialog.vala
+++ b/gitg/commit/gitg-commit-dialog.vala
@@ -62,6 +62,9 @@ class Dialog : Gtk.Dialog
[GtkChild (name = "infobar_close_button")]
private Gtk.Button d_infobar_close_button;
+ [GtkChild (name = "list_box_stats")]
+ private Gtk.ListBox d_list_box_stats;
+
private bool d_show_markup;
private bool d_show_right_margin;
private bool d_show_subject_margin;
@@ -76,6 +79,13 @@ class Dialog : Gtk.Dialog
private bool d_enable_spell_checking;
private string? d_spell_checking_language;
private GtkSpell.Checker? d_spell_checker;
+ private Ggit.DiffList d_diff_list;
+
+ public Ggit.DiffList? diff_list
+ {
+ owned get { return d_diff_list; }
+ construct set { d_diff_list = value; }
+ }
public GtkSource.View source_view_message
{
@@ -392,11 +402,63 @@ class Dialog : Gtk.Dialog
d_constructed = true;
init_message_area();
+
+ if (diff_list != null)
+ {
+ iterate_diff_list();
+ }
+ else
+ {
+ }
}
private Gtk.TextTag d_subject_tag;
private Gtk.TextTag d_too_long_tag;
+ private void iterate_diff_list()
+ {
+ var n = diff_list.get_num_deltas();
+
+ for (var i = 0; i < n; ++i)
+ {
+ Ggit.DiffDelta delta;
+ Ggit.DiffPatch patch;
+
+ try
+ {
+ diff_list.get_patch(i, out patch, out delta);
+ } catch { continue; }
+
+ size_t add;
+ size_t remove;
+
+ try
+ {
+ patch.get_line_stats(null, out add, out remove);
+ } catch { continue; }
+
+ var nf = delta.get_new_file();
+ var path = nf.get_path();
+
+ var row = new Gtk.Grid();
+ row.column_spacing = 6;
+
+ var ds = new Gitg.DiffStat();
+
+ ds.added = (uint)add;
+ ds.removed = (uint)remove;
+
+ row.attach(ds, 0, 0, 1, 1);
+
+ var lbl = new Gtk.Label(path);
+
+ row.attach(lbl, 1, 0, 1, 1);
+ row.show_all();
+
+ d_list_box_stats.add(row);
+ }
+ }
+
private void update_too_long_tag()
{
// Get the warning fg/bg colors
@@ -547,9 +609,10 @@ class Dialog : Gtk.Dialog
}
}
- public Dialog(Ggit.Signature author)
+ public Dialog(Ggit.Signature author,
+ Ggit.DiffList? diff_list)
{
- Object(author: author);
+ Object(author: author, diff_list: diff_list);
}
private void update_font_settings()
diff --git a/gitg/commit/gitg-commit.vala b/gitg/commit/gitg-commit.vala
index 600669a..3023455 100644
--- a/gitg/commit/gitg-commit.vala
+++ b/gitg/commit/gitg-commit.vala
@@ -502,11 +502,64 @@ namespace GitgCommit
return retval;
}
+ private async Ggit.DiffList? index_diff_list()
+ {
+ var opts = new Ggit.DiffOptions(Ggit.DiffOption.INCLUDE_UNTRACKED_CONTENT |
+ Ggit.DiffOption.DISABLE_PATHSPEC_MATCH |
+ Ggit.DiffOption.RECURSE_UNTRACKED_DIRS,
+ 3,
+ 3,
+ null,
+ null,
+ null);
+
+ var stage = application.repository.stage;
+
+ Ggit.Tree tree;
+
+ try
+ {
+ tree = yield stage.get_head_tree();
+ }
+ catch { return null; }
+
+ Ggit.DiffList? diff_list = null;
+
+ try
+ {
+ var index = application.repository.get_index();
+
+ yield Gitg.Async.thread(() => {
+ diff_list = new Ggit.DiffList.tree_to_index(application.repository,
+ tree,
+ index,
+ opts);
+ });
+ } catch { return null; }
+
+ return diff_list;
+ }
+
private void run_commit_dialog(bool skip_hooks,
Ggit.Signature author,
Ggit.Signature committer)
{
- var dlg = new Dialog(author);
+ index_diff_list.begin((obj, res) => {
+ var diff_list = index_diff_list.end(res);
+
+ run_commit_dialog_with_diff_list(skip_hooks,
+ author,
+ committer,
+ diff_list);
+ });
+ }
+
+ private void run_commit_dialog_with_diff_list(bool skip_hooks,
+ Ggit.Signature author,
+ Ggit.Signature committer,
+ Ggit.DiffList? diff_list)
+ {
+ var dlg = new Dialog(author, diff_list);
dlg.set_transient_for((Gtk.Window)d_main.get_toplevel());
dlg.set_default_response(Gtk.ResponseType.OK);
diff --git a/gitg/resources/ui/gitg-commit-dialog.ui b/gitg/resources/ui/gitg-commit-dialog.ui
index a09e921..b3f0cb7 100644
--- a/gitg/resources/ui/gitg-commit-dialog.ui
+++ b/gitg/resources/ui/gitg-commit-dialog.ui
@@ -119,7 +119,7 @@
</object>
<packing>
<property name="left_attach">0</property>
- <property name="top_attach">5</property>
+ <property name="top_attach">6</property>
<property name="width">2</property>
<property name="height">1</property>
</packing>
@@ -136,7 +136,7 @@
</object>
<packing>
<property name="left_attach">0</property>
- <property name="top_attach">4</property>
+ <property name="top_attach">5</property>
<property name="width">2</property>
<property name="height">1</property>
</packing>
@@ -237,6 +237,34 @@
<property name="height">1</property>
</packing>
</child>
+ <child>
+ <object class="GtkScrolledWindow" id="scrolled_window_stats">
+ <property name="visible">True</property>
+ <property name="vexpand">True</property>
+ <property name="shadow_type">in</property>
+ <style>
+ <class name="view"/>
+ <class name="content-view"/>
+ </style>
+ <child>
+ <object class="GtkListBox" id="list_box_stats">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="selection_mode">none</property>
+ <style>
+ <class name="view"/>
+ <class name="content-view"/>
+ </style>
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">4</property>
+ <property name="width">2</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
</object>
<packing>
<property name="expand">False</property>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]