Skip to content
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

git-changebar: Windows support possible #214

Closed
eht16 opened this issue Apr 12, 2015 · 4 comments
Closed

git-changebar: Windows support possible #214

eht16 opened this issue Apr 12, 2015 · 4 comments

Comments

@eht16
Copy link
Member

eht16 commented Apr 12, 2015

I recently built libgit2 on Windows. I will publish a ZIP archive soon (AFAIK there are no official Windows binary builds available).

There are only two issues I found so far:

  • repository paths contain backslashes:

According to libgit2/libgit2#3012 libgit2 does not support backslashes as path seperator in repository paths. However, the current GCB code constructs the path of the file in the repository from the absolute file path and so on Windows it contains backslashes.
The following diff works for me though there is maybe a more elegant solution. It's a naive approach by simply replacing all backslashes by forward slashes:

diff --git a/git-changebar/src/gcb-plugin.c b/git-changebar/src/gcb-plugin.c
index 57afbcb..4db07b7 100644
--- a/git-changebar/src/gcb-plugin.c
+++ b/git-changebar/src/gcb-plugin.c
@@ -332,8 +332,17 @@ worker_thread (gpointer data)

     if (repo) {
       const gchar *relpath = path + strlen (git_repository_workdir (repo));
+#ifdef G_OS_WIN32
+      GString *repo_path = g_string_new(relpath);
+      /* relpath contains backslashes on Windows but libgit requires repository paths
+       * to be built of slashes, so replace them. */
+      utils_string_replace_all(repo_path, "\\", "/");
+#endif

-      job->blob = repo_get_file_blob (repo, relpath);
+      job->blob = repo_get_file_blob (repo, repo_path->str);
+#ifdef G_OS_WIN32
+      g_string_free(repo_path, TRUE);
+#endif
     } else {
       job->blob = NULL;
     }
  • native EOL characters confuse the diff:

On Windows git repositories often use a setting which converts line endings in files to the native line ending characters. This confuses the generated diff and so all lines are marked as changed.
One could change that GIT setting but this could cause further troubles.
The best workaround I found so far is ignoring white space in the generated diff. This however is more than we want here because, AFAIU, this ignores any whitespace changes at the end of the line.
So I don't suggest to do this unconditionally but maybe a plugin setting could be added to let the user choose and a hint that this might be especially useful on Windows.
The option itself:

diff --git a/git-changebar/src/gcb-plugin.c b/git-changebar/src/gcb-plugin.c
index 57afbcb..4db07b7 100644
--- a/git-changebar/src/gcb-plugin.c
+++ b/git-changebar/src/gcb-plugin.c
@@ -547,7 +556,7 @@ diff_blob_to_doc (const git_blob   *old_blob,

   /* no context lines, and no need to bother about binary checks */
   opts.context_lines = 0;
-  opts.flags = GIT_DIFF_FORCE_TEXT;
+  opts.flags = GIT_DIFF_FORCE_TEXT | GIT_DIFF_IGNORE_WHITESPACE_EOL;

   ret = git_diff_blob_to_buffer (old_blob, NULL, buf, len, NULL, &opts,
                                  NULL, hunk_cb, NULL, payload);

I would take care to include the plugin and the libgit2 library in the Windows installer and related stuff.

b4n added a commit to b4n/geany-plugins that referenced this issue May 26, 2015
Git uses its own path representation for files inside its tree, which
follows the UNIX path style (forward slashes).  So properly convert
internal paths from native to Git paths.

See libgit2/libgit2#3012

Part of Issue geany#214.
b4n added a commit to b4n/geany-plugins that referenced this issue May 26, 2015
@b4n
Copy link
Member

b4n commented May 26, 2015

First, thanks a lot for testing this on Windows!

Then, I spent quite some time trying to address both issues. Well, the first is relatively easy as you suggested, all what is needed is converting the paths (6a396b1). The EOL thing was a bit harder, but fortunately libgit2 has API for it too, so it only required a refactor to be able to use that (ee45caa). The only downside (if it is one), is that this requires libgit2 >= 0.21, so some older distributions won't be supported anymore -- but well, that's life.
Both are in https://github.com/b4n/geany-plugins/tree/git-changebar/content-filtered, could you please try it and see if it actually works as expected on Windows?

@b4n b4n closed this as completed in f86e458 Jun 1, 2015
@b4n
Copy link
Member

b4n commented Jun 1, 2015

Okay, I successfully tested on Windows, paths seems to now work fine. Filters were tested on Linux, but should be the same on Windows.

Thanks!

@eht16
Copy link
Member Author

eht16 commented Jun 5, 2015

Awesome! Thank you.

The filters also work on Windows, just tested.

P.S.: sorry for being so late :(.

@eht16
Copy link
Member Author

eht16 commented Jun 5, 2015

JFTR: here is the promised Windows build of libgit2:
http://download.geany.org/contrib/libgit2-0.22.2.zip

marcelogp pushed a commit to marcelogp/geany-plugins that referenced this issue Oct 26, 2015
Git uses its own path representation for files inside its tree, which
follows the UNIX path style (forward slashes).  So properly convert
internal paths from native to Git paths.

See libgit2/libgit2#3012

Part of Issue geany#214.
marcelogp pushed a commit to marcelogp/geany-plugins that referenced this issue Oct 26, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants