[libgit2-glib] Add GgitStatusOptions
- From: Jesse van den Kieboom <jessevdk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgit2-glib] Add GgitStatusOptions
- Date: Sun, 23 Jun 2013 13:55:08 +0000 (UTC)
commit 26d95b42dece73ae247fa580e95d6bf9f8517b69
Author: Jesse van den Kieboom <jessevdk gmail com>
Date: Sun Jun 23 15:55:02 2013 +0200
Add GgitStatusOptions
libgit2-glib/Makefile.am | 2 +
libgit2-glib/ggit-repository.c | 12 +++-
libgit2-glib/ggit-repository.h | 1 +
libgit2-glib/ggit-status-options.c | 121 ++++++++++++++++++++++++++++++++++++
libgit2-glib/ggit-status-options.h | 52 +++++++++++++++
libgit2-glib/ggit-types.c | 14 ++++
libgit2-glib/ggit-types.h | 50 +++++++++++++++
7 files changed, 249 insertions(+), 3 deletions(-)
---
diff --git a/libgit2-glib/Makefile.am b/libgit2-glib/Makefile.am
index 36827af..9e6db90 100644
--- a/libgit2-glib/Makefile.am
+++ b/libgit2-glib/Makefile.am
@@ -50,6 +50,7 @@ INST_H_FILES = \
ggit-repository.h \
ggit-revision-walker.h \
ggit-signature.h \
+ ggit-status-options.h \
ggit-submodule.h \
ggit-tag.h \
ggit-transfer-progress.h \
@@ -97,6 +98,7 @@ C_FILES = \
ggit-repository.c \
ggit-revision-walker.c \
ggit-signature.c \
+ ggit-status-options.c \
ggit-submodule.c \
ggit-tag.c \
ggit-transfer-progress.c \
diff --git a/libgit2-glib/ggit-repository.c b/libgit2-glib/ggit-repository.c
index 64586a7..14395df 100644
--- a/libgit2-glib/ggit-repository.c
+++ b/libgit2-glib/ggit-repository.c
@@ -42,6 +42,7 @@
#include "ggit-submodule.h"
#include "ggit-signature.h"
#include "ggit-clone-options.h"
+#include "ggit-status-options.h"
#define GGIT_REPOSITORY_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE((object), GGIT_TYPE_REPOSITORY,
GgitRepositoryPrivate))
@@ -1017,6 +1018,7 @@ ggit_repository_file_status (GgitRepository *repository,
/**
* ggit_repository_file_status_foreach:
* @repository: a #GgitRepository.
+ * @options: (allow-none): status options, or %NULL.
* @callback: (scope call): a #GgitStatusCallback.
* @user_data: callback user data.
* @error: a #GError for error reporting, or %NULL.
@@ -1027,11 +1029,14 @@ ggit_repository_file_status (GgitRepository *repository,
* passed to this function. If the callback returns something other than
* 0, the iteration will stop and @error will be set.
*
+ * Set @options to %NULL to get the default status options.
+ *
* Returns: %TRUE if there was no error, %FALSE otherwise
*
*/
gboolean
ggit_repository_file_status_foreach (GgitRepository *repository,
+ GgitStatusOptions *options,
GgitStatusCallback callback,
gpointer user_data,
GError **error)
@@ -1042,9 +1047,10 @@ ggit_repository_file_status_foreach (GgitRepository *repository,
g_return_val_if_fail (callback != NULL, FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
- ret = git_status_foreach (_ggit_native_get (repository),
- callback,
- user_data);
+ ret = git_status_foreach_ext (_ggit_native_get (repository),
+ _ggit_status_options_get_status_options (options),
+ callback,
+ user_data);
if (ret != GIT_OK)
{
diff --git a/libgit2-glib/ggit-repository.h b/libgit2-glib/ggit-repository.h
index 80c8af3..8c5309d 100644
--- a/libgit2-glib/ggit-repository.h
+++ b/libgit2-glib/ggit-repository.h
@@ -203,6 +203,7 @@ GgitStatusFlags ggit_repository_file_status (GgitRepository *re
gboolean ggit_repository_file_status_foreach
(GgitRepository *repository,
+ GgitStatusOptions *options,
GgitStatusCallback callback,
gpointer user_data,
GError **error);
diff --git a/libgit2-glib/ggit-status-options.c b/libgit2-glib/ggit-status-options.c
new file mode 100644
index 0000000..a1d7c3c
--- /dev/null
+++ b/libgit2-glib/ggit-status-options.c
@@ -0,0 +1,121 @@
+/*
+ * ggit-status-options.c
+ * This file is part of libgit2-glib
+ *
+ * Copyright (C) 2012 - Garrett Regier
+ *
+ * libgit2-glib is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * libgit2-glib is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with libgit2-glib. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "ggit-status-options.h"
+#include "ggit-utils.h"
+
+struct _GgitStatusOptions
+{
+ git_status_options status_options;
+};
+
+G_DEFINE_BOXED_TYPE (GgitStatusOptions, ggit_status_options,
+ ggit_status_options_copy, ggit_status_options_free)
+
+const git_status_options *
+_ggit_status_options_get_status_options (GgitStatusOptions *status_options)
+{
+ /* NULL is common for status_options as it specifies to use the default
+ * so handle a NULL status_options here instead of in every caller.
+ */
+ if (status_options == NULL)
+ {
+ return NULL;
+ }
+
+ return (const git_status_options *)&status_options->status_options;
+}
+
+/**
+ * ggit_status_options_copy:
+ * @status_options: a #GgitStatusOptions.
+ *
+ * Copies @status_options into a newly allocated #GgitStatusOptions.
+ *
+ * Returns: (transfer full): a newly allocated #GgitStatusOptions.
+ */
+GgitStatusOptions *
+ggit_status_options_copy (GgitStatusOptions *status_options)
+{
+ GgitStatusOptions *new_status_options;
+
+ g_return_val_if_fail (status_options != NULL, NULL);
+
+ new_status_options = g_slice_new (GgitStatusOptions);
+
+ new_status_options->status_options = status_options->status_options;
+
+ git_strarray_copy (&new_status_options->status_options.pathspec,
+ &status_options->status_options.pathspec);
+
+ return new_status_options;
+}
+
+/**
+ * ggit_status_options_free:
+ * @status_options: a #GgitStatusOptions.
+ *
+ * Frees @status_options.
+ */
+void
+ggit_status_options_free (GgitStatusOptions *status_options)
+{
+ git_status_options *gstatus_options;
+
+ g_return_if_fail (status_options != NULL);
+
+ gstatus_options = &status_options->status_options;
+ git_strarray_free (&gstatus_options->pathspec);
+
+ g_slice_free (GgitStatusOptions, status_options);
+}
+
+/**
+ * ggit_status_options_new:
+ * @flags: status flags.
+ * @show: status show options.
+ * @pathspec: (allow-none): which paths to show, defaults to showing all paths.
+ *
+ * Creates a new #GgitStatusOptions for use in #ggit_repository_stash_foreach.
+ *
+ * Returns: a newly allocated #GgitStatusOptions.
+ */
+GgitStatusOptions *
+ggit_status_options_new (GgitStatusFlag flags,
+ GgitStatusShow show,
+ const gchar **pathspec)
+{
+ GgitStatusOptions *status_options;
+ git_status_options gstatus_options = GIT_STATUS_OPTIONS_INIT;
+
+ status_options = g_slice_new (GgitStatusOptions);
+
+ gstatus_options.flags = flags;
+ gstatus_options.show = show;
+
+ ggit_utils_get_git_strarray_from_str_array (pathspec,
+ &gstatus_options.pathspec);
+
+ status_options->status_options = gstatus_options;
+
+ return status_options;
+}
+
+/* ex:set ts=8 noet: */
diff --git a/libgit2-glib/ggit-status-options.h b/libgit2-glib/ggit-status-options.h
new file mode 100644
index 0000000..24472e4
--- /dev/null
+++ b/libgit2-glib/ggit-status-options.h
@@ -0,0 +1,52 @@
+/*
+ * ggit-status-options.h
+ * This file is part of libgit2-glib
+ *
+ * Copyright (C) 2012 - Garrett Regier
+ *
+ * libgit2-glib is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * libgit2-glib is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with libgit2-glib. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef __GGIT_STATUS_OPTIONS_H__
+#define __GGIT_STATUS_OPTIONS_H__
+
+#include <glib-object.h>
+#include <git2/strarray.h>
+#include <git2/status.h>
+
+#include "ggit-types.h"
+
+G_BEGIN_DECLS
+
+#define GGIT_TYPE_STATUS_OPTIONS (ggit_status_options_get_type ())
+#define GGIT_STATUS_OPTIONS(obj) ((GgitStatusOptions *)obj)
+
+GType ggit_status_options_get_type (void) G_GNUC_CONST;
+
+const git_status_options *
+ _ggit_status_options_get_status_options (GgitStatusOptions *status_options);
+
+GgitStatusOptions *ggit_status_options_copy (GgitStatusOptions *status_options);
+void ggit_status_options_free (GgitStatusOptions *status_options);
+
+GgitStatusOptions *ggit_status_options_new (GgitStatusFlag flags,
+ GgitStatusShow show,
+ const gchar **pathspec);
+
+G_END_DECLS
+
+#endif /* __GGIT_STATUS_OPTIONS_H__ */
+
+/* ex:set ts=8 noet: */
diff --git a/libgit2-glib/ggit-types.c b/libgit2-glib/ggit-types.c
index 096be29..d837e72 100644
--- a/libgit2-glib/ggit-types.c
+++ b/libgit2-glib/ggit-types.c
@@ -168,4 +168,18 @@ ASSERT_ENUM (GGIT_SUBMODULE_UPDATE_CHECKOUT, GIT_SUBMODULE_UPDATE_CHECKOUT);
ASSERT_ENUM (GGIT_SUBMODULE_UPDATE_REBASE, GIT_SUBMODULE_UPDATE_REBASE);
ASSERT_ENUM (GGIT_SUBMODULE_UPDATE_MERGE, GIT_SUBMODULE_UPDATE_MERGE);
+ASSERT_ENUM (GGIT_STATUS_FLAG_INCLUDE_UNTRACKED, GIT_STATUS_OPT_INCLUDE_UNTRACKED);
+ASSERT_ENUM (GGIT_STATUS_FLAG_INCLUDE_IGNORED, GIT_STATUS_OPT_INCLUDE_IGNORED);
+ASSERT_ENUM (GGIT_STATUS_FLAG_INCLUDE_UNMODIFIED, GIT_STATUS_OPT_INCLUDE_UNMODIFIED);
+ASSERT_ENUM (GGIT_STATUS_FLAG_EXCLUDE_SUBMODULES, GIT_STATUS_OPT_EXCLUDE_SUBMODULES);
+ASSERT_ENUM (GGIT_STATUS_FLAG_RECURSE_UNTRACKED_DIRS, GIT_STATUS_OPT_RECURSE_UNTRACKED_DIRS);
+ASSERT_ENUM (GGIT_STATUS_FLAG_DISABLE_PATHSPEC_MATCH, GIT_STATUS_OPT_DISABLE_PATHSPEC_MATCH);
+ASSERT_ENUM (GGIT_STATUS_FLAG_RECURSE_IGNORED_DIRS, GIT_STATUS_OPT_RECURSE_IGNORED_DIRS);
+ASSERT_ENUM (GGIT_STATUS_FLAG_DEFAULT, GIT_STATUS_OPT_DEFAULTS);
+
+ASSERT_ENUM (GGIT_STATUS_SHOW_INDEX_AND_WORKDIR, GIT_STATUS_SHOW_INDEX_AND_WORKDIR);
+ASSERT_ENUM (GGIT_STATUS_SHOW_INDEX_ONLY, GIT_STATUS_SHOW_INDEX_ONLY);
+ASSERT_ENUM (GGIT_STATUS_SHOW_WORKDIR_ONLY, GIT_STATUS_SHOW_WORKDIR_ONLY);
+ASSERT_ENUM (GGIT_STATUS_SHOW_INDEX_THEN_WORKDIR, GIT_STATUS_SHOW_INDEX_THEN_WORKDIR);
+
/* ex:set ts=8 noet: */
diff --git a/libgit2-glib/ggit-types.h b/libgit2-glib/ggit-types.h
index 92e26d2..313cff8 100644
--- a/libgit2-glib/ggit-types.h
+++ b/libgit2-glib/ggit-types.h
@@ -258,6 +258,13 @@ typedef struct _GgitRevisionWalker GgitRevisionWalker;
typedef struct _GgitSignature GgitSignature;
/**
+ * GgitStatusOptions:
+ *
+ * Represents the options used when creating getting file status.
+ */
+typedef struct _GgitStatusOptions GgitStatusOptions;
+
+/**
* GgitSubmodule:
*
* Represents a git submodule.
@@ -668,6 +675,49 @@ typedef enum {
GGIT_TREE_WALK_MODE_POST = 1,
} GgitTreeWalkMode;
+/**
+ * GgitStatusFlag:
+ * GGIT_STATUS_FLAG_INCLUDE_UNTRACKED:
+ * GGIT_STATUS_FLAG_INCLUDE_IGNORED:
+ * GGIT_STATUS_FLAG_INCLUDE_UNMODIFIED:
+ * GGIT_STATUS_FLAG_EXCLUDE_SUBMODULES:
+ * GGIT_STATUS_FLAG_RECURSE_UNTRACKED_DIRS:
+ * GGIT_STATUS_FLAG_DISABLE_PATHSPEC_MATCH:
+ * GGIT_STATUS_FLAG_RECURSE_IGNORED_DIRS:
+ * GGIT_STATUS_FLAG_SORT_CASE_SENSITIVELY:
+ * GGIT_STATUS_FLAG_SORT_CASE_INSENSITIVELY:
+ * GGIT_STATUS_FLAG_DEFAULT:
+ *
+ */
+typedef enum {
+ GGIT_STATUS_FLAG_INCLUDE_UNTRACKED = (1 << 0),
+ GGIT_STATUS_FLAG_INCLUDE_IGNORED = (1 << 1),
+ GGIT_STATUS_FLAG_INCLUDE_UNMODIFIED = (1 << 2),
+ GGIT_STATUS_FLAG_EXCLUDE_SUBMODULES = (1 << 3),
+ GGIT_STATUS_FLAG_RECURSE_UNTRACKED_DIRS = (1 << 4),
+ GGIT_STATUS_FLAG_DISABLE_PATHSPEC_MATCH = (1 << 5),
+ GGIT_STATUS_FLAG_RECURSE_IGNORED_DIRS = (1 << 6),
+ GGIT_STATUS_FLAG_SORT_CASE_SENSITIVELY = (1 << 9),
+ GGIT_STATUS_FLAG_SORT_CASE_INSENSITIVELY = (1 << 10),
+ GGIT_STATUS_FLAG_DEFAULT = GGIT_STATUS_FLAG_INCLUDE_IGNORED |
+ GGIT_STATUS_FLAG_INCLUDE_UNTRACKED |
+ GGIT_STATUS_FLAG_RECURSE_UNTRACKED_DIRS
+} GgitStatusFlag;
+
+/**
+ * GgitStatusShow:
+ * @GGIT_STATUS_SHOW_INDEX_AND_WORKDIR:
+ * @GGIT_STATUS_SHOW_INDEX_ONLY:
+ * @GGIT_STATUS_SHOW_WORKDIR_ONLY:
+ * @GGIT_STATUS_SHOW_INDEX_THEN_WORKDIR:
+ *
+ */
+typedef enum {
+ GGIT_STATUS_SHOW_INDEX_AND_WORKDIR = 0,
+ GGIT_STATUS_SHOW_INDEX_ONLY = 1,
+ GGIT_STATUS_SHOW_WORKDIR_ONLY = 2,
+ GGIT_STATUS_SHOW_INDEX_THEN_WORKDIR = 3,
+} GgitStatusShow;
/**
* GgitBranchesCallback:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]