[gitg/wip/fetch] Update refs after remote tip updates
- From: Jesse van den Kieboom <jessevdk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gitg/wip/fetch] Update refs after remote tip updates
- Date: Tue, 23 Dec 2014 18:14:24 +0000 (UTC)
commit b399bb2f4f17a47f8d9346c4b215fb5ed8d23b07
Author: Jesse van den Kieboom <jessevdk gmail com>
Date: Tue Dec 23 19:14:03 2014 +0100
Update refs after remote tip updates
gitg/history/gitg-history-refs-list.vala | 77 ++++++++++++++++++++++++++----
gitg/history/gitg-history.vala | 13 +++++
2 files changed, 80 insertions(+), 10 deletions(-)
---
diff --git a/gitg/history/gitg-history-refs-list.vala b/gitg/history/gitg-history-refs-list.vala
index 8e8fa1c..b52bc46 100644
--- a/gitg/history/gitg-history-refs-list.vala
+++ b/gitg/history/gitg-history-refs-list.vala
@@ -425,6 +425,8 @@ public class RefsList : Gtk.ListBox
private Gtk.ListBoxRow? d_selected_row;
private Gitg.Remote[] d_remotes;
+ public signal void changed();
+
private class RemoteHeader
{
public RefHeader header;
@@ -609,7 +611,43 @@ public class RefsList : Gtk.ListBox
Ggit.OId a,
Ggit.OId b)
{
- stdout.printf("remote tip updated: %s, %s, %s\n", refname, a.to_string()[0:6],
b.to_string()[0:6]);
+ if (a.is_zero())
+ {
+ Gitg.Ref reference;
+
+ repository.clear_refs_cache();
+
+ try
+ {
+ reference = repository.lookup_reference(refname);
+ }
+ catch (Error e)
+ {
+ stderr.printf("Failed to lookup new reference '%s': %s\n", refname,
e.message);
+ return;
+ }
+
+ add_ref(reference);
+ }
+ else if (b.is_zero())
+ {
+ // Reference was removed, we need to find it by name
+ foreach (var reference in d_ref_map.keys)
+ {
+ if (reference.get_name() == refname)
+ {
+ repository.clear_refs_cache();
+ remove_ref(reference);
+ break;
+ }
+ }
+ }
+ else
+ {
+ // Ref just got updated, we should already have it. Just emit changed.
+ repository.clear_refs_cache();
+ changed();
+ }
}
private RefHeader add_remote_header(string name)
@@ -673,9 +711,15 @@ public class RefsList : Gtk.ListBox
return add_ref_row(reference, animation);
}
- public void add_ref(Gitg.Ref reference)
+ public bool add_ref(Gitg.Ref reference)
{
- add_ref_internal(reference, RefAnimation.ANIMATE);
+ if (add_ref_internal(reference, RefAnimation.ANIMATE) != null)
+ {
+ changed();
+ return true;
+ }
+
+ return false;
}
public void replace_ref(Gitg.Ref old_ref, Gitg.Ref new_ref)
@@ -687,12 +731,17 @@ public class RefsList : Gtk.ListBox
select = (get_selected_row() == d_ref_map[old_ref]);
}
- remove_ref_internal(old_ref, RefAnimation.ANIMATE);
- add_ref_internal(new_ref, RefAnimation.ANIMATE);
+ var removed = remove_ref_internal(old_ref, RefAnimation.ANIMATE);
+ var newrow = add_ref_internal(new_ref, RefAnimation.ANIMATE);
if (select)
{
- select_row(d_ref_map[new_ref]);
+ select_row(newrow);
+ }
+
+ if (removed || newrow != null)
+ {
+ changed();
}
}
@@ -718,11 +767,11 @@ public class RefsList : Gtk.ListBox
return name == "HEAD";
}
- private void remove_ref_internal(Gitg.Ref reference, RefAnimation animation = RefAnimation.NONE)
+ private bool remove_ref_internal(Gitg.Ref reference, RefAnimation animation = RefAnimation.NONE)
{
if (!d_ref_map.has_key(reference))
{
- return;
+ return false;
}
var row = d_ref_map[reference];
@@ -751,11 +800,19 @@ public class RefsList : Gtk.ListBox
d_header_map.unset(remote);
}
}
+
+ return true;
}
- public void remove_ref(Gitg.Ref reference)
+ public bool remove_ref(Gitg.Ref reference)
{
- remove_ref_internal(reference);
+ if (remove_ref_internal(reference))
+ {
+ changed();
+ return true;
+ }
+
+ return false;
}
private void refresh()
diff --git a/gitg/history/gitg-history.vala b/gitg/history/gitg-history.vala
index 86c1394..0814216 100644
--- a/gitg/history/gitg-history.vala
+++ b/gitg/history/gitg-history.vala
@@ -474,6 +474,19 @@ namespace GitgHistory
update_walker();
});
+ uint idleupdate = 0;
+
+ d_main.refs_list.changed.connect(() => {
+ if (idleupdate == 0)
+ {
+ idleupdate = Idle.add(() => {
+ idleupdate = 0;
+ update_walker();
+ return false;
+ });
+ }
+ });
+
d_commit_list_popup = new Gitg.PopupMenu(d_main.commit_list_view);
d_commit_list_popup.populate_menu.connect(on_commit_list_populate_menu);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]