[libgit2-glib/wip/albfan/stage-windows] Invalid path resolving relative path on windows




commit 895be522e0bf16680780fbc8812498daf3cf3076
Author: Alberto Fanjul <albertofanjul gmail com>
Date:   Mon May 17 12:43:15 2021 +0200

    Invalid path resolving relative path on windows

 libgit2-glib/ggit-index.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
---
diff --git a/libgit2-glib/ggit-index.c b/libgit2-glib/ggit-index.c
index 20cb8cd..e54a4f9 100644
--- a/libgit2-glib/ggit-index.c
+++ b/libgit2-glib/ggit-index.c
@@ -425,6 +425,22 @@ ggit_index_get_entries_resolve_undo (GgitIndex *idx)
        return _ggit_index_entries_resolve_undo_wrap (idx);
 }
 
+static void
+string_replace (GString *string,
+                const gchar *find,
+                const gchar *replace)
+{
+       const gchar *at;
+       gssize pos;
+
+       at = strstr (string->str, find);
+       if (at != NULL) {
+               pos = at - string->str;
+               g_string_erase (string, pos, strlen (find));
+               g_string_insert (string, pos, replace);
+       }
+}
+
 /**
  * ggit_index_add_file:
  * @idx: a #GgitIndex.
@@ -456,6 +472,7 @@ ggit_index_add_file (GgitIndex  *idx,
 
        wd = ggit_repository_get_workdir (repo);
        path = g_file_get_relative_path (wd, file);
+       string_replace (path, "\\", "/");
 
        g_object_unref (wd);
        g_object_unref (repo);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]