[libgit2-glib] Added bindings for blame options
- From: Jesse van den Kieboom <jessevdk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgit2-glib] Added bindings for blame options
- Date: Mon, 25 Nov 2013 10:58:32 +0000 (UTC)
commit c211b7114a45ff8d44669bf0dd8670305f543dfd
Author: Jesse van den Kieboom <jessevdk gmail com>
Date: Mon Nov 25 11:58:03 2013 +0100
Added bindings for blame options
libgit2-glib/Makefile.am | 2 +
libgit2-glib/ggit-blame-options.c | 367 +++++++++++++++++++++++++++++++++++++
libgit2-glib/ggit-blame-options.h | 75 ++++++++
libgit2-glib/ggit-types.c | 3 +
libgit2-glib/ggit-types.h | 20 ++
5 files changed, 467 insertions(+), 0 deletions(-)
---
diff --git a/libgit2-glib/Makefile.am b/libgit2-glib/Makefile.am
index ee11732..4173b1a 100644
--- a/libgit2-glib/Makefile.am
+++ b/libgit2-glib/Makefile.am
@@ -18,6 +18,7 @@ libgit2_glib_1_0_la_LDFLAGS = \
libgit2_glib_1_0_la_LIBADD = $(LIBGIT2_GLIB_LIBS)
INST_H_FILES = \
+ ggit-blame-options.h \
ggit-blob.h \
ggit-blob-output-stream.h \
ggit-branch.h \
@@ -73,6 +74,7 @@ NOINST_H_FILES = \
ggit-utils.h
C_FILES = \
+ ggit-blame-options.c \
ggit-blob.c \
ggit-blob-output-stream.c \
ggit-branch.c \
diff --git a/libgit2-glib/ggit-blame-options.c b/libgit2-glib/ggit-blame-options.c
new file mode 100644
index 0000000..66cf376
--- /dev/null
+++ b/libgit2-glib/ggit-blame-options.c
@@ -0,0 +1,367 @@
+/*
+ * ggit-blame-options.h
+ * This file is part of libgit2-glib
+ *
+ * Copyright (C) 2013 - Jesse van den Kieboom
+ *
+ * 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-blame-options.h"
+#include "ggit-oid.h"
+
+struct _GgitBlameOptions
+{
+ git_blame_options blame_options;
+};
+
+G_DEFINE_BOXED_TYPE (GgitBlameOptions, ggit_blame_options,
+ ggit_blame_options_copy, ggit_blame_options_free);
+
+const git_blame_options *
+_ggit_blame_options_get_blame_options (GgitBlameOptions *blame_options)
+{
+ /* NULL is common for blame_options as it specifies to use the default
+ * so handle a NULL blame_options here instead of in every caller.
+ */
+ if (blame_options == NULL)
+ {
+ return NULL;
+ }
+
+ return (const git_blame_options *)&blame_options->blame_options;
+}
+
+/**
+ * ggit_blame_options_copy:
+ * @blame_options: a #GgitBlameOptions.
+ *
+ * Copies @blame_options into a newly allocated #GgitBlameOptions.
+ *
+ * Returns: (transfer full): a newly allocated #GgitBlameOptions.
+ */
+GgitBlameOptions *
+ggit_blame_options_copy (GgitBlameOptions *blame_options)
+{
+ GgitBlameOptions *ret;
+
+ g_return_val_if_fail (blame_options != NULL, NULL);
+
+ ret = g_slice_new (GgitBlameOptions);
+ ret->blame_options = blame_options->blame_options;
+
+ return ret;
+}
+
+/**
+ * ggit_blame_options_free:
+ * @blame_options: a #GgitBlameOptions.
+ *
+ * Frees @blame_options.
+ */
+void
+ggit_blame_options_free (GgitBlameOptions *blame_options)
+{
+ g_return_if_fail (blame_options != NULL);
+
+ g_slice_free (GgitBlameOptions, blame_options);
+}
+
+/**
+ * ggit_blame_options_new:
+ *
+ * Create a new, empty #GgitBlameOptions.
+ *
+ * Returns: (transfer full): a newly allocated #GgitBlameOptions.
+ */
+GgitBlameOptions *
+ggit_blame_options_new (void)
+{
+ GgitBlameOptions *ret;
+ git_blame_options gblame_options = GIT_BLAME_OPTIONS_INIT;
+
+ ret = g_slice_new (GgitBlameOptions);
+ ret->blame_options = gblame_options;
+
+ return ret;
+}
+
+/**
+ * ggit_blame_get_flags:
+ * @blame_options: a #GgitBlameOptions.
+ *
+ * Get the blame options flags.
+ *
+ * Returns: a #GgitBlameFlags.
+ *
+ **/
+GgitBlameFlags
+ggit_blame_get_flags (GgitBlameOptions *blame_options)
+{
+ g_return_val_if_fail (blame_options != NULL, GGIT_BLAME_NORMAL);
+
+ return (GgitBlameFlags)blame_options->blame_options.flags;
+}
+
+/**
+ * ggit_blame_set_flags:
+ * @blame_options: a #GgitBlameOptions.
+ * @flags: a #GgitBlameFlags.
+ *
+ * Set the blame options flags.
+ *
+ **/
+void
+ggit_blame_set_flags (GgitBlameOptions *blame_options,
+ GgitBlameFlags flags)
+{
+ g_return_if_fail (blame_options != NULL);
+
+ blame_options->blame_options.flags = (uint32_t)flags;
+}
+
+/**
+ * ggit_blame_options_get_newest_commit:
+ * @blame_options: a #GgitBlameOptions.
+ *
+ * Get the id of the newest commit to consider in the blame. The default
+ * value of %NULL indicates to use HEAD.
+ *
+ * Returns: (transfer full): a #GgitOId or %NULL.
+ *
+ **/
+GgitOId *
+ggit_blame_options_get_newest_commit (GgitBlameOptions *blame_options)
+{
+ g_return_val_if_fail (blame_options != NULL, NULL);
+
+ if (git_oid_iszero (&blame_options->blame_options.newest_commit))
+ {
+ return NULL;
+ }
+ else
+ {
+ return _ggit_oid_wrap (&blame_options->blame_options.newest_commit);
+ }
+}
+
+/**
+ * ggit_blame_options_set_newest_commit:
+ * @blame_options: a #GgitBlameOptions.
+ * @oid: (allow-none): a #GgitOId or %NULL.
+ *
+ * Set the id of the newest commit to consider in the blame. Specify %NULL to
+ * set the default value which indicates to use HEAD.
+ *
+ **/
+void
+ggit_blame_options_set_newest_commit (GgitBlameOptions *blame_options,
+ GgitOId *oid)
+{
+ git_oid zero = {{0,}};
+
+ g_return_if_fail (blame_options != NULL);
+
+ if (oid == NULL)
+ {
+ blame_options->blame_options.newest_commit = zero;
+ }
+ else
+ {
+ blame_options->blame_options.newest_commit = *_ggit_oid_get_oid (oid);
+ }
+}
+
+/**
+ * ggit_blame_options_get_oldest_commit:
+ * @blame_options: a #GgitBlameOptions.
+ *
+ * Get the id of the oldest commit to consider in the blame. Teh default value
+ * of %NULL indicates to used HEAD.
+ *
+ * Returns: (transfer full): a #GgitOId.
+ *
+ **/
+GgitOId *
+ggit_blame_options_get_oldest_commit (GgitBlameOptions *blame_options)
+{
+ g_return_val_if_fail (blame_options != NULL, NULL);
+
+ if (git_oid_iszero (&blame_options->blame_options.oldest_commit))
+ {
+ return NULL;
+ }
+ else
+ {
+ return _ggit_oid_wrap (&blame_options->blame_options.oldest_commit);
+ }
+}
+
+/**
+ * ggit_blame_options_set_oldest_commit:
+ * @blame_options: a #GgitBlameOptions.
+ * @oid: (allow-none): a #GgitOId.
+ *
+ * Set the id of the oldest commit to consider in the blame. Specify %NULL to
+ * set the default value which indicates to consider the first commit without
+ * a parent.
+ *
+ **/
+void
+ggit_blame_options_set_oldest_commit (GgitBlameOptions *blame_options,
+ GgitOId *oid)
+{
+ git_oid zero = {{0,}};
+
+ g_return_if_fail (blame_options != NULL);
+
+ if (oid == NULL)
+ {
+ blame_options->blame_options.oldest_commit = zero;
+ }
+ else
+ {
+ blame_options->blame_options.oldest_commit = *_ggit_oid_get_oid (oid);
+ }
+}
+
+/**
+ * ggit_blame_options_get_minimum_line:
+ * @blame_options: a #GgitBlameOptions.
+ *
+ * Get the first line in the file to consider. The default is 1.
+ *
+ * Returns: the first line to consider.
+ *
+ **/
+guint32
+ggit_blame_options_get_minimum_line (GgitBlameOptions *blame_options)
+{
+ g_return_val_if_fail (blame_options != NULL, 0);
+
+ if (blame_options->blame_options.min_line == 0)
+ {
+ return 1;
+ }
+ else
+ {
+ return blame_options->blame_options.min_line;
+ }
+}
+
+/**
+ * ggit_blame_options_set_minimum_line:
+ * @blame_options: a #GgitBlameOptions.
+ * @line: the first line to consider.
+ *
+ * Set the first line in the file to consider. Lines start at 1.
+ *
+ **/
+void
+ggit_blame_options_set_minimum_line (GgitBlameOptions *blame_options,
+ guint32 line)
+{
+ g_return_if_fail (blame_options != NULL);
+
+ blame_options->blame_options.min_line = line;
+}
+
+/**
+ * ggit_blame_options_get_maximum_line:
+ * @blame_options: a #GgitBlameOptions.
+ *
+ * Get the last line in the file to consider. The default is 1.
+ *
+ * Returns: the last line to consider.
+ *
+ **/
+guint32
+ggit_blame_options_get_maximum_line (GgitBlameOptions *blame_options)
+{
+ g_return_val_if_fail (blame_options != NULL, 0);
+
+ if (blame_options->blame_options.max_line == 0)
+ {
+ return 1;
+ }
+ else
+ {
+ return blame_options->blame_options.max_line;
+ }
+}
+
+/**
+ * ggit_blame_options_set_maximum_line:
+ * @blame_options: a #GgitBlameOptions.
+ * @line: the last line to consider.
+ *
+ * Set the last line in the file to consider. Lines start at 1.
+ *
+ **/
+
+void
+ggit_blame_options_set_maximum_line (GgitBlameOptions *blame_options,
+ guint32 line)
+{
+ g_return_if_fail (blame_options != NULL);
+
+ blame_options->blame_options.max_line = line;
+}
+
+/**
+ * ggit_blame_options_get_minimum_match_characters:
+ * @blame_options: a #GgitBlameOptions.
+ *
+ * Get the minimum number of characters that must be detected as moving/copying
+ * within a file for it to associate those lines with a parent commit. This is
+ * only used when any of the #GGIT_BLAME_TRACK_COPIES_SAME_FILE flag is
+ * specified. The default value is 20.
+ *
+ * Returns: the minimum number of characters.
+ *
+ **/
+guint16
+ggit_blame_options_get_minimum_match_characters (GgitBlameOptions *blame_options)
+{
+ g_return_val_if_fail (blame_options != NULL, 0);
+
+ if (blame_options->blame_options.min_match_characters == 0)
+ {
+ return 20;
+ }
+ else
+ {
+ return blame_options->blame_options.min_match_characters;
+ }
+}
+
+/**
+ * ggit_blame_options_set_minimum_match_characters:
+ * @blame_options: a #GgitBlameOptions.
+ * @characters: the minimum number of characters.
+ *
+ * Set the minimum number of characters that must be detected as moving/copying
+ * within a file for it to associate those lines with a parent commit. This is
+ * only used when any of the #GGIT_BLAME_TRACK_COPIES_ flags are specified. The
+ * default value is 20.
+ *
+ **/
+void
+ggit_blame_options_set_minimum_match_characters (GgitBlameOptions *blame_options,
+ guint16 characters)
+{
+ g_return_if_fail (blame_options != NULL);
+ blame_options->blame_options.min_match_characters = characters;
+}
+
diff --git a/libgit2-glib/ggit-blame-options.h b/libgit2-glib/ggit-blame-options.h
new file mode 100644
index 0000000..c9f6b09
--- /dev/null
+++ b/libgit2-glib/ggit-blame-options.h
@@ -0,0 +1,75 @@
+/*
+ * ggit-blame-options.h
+ * This file is part of libgit2-glib
+ *
+ * Copyright (C) 2013 - Jesse van den Kieboom
+ *
+ * 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_BLAME_OPTIONS_H__
+#define __GGIT_BLAME_OPTIONS_H__
+
+#include <glib-object.h>
+#include <git2.h>
+
+#include <libgit2-glib/ggit-types.h>
+
+G_BEGIN_DECLS
+
+#define GGIT_TYPE_BLAME_OPTIONS (ggit_blame_options_get_type ())
+#define GGIT_BLAME_OPTIONS(obj) ((GgitBlameOptions *)obj)
+
+GType ggit_blame_options_get_type (void) G_GNUC_CONST;
+
+const git_blame_options *
+ _ggit_blame_options_get_blame_options (GgitBlameOptions *blame_options);
+
+GgitBlameOptions *ggit_blame_options_copy (GgitBlameOptions *blame_options);
+void ggit_blame_options_free (GgitBlameOptions *blame_options);
+
+GgitBlameOptions *ggit_blame_options_new (void);
+
+GgitBlameFlags ggit_blame_get_flags (GgitBlameOptions *blame_options);
+void ggit_blame_set_flags (GgitBlameOptions *blame_options,
+ GgitBlameFlags flags);
+
+GgitOId *ggit_blame_options_get_newest_commit (GgitBlameOptions *blame_options);
+void ggit_blame_options_set_newest_commit (GgitBlameOptions *blame_options,
+ GgitOId *oid);
+
+GgitOId *ggit_blame_options_get_oldest_commit (GgitBlameOptions *blame_options);
+void ggit_blame_options_set_oldest_commit (GgitBlameOptions *blame_options,
+ GgitOId *oid);
+
+guint32 ggit_blame_options_get_minimum_line (GgitBlameOptions *blame_options);
+void ggit_blame_options_set_minimum_line (GgitBlameOptions *blame_options,
+ guint32 line);
+
+guint32 ggit_blame_options_get_maximum_line (GgitBlameOptions *blame_options);
+void ggit_blame_options_set_maximum_line (GgitBlameOptions *blame_options,
+ guint32 line);
+
+guint16 ggit_blame_options_get_minimum_match_characters
+ (GgitBlameOptions *blame_options);
+
+void ggit_blame_options_set_minimum_match_characters
+ (GgitBlameOptions *blame_options,
+ guint16 characters);
+
+G_END_DECLS
+
+#endif /* __GGIT_BLAME_OPTIONS_H__ */
+
+/* ex:set ts=8 noet: */
diff --git a/libgit2-glib/ggit-types.c b/libgit2-glib/ggit-types.c
index 0788ff7..117fd39 100644
--- a/libgit2-glib/ggit-types.c
+++ b/libgit2-glib/ggit-types.c
@@ -206,4 +206,7 @@ ASSERT_ENUM (GGIT_STATUS_SHOW_INDEX_AND_WORKDIR, GIT_STATUS_SHOW_INDEX_AND_WORKD
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_BLAME_NORMAL, GIT_BLAME_NORMAL);
+ASSERT_ENUM (GGIT_BLAME_TRACK_COPIES_SAME_FILE, GIT_BLAME_TRACK_COPIES_SAME_FILE);
+
/* ex:set ts=8 noet: */
diff --git a/libgit2-glib/ggit-types.h b/libgit2-glib/ggit-types.h
index e1d8361..7072206 100644
--- a/libgit2-glib/ggit-types.h
+++ b/libgit2-glib/ggit-types.h
@@ -363,6 +363,13 @@ typedef struct _GgitTreeEntry GgitTreeEntry;
typedef struct _GgitTreeBuilder GgitTreeBuilder;
/**
+ * GgitBlameOptions:
+ *
+ * Represents blame options.
+ */
+typedef struct _GgitBlameOptions GgitBlameOptions;
+
+/**
* GgitBranchType:
* @GGIT_BRANCH_LOCAL: specifies a local branch.
* @GGIT_BRANCH_REMOTE: specifies a remote branch.
@@ -381,6 +388,19 @@ typedef enum
GGIT_CAP_HTTPS = 1 << 1
} GgitCapFlags;
+
+/**
+ * GgitBlameFlags:
+ * @GGIT_BLAME_NORMAL: Normal blame, the default.
+ * @GGIT_BLAME_TRACK_COPIES_SAME_FILE: Track lines that have moved within a file
+ * (like git blame -M)
+ */
+typedef enum
+{
+ GGIT_BLAME_NORMAL = 0,
+ GGIT_BLAME_TRACK_COPIES_SAME_FILE = 1 << 0,
+} GgitBlameFlags;
+
/**
* GgitConfigLevel:
* @GGIT_CONFIG_LEVEL_SYSTEM: System-wide configuration file.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]