-
Notifications
You must be signed in to change notification settings - Fork 275
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[New plugin] Git Change Bar #189
Conversation
This allows to automatically update the diff bar when e.g. changes are committed.
If the file encoding is different than the buffer encoding (as Geany will always have the buffer in UTF-8 but for encoding None) we need to convert it to get proper binary representation and then proper diff.
Apparently what was introduced as a defensive check catches an actual legitimate case, so transform it to a normal check.
This fixes ref monitoring after switching branches. While in most cases it doesn't matter because either the file has not changed or it has to be reloaded from disk anyway, it happens when the user uses `checkout -b`, as this will change the ref HEAD points to without touching the tree or index.
While monitoring provides best user experience by keeping the diff in sync with the actual repository status throughout commits and branch switch, some people want to avoid this kind of implicit behavior, so add a setting to allow disabling it.
While the initial goal of this plugin was bigger, only the changebar feature is currently ready, and useful enough to be released on its own.
Can you please add an entry to MAINTAINERS? :) |
Damn, I thought about it earlier today and then forgot :/ Fixed, thanks :) |
Hi, I've got some Problems when I run make: I've got libgit2-dev Version 0.19.0-2 on Xubuntu 13.10 |
Damn. Apparently libgit2 changes API quite often, and don't document these very well (I have 0.21.3 here FTR). Anyway, this one should be easy to fix, could you try this patch please? diff --git a/git-changebar/src/gcb-plugin.c b/git-changebar/src/gcb-plugin.c
index 38e7bae..1dbce0e 100644
--- a/git-changebar/src/gcb-plugin.c
+++ b/git-changebar/src/gcb-plugin.c
@@ -36,6 +36,9 @@
# define git_libgit2_init git_threads_init
# define git_libgit2_shutdown git_threads_shutdown
#endif
+#if LIBGIT2_VER_MAJOR == 0 && LIBGIT2_VER_MINOR < 20
+# define git_diff_hunk git_diff_range
+#endif
GeanyPlugin *geany_plugin; If it's all it takes I'll commit it, otherwise I'd like to see the additional issues and fix them at the same time. I'll try to build myself against 0.18 or 0.19 but it might not be immediate cause I'd have to set the environment up, so don't hesitate to tell me how it's going :) [edit]: typo in the patch, |
It runs through now. But there were some warnings/notes:
Also Geany crashed after I opened a file in one of my git repos. edt: Backtrace:
|
Boy. They also changed the signature for |
Debian stable is lagging libgit2 from what I have seen. Jessie will have 0.21. Also most common current distribution are having 0.21 aboard, maybe support 0.20+ is quiet ok. |
OK, give this a try: diff --git a/git-changebar/src/gcb-plugin.c b/git-changebar/src/gcb-plugin.c
index 38e7bae..0cb20a2 100644
--- a/git-changebar/src/gcb-plugin.c
+++ b/git-changebar/src/gcb-plugin.c
@@ -36,6 +36,9 @@
# define git_libgit2_init git_threads_init
# define git_libgit2_shutdown git_threads_shutdown
#endif
+#if LIBGIT2_VER_MAJOR == 0 && LIBGIT2_VER_MINOR < 20
+# define git_diff_hunk git_diff_range
+#endif
GeanyPlugin *geany_plugin;
@@ -569,6 +572,18 @@ diff_hunk_cb (const git_diff_delta *delta,
return 0;
}
+#if LIBGIT2_VER_MAJOR == 0 && LIBGIT2_VER_MINOR < 20
+static int
+diff_hunk_cb_wrapper (const git_diff_delta *delta,
+ const git_diff_hunk *hunk,
+ const char *header,
+ size_t header_len,
+ void *data)
+{
+ return diff_hunk_cb (delta, hunk, data);
+}
+# define diff_hunk_cb diff_hunk_cb_wrapper
+#endif
static GtkWidget *
get_widget_for_blob_range (GeanyDocument *doc,
@@ -663,6 +678,18 @@ tooltip_diff_hunk_cb (const git_diff_delta *delta,
return thd->found;
}
+#if LIBGIT2_VER_MAJOR == 0 && LIBGIT2_VER_MINOR < 20
+static int
+tooltip_diff_hunk_cb_wrapper (const git_diff_delta *delta,
+ const git_diff_hunk *hunk,
+ const char *header,
+ size_t header_len,
+ void *data)
+{
+ return tooltip_diff_hunk_cb (delta, hunk, data);
+}
+# define tooltip_diff_hunk_cb tooltip_diff_hunk_cb_wrapper
+#endif
static gboolean
on_sci_query_tooltip (GtkWidget *widget, |
I might consider it then, because it seems to get real painful to support 0.19. |
Good News, works now^^ Nice job. |
@lycianwolf no more warnings either? |
No. Not one. |
libgit2 < 0.20 had incompatible API for diff callbacks, so it requires some wrapping.
Great. Here you go, I added 332639f |
I can reproduce @lycianwolf mouse over issue |
Hum. Which ligit2 version @frlan? |
It's 0.21.3 from Jessie. |
Everything is fine with libgit2 0.19.0 in Xubuntu 14.04. |
Jessie has 0.21.1, 0.21.3 is only in unstable :) This said, I tried on Debian unstable (libgit2 0.21.3), with and without a composite window manager, and both on GTK2 and GTK3, and all was fine. I'm sorry, but I have no idea why you don't get the correct tooltip… could you maybe add a debug message at the start of g_debug ("%s(%p, %p, %d, %d)", G_STRFUNC, (gpointer) doc, (gpointer) blob,
line_start, n_lines); Actually the only thing I can imagine that would explain what I see in your capture would be if the Just as a matter of curiosity as I doubt it has anything to do with it, which Geany revision do you have? This plugins requires revision geany/geany@0a58f50 or newer for the tooltip to work properly with GTK2, but it's pretty old now (Dec 2, 2014) so I would imagine you have it. @aeberspaecher thanks! I was starting to feel like I was crazy or something, now I know at least I'm not the only one for which it does work :p |
Enable extra scrolling after the file's end so that even the last line can be displayed on top of the view at any size.
Okay guys! It was a bug with tooltips near the end of the original (as committed) file. Fixed in 913cf5d Thanks a lot @lycianwolf and @frlan for discovering this and for the help on IRC to narrow it down! Also as a bonus, now the zoom level of the editor is respected in the tooltip -- thanks to @frlan's capture that made me realize I didn't respect it before :) |
Now it really works^^ Thanks @b4n |
Suggested (minor) feature: it would be really nice to have keybindings for going to the next/previous hunk in the file. Suggested (bigger) feature: not sure if it's not out of scope of the plugin but it would be also nice to see all the modified files (e.g. in a new sidebar tab). Clicking the file in the sidebar would jump to the first change hunk in the file and together with the above-mentioned keybindings, one could easily review all the changes for the commit. Finally one really minor visual problem - when you press and hold enter, the change gets drawn only after you release it. I haven't checked the code but it might be just an issue of setting higher priority for some idle function (and if not, don't worry, it really doesn't matter). And thanks, thanks, thanks @b4n !!! I kept a hacky port of changebar from CodeBlocks which was part of scintilla itself and finally dropped it because there were too many changes in scintilla and it was getting hard to maintain. Proper changebar implementation was on my todo list and having it diffed against git is even better! |
Am 19.02.2015 um 11:51 schrieb Jiří Techet:
IIRC is this partly avaialble via gitbrowser[1] |
Ah, good, I'll try it (and this functionality probably really doesn't belong to git-changebar because it doesn't know anything about project and which opened files belong to which project). Is there any list of out-of-geany-plugins plugins? |
@techee, not that I know of, but you can find the best C/C++ code auto-formatter available here: http://codebrainz.github.io/code-format/ :) |
Sounds interesting, I'll look into that :)
Well, at first I wanted to make a mostly full-featured Git plugin, with log history browsing [1], branch management [1], file list, blame display in the the sidebar [2], commit management, staging/unstaging of chunks by clicking on the changebar and whatnot, but I postponed that for several reason -- the most important one being that doing that isn't so trivial so takes some time :) [1] I started a plugin (https://github.com/b4n/geany-git-ui) some time ago that implemented some of those, but while it has some nice features it's not yet really useful or ready enough for me to really release it (not to mention I have plenty uncommitted changes I let around and I now am scared of committing because I don't see what is what so well anymore :-'). However, feel free to try it out and use it and improve it and guilt me up into working on it and whatnot if you feel like it ;) BTW, when I started this plugin, I didn't know about libgit2 (I'm not even sure it existed at the time), and so I wrote some kind of custom GObject git library, which interacts with the Git command-line tool. While it has some advantages (like everything Git can do (non-interactively) can be done with limited efforts), it's obviously not very optimal. [2] This one I wanted to include in git-changebar, but I couldn't seem to get anything sensible out of libgit2 for modified buffers. I didn't spend days on it either, but it really felt like a libgit2 bug, so I let it go. This bump, and the fact that it'd be only seldom useful for me (it'd be at time, but not in a day-to-day basis) didn't help ^^
This actually is a feature :D I could lower the delay, or make it configurable if it's useful. Or maybe it could be removed altogether when I have a cached blob, I didn't test how long it takes to actually refresh the changebar alone. |
Maybe one more idea - would it be possible to copy/paste text from the By the way, apart from a minor problem with libgit2 configuration on OS X everything works there and while I don't plan to bundle plugins with extra And once again, thanks for Christmas in February :-). |
automake: warnings are treated as errors Then it compiles fine (unfortunately OS X doesn't have clang-format |
It might be hard to allow interaction with the tooltip, because it's almost fully managed by GTK itself -- I only provide the contents. (but yes, it's a Scintilla instance)
Undoing a hunk like that look more useful to me indeed, and should be reasonably easy to implement. I'll also try to give this a shot :) |
|
New plugin highlighting uncommitted changes to files tracked with Git. It is very similar in features to GEdit's Git plugin.
Features:
checkout -b
(optional).Closes #187.
Yes, I'm showing off with a pretty picture.