[gitg] Allow choosing merge diff parent
- From: Jesse van den Kieboom <jessevdk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gitg] Allow choosing merge diff parent
- Date: Tue, 16 Dec 2014 07:24:29 +0000 (UTC)
commit e5f467cbd3ff2352c213103d3e786090df08da6a
Author: Jesse van den Kieboom <jessevdk gmail com>
Date: Tue Dec 16 08:23:30 2014 +0100
Allow choosing merge diff parent
gitg/gitg-commit-action-create-patch.vala | 2 +-
libgitg/gitg-commit.vala | 30 ++++++---------------
libgitg/gitg-diff-view.vala | 40 ++++++++++++++++++++++++++--
libgitg/resources/diff-view.css | 9 ++++++
libgitg/resources/diff-view.html | 2 +
libgitg/resources/diff-view.js | 30 +++++++++++++++++++++-
6 files changed, 87 insertions(+), 26 deletions(-)
---
diff --git a/gitg/gitg-commit-action-create-patch.vala b/gitg/gitg-commit-action-create-patch.vala
index c232c0f..bf3a789 100644
--- a/gitg/gitg-commit-action-create-patch.vala
+++ b/gitg/gitg-commit-action-create-patch.vala
@@ -107,7 +107,7 @@ class CommitActionCreatePatch : GitgExt.UIElement, GitgExt.Action, GitgExt.Commi
opts.n_context_lines = nc;
opts.n_interhunk_lines = nc;
- return commit.get_diff(opts);
+ return commit.get_diff(opts, 0);
}
private void create_patch(File file) throws Error
diff --git a/libgitg/gitg-commit.vala b/libgitg/gitg-commit.vala
index 47f1fe3..5d2c594 100644
--- a/libgitg/gitg-commit.vala
+++ b/libgitg/gitg-commit.vala
@@ -111,7 +111,7 @@ public class Commit : Ggit.Commit
}
}
- public Ggit.Diff get_diff(Ggit.DiffOptions? options)
+ public Ggit.Diff get_diff(Ggit.DiffOptions? options, int parent)
{
Ggit.Diff? diff = null;
@@ -121,9 +121,9 @@ public class Commit : Ggit.Commit
{
var parents = get_parents();
- // Create a new diff from the parents to the commit tree
if (parents.size == 0)
{
+ // No parents, initial commit?
diff = new Ggit.Diff.tree_to_tree(repo,
null,
get_tree(),
@@ -131,27 +131,15 @@ public class Commit : Ggit.Commit
}
else
{
- for (var i = 0; i < parents.size; ++i)
+ if (parent >= parents.size)
{
- var parent = parents[i];
-
- if (i == 0)
- {
- diff = new Ggit.Diff.tree_to_tree(repo,
- parent.get_tree(),
- get_tree(),
- options);
- }
- else
- {
- var d = new Ggit.Diff.tree_to_tree(repo,
- parent.get_tree(),
- get_tree(),
- options);
-
- diff.merge(d);
- }
+ parent = (int)parents.size - 1;
}
+
+ diff = new Ggit.Diff.tree_to_tree(repo,
+ parents[parent].get_tree(),
+ get_tree(),
+ options);
}
}
catch (Error e)
diff --git a/libgitg/gitg-diff-view.vala b/libgitg/gitg-diff-view.vala
index be90c86..00dc045 100644
--- a/libgitg/gitg-diff-view.vala
+++ b/libgitg/gitg-diff-view.vala
@@ -42,6 +42,9 @@ namespace Gitg
case "load-parent":
d_view.load_parent(parameter("value"));
break;
+ case "select-parent":
+ d_view.select_parent(parameter("value"));
+ break;
}
return false;
@@ -58,6 +61,7 @@ namespace Gitg
private Settings? d_fontsettings;
private bool d_has_selection;
private Ggit.DiffOptions? d_options;
+ private string? d_parent;
private static Gee.HashMap<string, DiffView> s_diff_map;
private static uint64 s_diff_id;
@@ -103,6 +107,7 @@ namespace Gitg
{
d_diff = value;
d_commit = null;
+ d_parent = null;
update();
}
@@ -113,8 +118,12 @@ namespace Gitg
get { return d_commit; }
set
{
- d_commit = value;
- d_diff = null;
+ if (d_commit != value)
+ {
+ d_commit = value;
+ d_diff = null;
+ d_parent = null;
+ }
update();
}
@@ -230,6 +239,7 @@ namespace Gitg
o.set_boolean_member("debug", Environment.get_variable("GITG_GTK_DIFF_VIEW_DEBUG") !=
null);
o.set_boolean_member("changes_inline", changes_inline);
o.set_boolean_member("show_parents", show_parents);
+ o.set_string_member("parent", d_parent);
var strings = new Json.Object();
@@ -238,6 +248,7 @@ namespace Gitg
strings.set_string_member("loading_diff", _("Loading diff…"));
strings.set_string_member("notes", _("Notes:"));
strings.set_string_member("parents", _("Parents:"));
+ strings.set_string_member("diff_against", _("Diff against:"));
o.set_object_member("strings", strings);
@@ -512,7 +523,24 @@ namespace Gitg
if (d_commit != null)
{
- d_diff = d_commit.get_diff(options);
+ int parent = 0;
+ var parents = d_commit.get_parents();
+
+ if (d_parent != null)
+ {
+ for (var i = 0; i < parents.size; i++)
+ {
+ var id = parents.get_id(i);
+
+ if (id.to_string() == d_parent)
+ {
+ parent = i;
+ break;
+ }
+ }
+ }
+
+ d_diff = d_commit.get_diff(options, parent);
}
if (d_diff != null)
@@ -540,6 +568,12 @@ namespace Gitg
request_select_commit(id);
}
+ public void select_parent(string id)
+ {
+ d_parent = id;
+ update();
+ }
+
private PatchSet parse_patchset(Json.Node node)
{
PatchSet ret = new PatchSet();
diff --git a/libgitg/resources/diff-view.css b/libgitg/resources/diff-view.css
index c0afa13..58f7511 100644
--- a/libgitg/resources/diff-view.css
+++ b/libgitg/resources/diff-view.css
@@ -244,6 +244,15 @@ div.commit .note_message {
margin-bottom: 5px;
}
+div.commit .parent-chooser {
+ float: right;
+}
+
+div.commit .parent-chooser select {
+ margin-left: 6px;
+ padding: 1px;
+}
+
a {
color: #3465a4;
}
diff --git a/libgitg/resources/diff-view.html b/libgitg/resources/diff-view.html
index 56492ea..76744f0 100644
--- a/libgitg/resources/diff-view.html
+++ b/libgitg/resources/diff-view.html
@@ -35,6 +35,8 @@
<div id="diff">
<div id="diff_header">
<div class="commit">
+ <div class="parent-chooser" data-id="parent_chooser">
+ </div>
<img class="avatar" data-id="avatar" src="gitg-diff:/icon/avatar-default-symbolic?size=50"/>
<p>
<span class="author" data-id="author"></span><br/>
diff --git a/libgitg/resources/diff-view.js b/libgitg/resources/diff-view.js
index 217f72a..8ab37ca 100644
--- a/libgitg/resources/diff-view.js
+++ b/libgitg/resources/diff-view.js
@@ -27,7 +27,8 @@ var settings = {
unstage: 'unstage',
loading_diff: 'Loading diff...',
notes: 'Notes:',
- parents: 'Parents:'
+ parents: 'Parents:',
+ diff_against: 'Diff against:'
},
};
@@ -165,6 +166,33 @@ function write_commit(content, commit)
elems.notes_container.hide();
}
+ if (commit.parents.length > 1)
+ {
+ var span = $('<span/>').text(settings.strings.diff_against);
+ var chooser = $('<select/>');
+
+ for (var i = 0; i < commit.parents.length; i++)
+ {
+ var parent = commit.parents[i];
+ var elem = $('<option/>', {
+ value: parent.id
+ }).text(parent.id.slice(0, 6));
+
+ if (parent.id === settings.parent)
+ {
+ elem.attr('selected', 'selected');
+ }
+
+ chooser.append(elem);
+ }
+
+ chooser.on('change', function() {
+ xhr_get('internal', {'action': 'select-parent', 'value': chooser.val()});
+ });
+
+ elems.parent_chooser.html([span, chooser]);
+ }
+
if (commit.parents.length > 1 && settings.show_parents)
{
var d = $('<div/>');
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]