[gitg/mainlining: 2/4] Implement configuring of mainlines
- From: Jesse van den Kieboom <jessevdk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gitg/mainlining: 2/4] Implement configuring of mainlines
- Date: Sun, 21 Dec 2014 20:17:29 +0000 (UTC)
commit 918d0f90bdaed4474fc1d4a811165ee5804309ec
Author: Jesse van den Kieboom <jessevdk gmail com>
Date: Sun Dec 21 21:15:24 2014 +0100
Implement configuring of mainlines
data/org.gnome.gitg.gschema.xml.in.in | 8 +
gitg/history/gitg-history.vala | 169 ++++++++++++++++++++++--
gitg/preferences/gitg-preferences-history.vala | 24 +---
gitg/resources/ui/gitg-preferences-history.ui | 57 ++++++---
4 files changed, 209 insertions(+), 49 deletions(-)
---
diff --git a/data/org.gnome.gitg.gschema.xml.in.in b/data/org.gnome.gitg.gschema.xml.in.in
index fdb9cf8..624fda8 100644
--- a/data/org.gnome.gitg.gschema.xml.in.in
+++ b/data/org.gnome.gitg.gschema.xml.in.in
@@ -85,6 +85,14 @@
unstaged changes in the history.
</_description>
</key>
+ <key name="mainline-head" type="b">
+ <default>true</default>
+ <_summary>Mainline Head</_summary>
+ <_description>
+ Setting that indicates whether to always preserve a mainline in the
+ history for the current HEAD.
+ </_description>
+ </key>
</schema>
<schema gettext-domain="@GETTEXT_PACKAGE@" id="org.gnome.gitg.preferences.commit"
path="/org/gnome/gitg/preferences/commit/">
<child name="message" schema="org.gnome.gitg.preferences.commit.message" />
diff --git a/gitg/history/gitg-history.vala b/gitg/history/gitg-history.vala
index d12fd05..6215e02 100644
--- a/gitg/history/gitg-history.vala
+++ b/gitg/history/gitg-history.vala
@@ -41,6 +41,8 @@ namespace GitgHistory
private Gitg.PopupMenu d_refs_list_popup;
private Gitg.PopupMenu d_commit_list_popup;
+ private string[] d_mainline;
+
private Gitg.UIElements<GitgExt.HistoryPanel> d_panels;
public Activity(GitgExt.Application application)
@@ -115,10 +117,15 @@ namespace GitgHistory
construct
{
d_settings = new Settings("org.gnome.gitg.preferences.history");
+
d_settings.changed["topological-order"].connect((s, k) => {
update_sort_mode();
});
+ d_settings.changed["mainline-head"].connect((s, k) => {
+ update_walker();
+ });
+
d_selected = new Gee.HashSet<Ggit.OId>((Gee.HashDataFunc<Ggit.OId>)Ggit.OId.hash,
(Gee.EqualDataFunc<Ggit.OId>)Ggit.OId.equal);
@@ -130,6 +137,8 @@ namespace GitgHistory
application.bind_property("repository", this,
"repository", BindingFlags.DEFAULT);
+
+ reload_mainline();
}
private void update_sort_mode()
@@ -275,12 +284,93 @@ namespace GitgHistory
return -1;
}
+ private void store_changed_mainline()
+ {
+ var repo = application.repository;
+ Ggit.Config config;
+
+ try
+ {
+ config = repo.get_config();
+ } catch { return; }
+
+ store_mainline(config, string.joinv(",", d_mainline));
+ }
+
+ private void store_mainline(Ggit.Config? config, string mainline)
+ {
+ if (config != null)
+ {
+ try
+ {
+ config.set_string("gitg.mainline", mainline);
+ }
+ catch (Error e)
+ {
+ stderr.printf("Failed to set gitg.mainline: %s\n", e.message);
+ }
+ }
+ }
+
+ private void reload_mainline()
+ {
+ var uniq = new Gee.HashSet<string>();
+
+ d_mainline = new string[0];
+
+ var repository = application.repository;
+
+ if (repository == null)
+ {
+ return;
+ }
+
+ Ggit.Config? config = null;
+ var ref_names = new string[0];
+
+ try
+ {
+ config = repository.get_config();
+ ref_names = config.get_string("gitg.mainline").split(",");
+ }
+ catch
+ {
+ ref_names = new string[] {"refs/heads/master"};
+ }
+
+ foreach (var name in ref_names)
+ {
+ Gitg.Ref r;
+
+ try
+ {
+ r = repository.lookup_reference(name);
+ }
+ catch (Error e)
+ {
+ stderr.printf("Failed to lookup reference (%s): %s\n", name,
e.message);
+ continue;
+ }
+
+ var id = id_for_ref(r);
+
+ if (id != null && uniq.add(name))
+ {
+ d_mainline += name;
+ }
+ }
+
+ store_mainline(config, string.joinv(",", d_mainline));
+ }
+
private void reload()
{
var view = d_main.commit_list_view;
double vadj = d_main.refs_list.get_adjustment().get_value();
+ reload_mainline();
+
d_selected.clear();
d_scroll_to = null;
@@ -481,6 +571,48 @@ namespace GitgHistory
ac.populate_menu(menu);
}
+ var item = new Gtk.CheckMenuItem.with_label(_("Mainline"));
+ int pos = 0;
+
+ foreach (var ml in d_mainline)
+ {
+ if (ml == reference.get_name())
+ {
+ item.active = true;
+ break;
+ }
+
+ ++pos;
+ }
+
+ item.activate.connect(() => {
+ if (item.active)
+ {
+ d_mainline += reference.get_name();
+ }
+ else
+ {
+ var nml = new string[d_mainline.length - 1];
+ nml.length = 0;
+
+ for (var i = 0; i < d_mainline.length; i++)
+ {
+ if (i != pos)
+ {
+ nml += d_mainline[i];
+ }
+ }
+
+ d_mainline = nml;
+ }
+
+ store_changed_mainline();
+ update_walker();
+ });
+
+ item.show();
+ menu.append(item);
+
// To keep actions alive as long as the menu is alive
menu.set_data("gitg-ext-actions", actions);
return menu;
@@ -537,21 +669,38 @@ namespace GitgHistory
var isall = d_main.refs_list.is_all;
- var permanent = new Ggit.OId[0];
+ var perm_uniq = new Gee.HashSet<Ggit.OId>((Gee.HashDataFunc)Ggit.OId.hash,
+ (Gee.EqualDataFunc)Ggit.OId.equal);
- var seen = new Gee.HashSet<Ggit.OId>((Gee.HashDataFunc)Ggit.OId.hash,
- (Gee.EqualDataFunc)Ggit.OId.equal);
+ var permanent = new Ggit.OId[0];
- try
+ foreach (var ml in d_mainline)
{
- var head = id_for_ref(application.repository.get_head());
+ Ggit.OId id;
+
+ try
+ {
+ id = id_for_ref(application.repository.lookup_reference(ml));
+ } catch { continue; }
- if (head != null)
+ if (id != null && perm_uniq.add(id))
{
- permanent += head;
- seen.add(head);
+ permanent += id;
}
- } catch {}
+ }
+
+ if (d_settings.get_boolean("mainline-head"))
+ {
+ try
+ {
+ var head = id_for_ref(application.repository.get_head());
+
+ if (head != null && perm_uniq.add(head))
+ {
+ permanent += head;
+ }
+ } catch {}
+ }
foreach (var r in d_main.refs_list.selection)
{
@@ -565,7 +714,7 @@ namespace GitgHistory
{
d_selected.add(id);
- if (seen.add(id))
+ if (perm_uniq.add(id))
{
permanent += id;
}
diff --git a/gitg/preferences/gitg-preferences-history.vala b/gitg/preferences/gitg-preferences-history.vala
index d7c536e..0bf43c8 100644
--- a/gitg/preferences/gitg-preferences-history.vala
+++ b/gitg/preferences/gitg-preferences-history.vala
@@ -38,14 +38,8 @@ public class PreferencesHistory : Gtk.Grid, GitgExt.Preferences
[GtkChild (name = "topological_order")]
private Gtk.CheckButton d_topological_order;
- [GtkChild (name = "show_stash")]
- private Gtk.CheckButton d_show_stash;
-
- [GtkChild (name = "show_staged")]
- private Gtk.CheckButton d_show_staged;
-
- [GtkChild (name = "show_unstaged")]
- private Gtk.CheckButton d_show_unstaged;
+ [GtkChild (name = "mainline_head")]
+ private Gtk.CheckButton d_mainline_head;
private static int round_val(double val)
{
@@ -68,18 +62,8 @@ public class PreferencesHistory : Gtk.Grid, GitgExt.Preferences
"active",
SettingsBindFlags.GET | SettingsBindFlags.SET);
- settings.bind("show-stash",
- d_show_stash,
- "active",
- SettingsBindFlags.GET | SettingsBindFlags.SET);
-
- settings.bind("show-staged",
- d_show_staged,
- "active",
- SettingsBindFlags.GET | SettingsBindFlags.SET);
-
- settings.bind("show-unstaged",
- d_show_unstaged,
+ settings.bind("mainline-head",
+ d_mainline_head,
"active",
SettingsBindFlags.GET | SettingsBindFlags.SET);
diff --git a/gitg/resources/ui/gitg-preferences-history.ui b/gitg/resources/ui/gitg-preferences-history.ui
index 5a24edc..472d59f 100644
--- a/gitg/resources/ui/gitg-preferences-history.ui
+++ b/gitg/resources/ui/gitg-preferences-history.ui
@@ -132,25 +132,6 @@
</packing>
</child>
<child>
- <object class="GtkCheckButton" id="topological_order">
- <property name="label" translatable="yes">Show history in topological order</property>
- <property name="use_action_appearance">False</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="has_focus">False</property>
- <property name="is_focus">False</property>
- <property name="receives_default">False</property>
- <property name="halign">start</property>
- <property name="draw_indicator">True</property>
- </object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">5</property>
- <property name="width">1</property>
- <property name="height">1</property>
- </packing>
- </child>
- <child>
<object class="GtkGrid" id="grid5">
<property name="visible">True</property>
<property name="can_focus">False</property>
@@ -216,6 +197,44 @@
<property name="height">1</property>
</packing>
</child>
+ <child>
+ <object class="GtkCheckButton" id="topological_order">
+ <property name="label" translatable="yes">Show history in topological order</property>
+ <property name="use_action_appearance">False</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="has_focus">False</property>
+ <property name="is_focus">False</property>
+ <property name="receives_default">False</property>
+ <property name="halign">start</property>
+ <property name="draw_indicator">True</property>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">2</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkCheckButton" id="mainline_head">
+ <property name="label" translatable="yes">Preserve mainline for currently checked out
branch</property>
+ <property name="use_action_appearance">False</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="has_focus">False</property>
+ <property name="is_focus">False</property>
+ <property name="receives_default">False</property>
+ <property name="halign">start</property>
+ <property name="draw_indicator">True</property>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">3</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
</object>
<packing>
<property name="left_attach">0</property>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]