[libgit2-glib] Fix branch binding due to once again api breaks in libgit2
- From: Ignacio Casal Quinteiro <icq src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgit2-glib] Fix branch binding due to once again api breaks in libgit2
- Date: Sat, 22 Sep 2012 11:19:50 +0000 (UTC)
commit 1a840722edd72315c84e2fc501534c769bb77fe6
Author: Ignacio Casal Quinteiro <icq gnome org>
Date: Sat Sep 22 13:19:00 2012 +0200
Fix branch binding due to once again api breaks in libgit2
libgit2-glib/Makefile.am | 2 +
libgit2-glib/ggit-branch.c | 137 ++++++++++++++++++++++++++++++++++++++++
libgit2-glib/ggit-branch.h | 71 +++++++++++++++++++++
libgit2-glib/ggit-repository.c | 110 ++++++++++++--------------------
libgit2-glib/ggit-repository.h | 19 ++----
5 files changed, 257 insertions(+), 82 deletions(-)
---
diff --git a/libgit2-glib/Makefile.am b/libgit2-glib/Makefile.am
index 9b9e3e3..409e3fb 100644
--- a/libgit2-glib/Makefile.am
+++ b/libgit2-glib/Makefile.am
@@ -16,6 +16,7 @@ libgit2_glib_1_0_la_LIBADD = $(LIBGIT2_GLIB_LIBS)
INST_H_FILES = \
ggit-blob.h \
+ ggit-branch.h \
ggit-commit.h \
ggit-config.h \
ggit-diff.h \
@@ -54,6 +55,7 @@ NOINST_H_FILES = \
C_FILES = \
ggit-blob.c \
+ ggit-branch.c \
ggit-commit.c \
ggit-config.c \
ggit-convert.c \
diff --git a/libgit2-glib/ggit-branch.c b/libgit2-glib/ggit-branch.c
new file mode 100644
index 0000000..b9a0675
--- /dev/null
+++ b/libgit2-glib/ggit-branch.c
@@ -0,0 +1,137 @@
+/*
+ * ggit-branch.c
+ * This file is part of libgit2-glib
+ *
+ * Copyright (C) 2012 - Ignacio Casal Quinteiro
+ *
+ * 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-branch.h"
+
+
+G_DEFINE_TYPE (GgitBranch, ggit_branch, GGIT_TYPE_REF)
+
+static void
+ggit_branch_class_init (GgitBranchClass *klass)
+{
+}
+
+static void
+ggit_branch_init (GgitBranch *self)
+{
+}
+
+GgitBranch *
+_ggit_branch_wrap (git_reference *ref)
+{
+ return g_object_new (GGIT_TYPE_BRANCH,
+ "native", ref,
+ NULL);
+}
+
+/**
+ * ggit_branch_delete:
+ * @branch: a #GgitBranch.
+ * @error: a #GError for error reporting, or %NULL.
+ *
+ * Deletes an existing branch reference.
+ *
+ * If the branch is successfully deleted, this object is
+ * not useful anymore and if should be freed with g_object_unref().
+ */
+void
+ggit_branch_delete (GgitBranch *branch,
+ GError **error)
+{
+ gint ret;
+
+ g_return_if_fail (GGIT_IS_BRANCH (branch));
+ g_return_if_fail (error == NULL || *error == NULL);
+
+ ret = git_branch_delete (_ggit_native_get (branch));
+
+ if (ret != GIT_OK)
+ {
+ _ggit_error_set (error, ret);
+ }
+}
+
+/**
+ * ggit_branch_move:
+ * @branch: a #GgitBranch.
+ * @new_branch_name: target name of the branch once the move is performed; this name is validated for consistency.
+ * @flags: a GgitCreateFlags.
+ * @error: a #GError for error reporting, or %NULL.
+ *
+ * Moves/renames an existing branch reference.
+ **/
+void
+ggit_branch_move (GgitBranch *branch,
+ const gchar *new_branch_name,
+ GgitCreateFlags flags,
+ GError **error)
+{
+ gboolean force;
+ gint ret;
+
+ g_return_if_fail (GGIT_IS_BRANCH (branch));
+ g_return_if_fail (new_branch_name != NULL);
+ g_return_if_fail (error == NULL || *error == NULL);
+
+ force = flags & GGIT_CREATE_FORCE;
+
+ ret = git_branch_move (_ggit_native_get (branch),
+ new_branch_name,
+ force ? 1 : 0);
+
+ if (ret != GIT_OK)
+ {
+ _ggit_error_set (error, ret);
+ }
+}
+
+/**
+ * ggit_branch_get_tracking:
+ * @branch: a #GgitBranch.
+ * @error: a #GError for error reporting, or %NULL.
+ *
+ * Gets the reference supporting the remote tracking branch,
+ * given a local branch reference.
+ *
+ * Returns: (transfer full) (allow-none): the reference supporting the remote tracking branch.
+ */
+GgitBranch *
+ggit_branch_get_tracking (GgitBranch *branch,
+ GError **error)
+{
+ gint ret;
+ git_reference *tracking;
+
+ g_return_val_if_fail (GGIT_IS_BRANCH (branch), NULL);
+ g_return_val_if_fail (error == NULL || *error == NULL, NULL);
+
+ ret = git_branch_tracking (&tracking,
+ _ggit_native_get (branch));
+
+ if (ret != GIT_OK)
+ {
+ _ggit_error_set (error, ret);
+ return NULL;
+ }
+
+ return _ggit_branch_wrap (tracking);
+}
+
+/* ex:set ts=8 noet: */
diff --git a/libgit2-glib/ggit-branch.h b/libgit2-glib/ggit-branch.h
new file mode 100644
index 0000000..fd61439
--- /dev/null
+++ b/libgit2-glib/ggit-branch.h
@@ -0,0 +1,71 @@
+/*
+ * ggit-branch.h
+ * This file is part of libgit2-glib
+ *
+ * Copyright (C) 2012 - Ignacio Casal Quinteiro
+ *
+ * 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_BRANCH_H__
+#define __GGIT_BRANCH_H__
+
+#include <libgit2-glib/ggit-ref.h>
+
+G_BEGIN_DECLS
+
+#define GGIT_TYPE_BRANCH (ggit_branch_get_type ())
+#define GGIT_BRANCH(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GGIT_TYPE_BRANCH, GgitBranch))
+#define GGIT_BRANCH_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GGIT_TYPE_BRANCH, GgitBranch const))
+#define GGIT_BRANCH_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GGIT_TYPE_BRANCH, GgitBranchClass))
+#define GGIT_IS_BRANCH(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GGIT_TYPE_BRANCH))
+#define GGIT_IS_BRANCH_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GGIT_TYPE_BRANCH))
+#define GGIT_BRANCH_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GGIT_TYPE_BRANCH, GgitBranchClass))
+
+typedef struct _GgitBranch GgitBranch;
+typedef struct _GgitBranchClass GgitBranchClass;
+typedef struct _GgitBranchPrivate GgitBranchPrivate;
+
+struct _GgitBranch
+{
+ GgitRef parent;
+
+ gpointer *_priv;
+};
+
+struct _GgitBranchClass
+{
+ GgitRefClass parent_class;
+};
+
+GType ggit_branch_get_type (void) G_GNUC_CONST;
+
+GgitBranch *_ggit_branch_wrap (git_reference *ref);
+
+void ggit_branch_delete (GgitBranch *branch,
+ GError **error);
+
+void ggit_branch_move (GgitBranch *branch,
+ const gchar *new_branch_name,
+ GgitCreateFlags flags,
+ GError **error);
+
+GgitBranch *ggit_branch_get_tracking (GgitBranch *branch,
+ GError **error);
+
+G_END_DECLS
+
+#endif /* __GGIT_BRANCH_H__ */
+
+/* ex:set ts=8 noet: */
diff --git a/libgit2-glib/ggit-repository.c b/libgit2-glib/ggit-repository.c
index 820fcfb..c4ee28f 100644
--- a/libgit2-glib/ggit-repository.c
+++ b/libgit2-glib/ggit-repository.c
@@ -1270,7 +1270,7 @@ ggit_repository_list_tags (GgitRepository *repository,
* Returns: (transfer full) (allow-none): the reference to which the branch
* points, or %NULL in case of an error.
**/
-GgitRef *
+GgitBranch *
ggit_repository_create_branch (GgitRepository *repository,
const gchar *branch_name,
GgitObject *target,
@@ -1300,75 +1300,7 @@ ggit_repository_create_branch (GgitRepository *repository,
return NULL;
}
- return _ggit_ref_wrap (reference);
-}
-
-/**
- * ggit_repository_delete_branch:
- * @repository: a #GgitRepository.
- * @branch_name: the name of the branch.
- * @branch_type: a #GgitBranchType.
- * @error: a #GError.
- *
- * Deletes an existing branch reference.
- **/
-void
-ggit_repository_delete_branch (GgitRepository *repository,
- const gchar *branch_name,
- GgitBranchType branch_type,
- GError **error)
-{
- gint ret;
-
- g_return_if_fail (GGIT_IS_REPOSITORY (repository));
- g_return_if_fail (branch_name != NULL);
- g_return_if_fail (error == NULL || *error == NULL);
-
- ret = git_branch_delete (_ggit_native_get (repository),
- branch_name,
- branch_type);
-
- if (ret != GIT_OK)
- {
- _ggit_error_set (error, ret);
- }
-}
-
-/**
- * ggit_repository_move_branch:
- * @repository: a #GgitRepository.
- * @branch: the #GgitRef for the branch.
- * @new_branch_name: the new name of the branch.
- * @flags: a GgitCreateFlags.
- * @error: a #GError.
- *
- * Moves/renames an existing branch reference.
- **/
-void
-ggit_repository_move_branch (GgitRepository *repository,
- GgitRef *branch,
- const gchar *new_branch_name,
- GgitCreateFlags flags,
- GError **error)
-{
- gboolean force;
- gint ret;
-
- g_return_if_fail (GGIT_IS_REPOSITORY (repository));
- g_return_if_fail (GGIT_IS_REF (branch));
- g_return_if_fail (new_branch_name != NULL);
- g_return_if_fail (error == NULL || *error == NULL);
-
- force = flags & GGIT_CREATE_FORCE;
-
- ret = git_branch_move (_ggit_native_get (branch),
- new_branch_name,
- force ? 1 : 0);
-
- if (ret != GIT_OK)
- {
- _ggit_error_set (error, ret);
- }
+ return _ggit_branch_wrap (reference);
}
typedef gint (* _GitBranchesCallback) (const gchar *branch_name,
@@ -1410,6 +1342,44 @@ ggit_repository_branches_foreach (GgitRepository *repository,
}
/**
+ * ggit_repository_lookup_branch:
+ * @repository: a #GgitRepository.
+ * @branch_name: the name of the branch.
+ * @branch_type: a #GgitBranchType.
+ * @error: a #GError for error reporting, or %NULL.
+ *
+ * Lookups a branch by its name in a repository.
+ *
+ * Returns: (transfer full) (allow-none): a branch by its name in a repository.
+ */
+GgitBranch *
+ggit_repository_lookup_branch (GgitRepository *repository,
+ const gchar *branch_name,
+ GgitBranchType branch_type,
+ GError **error)
+{
+ gint ret;
+ git_reference *branch;
+
+ g_return_val_if_fail (GGIT_IS_REPOSITORY (repository), FALSE);
+ g_return_val_if_fail (branch_name != NULL, FALSE);
+ g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+ ret = git_branch_lookup (&branch,
+ _ggit_native_get (repository),
+ branch_name,
+ branch_type);
+
+ if (ret != GIT_OK)
+ {
+ _ggit_error_set (error, ret);
+ return NULL;
+ }
+
+ return _ggit_branch_wrap (branch);
+}
+
+/**
* ggit_repository_get_remote:
* @repository: a #GgitRepository.
* @name: the remote's name.
diff --git a/libgit2-glib/ggit-repository.h b/libgit2-glib/ggit-repository.h
index 5a20f75..fe1dfa8 100644
--- a/libgit2-glib/ggit-repository.h
+++ b/libgit2-glib/ggit-repository.h
@@ -31,6 +31,7 @@
#include <libgit2-glib/ggit-native.h>
#include <libgit2-glib/ggit-object.h>
#include <libgit2-glib/ggit-tree.h>
+#include <libgit2-glib/ggit-branch.h>
G_BEGIN_DECLS
@@ -120,29 +121,23 @@ GgitOId *ggit_repository_create_tag_lightweight (
gchar **ggit_repository_list_tags (GgitRepository *repository,
GError **error);
-GgitRef *ggit_repository_create_branch (GgitRepository *repository,
+GgitBranch *ggit_repository_create_branch (GgitRepository *repository,
const gchar *branch_name,
GgitObject *target,
GgitCreateFlags flags,
GError **error);
-void ggit_repository_delete_branch (GgitRepository *repository,
- const gchar *branch_name,
- GgitBranchType branch_type,
- GError **error);
-
-void ggit_repository_move_branch (GgitRepository *repository,
- GgitRef *branch,
- const gchar *new_branch_name,
- GgitCreateFlags flags,
- GError **error);
-
void ggit_repository_branches_foreach (GgitRepository *repository,
GgitBranchType branch_type,
GgitBranchesCallback callback,
gpointer user_data,
GError **error);
+GgitBranch *ggit_repository_lookup_branch (GgitRepository *repository,
+ const gchar *branch_name,
+ GgitBranchType branch_type,
+ GError **error);
+
GgitRemote *ggit_repository_get_remote (GgitRepository *repository,
const gchar *name,
GError **error);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]