[libgit2-glib] Added config find functions



commit e7c8278d00ce9494ea80c09ab47270a536b9494b
Author: Jesse van den Kieboom <jesse vandenkieboom epfl ch>
Date:   Tue Oct 30 10:35:50 2012 +0100

    Added config find functions

 libgit2-glib/ggit-config.c |   55 ++++++++++++++++++++++++++++++++++++++++++++
 libgit2-glib/ggit-config.h |    3 ++
 2 files changed, 58 insertions(+), 0 deletions(-)
---
diff --git a/libgit2-glib/ggit-config.c b/libgit2-glib/ggit-config.c
index 08854f8..602d221 100644
--- a/libgit2-glib/ggit-config.c
+++ b/libgit2-glib/ggit-config.c
@@ -161,7 +161,62 @@ ggit_config_new_default (GError **error)
 	{
 		return _ggit_config_wrap (config);
 	}
+}
+
+/**
+ * ggit_config_find_global:
+ *
+ * Find the file representing the users global git configuration. This file
+ * is usually located at $HOME/.gitconfig. This function will try to guess
+ * the full path to that file, if the file exists. The returned file may then
+ * be used with #ggit_config_new_from_file or #ggit_config_add_file. This
+ * function returns %NULL if the global config could not be found.
+ *
+ * Returns: (transfer full): a #GFile or %NULL if the global config could not be found.
+ *
+ **/
+GFile *
+ggit_config_find_global (void)
+{
+	gchar path[GIT_PATH_MAX];
 
+	if (git_config_find_global (path, GIT_PATH_MAX) != GIT_OK)
+	{
+		return NULL;
+	}
+	else
+	{
+		return g_file_new_for_path (path);
+	}
+}
+
+/**
+ * ggit_config_find_system:
+ *
+ * Find the file representing the systems global git configuration. This file
+ * is usually located at /etc/gitconfig on UNIX type systems or
+ * %PROGRAMFILES%\Git\etc\gitconfig on windows. This function will try to guess
+ * the full path to that file, if the file exists. The returned file may then
+ * be used with #ggit_config_new_from_file or #ggit_config_add_file. This
+ * function returns %NULL if the system config could not be found.
+ *
+ * Returns: (transfer full): a #GFile or %NULL if the system config could not
+ *                           be found.
+ *
+ **/
+GFile *
+ggit_config_find_system (void)
+{
+	gchar path[GIT_PATH_MAX];
+
+	if (git_config_find_system (path, GIT_PATH_MAX) != GIT_OK)
+	{
+		return NULL;
+	}
+	else
+	{
+		return g_file_new_for_path (path);
+	}
 }
 
 /**
diff --git a/libgit2-glib/ggit-config.h b/libgit2-glib/ggit-config.h
index fa9d93b..e09aa29 100644
--- a/libgit2-glib/ggit-config.h
+++ b/libgit2-glib/ggit-config.h
@@ -67,6 +67,9 @@ GgitConfig  *ggit_config_new_default   (GError                 **error);
 GgitConfig  *ggit_config_new_from_file (GFile                   *file,
                                         GError                 **error);
 
+GFile       *ggit_config_find_global   (void);
+GFile       *ggit_config_find_system   (void);
+
 void         ggit_config_add_file      (GgitConfig               *config,
                                         GFile                    *file,
                                         GgitConfigLevel           level,



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