[libgit2-glib] More completeness in the submodules
- From: Ignacio Casal Quinteiro <icq src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgit2-glib] More completeness in the submodules
- Date: Tue, 16 Oct 2012 12:53:08 +0000 (UTC)
commit ab3e15eeb11716764d76f2ba4bf50114245ed070
Author: Ignacio Casal Quinteiro <icq gnome org>
Date: Tue Oct 16 14:52:45 2012 +0200
More completeness in the submodules
libgit2-glib/ggit-submodule.c | 329 ++++++++++++++++++++++++++++++++++++++++-
libgit2-glib/ggit-submodule.h | 37 +++++-
libgit2-glib/ggit-types.c | 7 +
libgit2-glib/ggit-types.h | 20 +++-
4 files changed, 384 insertions(+), 9 deletions(-)
---
diff --git a/libgit2-glib/ggit-submodule.c b/libgit2-glib/ggit-submodule.c
index dc4d2f3..979a5ff 100644
--- a/libgit2-glib/ggit-submodule.c
+++ b/libgit2-glib/ggit-submodule.c
@@ -20,6 +20,10 @@
#include "ggit-submodule.h"
#include "ggit-oid.h"
+#include "ggit-repository.h"
+#include "ggit-error.h"
+
+#include <git2/errors.h>
struct _GgitSubmodule
@@ -80,6 +84,52 @@ ggit_submodule_unref (GgitSubmodule *submodule)
}
/**
+ * ggit_submodule_save:
+ * @submodule: a #GgitSubmodule.
+ * @error: a #GError for error reporting, or %NULL.
+ *
+ * Writes submodule settings to .gitmodules file.
+ * Commits any in-memory changes to the submodule to the gitmodules
+ * file on disk. You may also be interested in ggit_submodule_init() which
+ * writes submodule info to ".git/config" (which is better for local changes
+ * to submodule settings) and/or ggit_submodule_sync() which writes
+ * settings about remotes to the actual submodule repository.
+ */
+void
+ggit_submodule_save (GgitSubmodule *submodule,
+ GError **error)
+{
+ gint ret;
+
+ g_return_if_fail (submodule != NULL);
+ g_return_if_fail (error == NULL || *error == NULL);
+
+ ret = git_submodule_save (submodule->submodule);
+
+ if (ret != GIT_OK)
+ {
+ _ggit_error_set (error, ret);
+ }
+}
+
+/**
+ * ggit_submodule_get_owner:
+ * @submodule: a #GgitSubmodule
+ *
+ * Gets the containing repository for a submodule.
+ *
+ * Returns: (transfer full): the containing repository for a submodule.
+ */
+GgitRepository *
+ggit_submodule_get_owner (GgitSubmodule *submodule)
+{
+ g_return_val_if_fail (submodule != NULL, NULL);
+
+ return _ggit_repository_wrap (git_submodule_owner (submodule->submodule),
+ FALSE);
+}
+
+/**
* ggit_submodule_get_name:
* @submodule: a #GgitSubmodule.
*
@@ -131,6 +181,40 @@ ggit_submodule_get_url (GgitSubmodule *submodule)
}
/**
+ * ggit_submodule_set_url:
+ * @submodule: a #GgitSubmodule.
+ * @url: URL that should be used for the submodule.
+ * @error: a #GError for error reporting, or %NULL.
+ *
+ * Sets the URL for the submodule.
+ *
+ * This sets the URL in memory for the submodule. This will be used for
+ * any following submodule actions while this submodule data is in memory.
+ *
+ * After calling this, you may wish to call ggit_submodule_save() to write
+ * the changes back to the ".gitmodules" file and ggit_submodule_sync() to
+ * write the changes to the checked out submodule repository.
+ */
+void
+ggit_submodule_set_url (GgitSubmodule *submodule,
+ const gchar *url,
+ GError **error)
+{
+ gint ret;
+
+ g_return_if_fail (submodule != NULL);
+ g_return_if_fail (error == NULL || *error == NULL);
+
+ ret = git_submodule_set_url (submodule->submodule,
+ url);
+
+ if (ret != GIT_OK)
+ {
+ _ggit_error_set (error, ret);
+ }
+}
+
+/**
* ggit_submodule_get_index_oid:
* @submodule: a #GgitSubmodule.
*
@@ -154,6 +238,97 @@ ggit_submodule_get_index_oid (GgitSubmodule *submodule)
}
/**
+ * ggit_submodule_get_head_oid:
+ * @submodule: a #GgitSubmodule.
+ *
+ * Gets the OID for the submodule in the current HEAD tree.
+ *
+ * Returns: (transfer full) (allow-none): the OID for the submodule in the current HEAD tree or %NULL.
+ */
+GgitOId *
+ggit_submodule_get_head_oid (GgitSubmodule *submodule)
+{
+ GgitOId *oid = NULL;
+
+ g_return_val_if_fail (submodule != NULL, NULL);
+
+ if (git_submodule_head_oid (submodule->submodule))
+ {
+ oid = _ggit_oid_new (git_submodule_head_oid (submodule->submodule));
+ }
+
+ return oid;
+}
+
+/**
+ * ggit_submodule_get_workdir_oid:
+ * @submodule: a #GgitSubmodule.
+ *
+ * Gets the OID for the submodule in the current working directory.
+ * Corresponds to looking up 'HEAD' in the checked out submodule.
+ * If there are pending changes in the index or anything
+ * else, this won't notice that. You should call ggit_submodule_status()
+ * for a more complete picture about the state of the working directory.
+ *
+ * Returns: (transfer full) (allow-none): the OID for the submodule in the current working directory or %NULL.
+ */
+GgitOId *
+ggit_submodule_get_workdir_oid (GgitSubmodule *submodule)
+{
+ GgitOId *oid = NULL;
+
+ g_return_val_if_fail (submodule != NULL, NULL);
+
+ if (git_submodule_wd_oid (submodule->submodule))
+ {
+ oid = _ggit_oid_new (git_submodule_wd_oid (submodule->submodule));
+ }
+
+ return oid;
+}
+
+/**
+ * ggit_submodule_get_ignore:
+ * @submodule: a #GgitSubmodule.
+ *
+ * Gets a #GgitSubmoduleIgnore. See see gitmodules(5) ignore.
+ *
+ * Returns: the #GgitSubmoduleIgnore.
+ */
+GgitSubmoduleIgnore
+ggit_submodule_get_ignore (GgitSubmodule *submodule)
+{
+ g_return_val_if_fail (submodule != NULL, 0);
+
+ return git_submodule_ignore (submodule->submodule);
+}
+
+/**
+ * ggit_submodule_set_ignore:
+ * @submodule: a #GgitSubmodule.
+ * @ignore: a #GgitSubmoduleIgnore.
+ *
+ * Sets the ignore rule in memory for the submodule. This will be used
+ * for any following actions (such as ggit_submodule_status()) while the
+ * submodule is in memory. You should call ggit_submodule_save() if you
+ * want to persist the new ignore role.
+ *
+ * Calling this again with GGIT_SUBMODULE_IGNORE_DEFAULT or calling
+ * ggit_submodule_reload() will revert the rule to the value that was in the
+ * original config.
+ *
+ * Returns: the old #GgitSubmoduleIgnore.
+ */
+GgitSubmoduleIgnore
+ggit_submodule_set_ignore (GgitSubmodule *submodule,
+ GgitSubmoduleIgnore ignore)
+{
+ g_return_val_if_fail (submodule != NULL, 0);
+
+ return git_submodule_set_ignore (submodule->submodule, ignore);
+}
+
+/**
* ggit_submodule_get_update:
* @submodule: a #GgitSubmodule.
*
@@ -170,19 +345,26 @@ ggit_submodule_get_update (GgitSubmodule *submodule)
}
/**
- * ggit_submodule_get_ignore:
+ * ggit_submodule_set_update:
* @submodule: a #GgitSubmodule.
+ * @update: a #GgitSubmoduleUpdate.
*
- * Gets a #GgitSubmoduleIgnore. See see gitmodules(5) ignore.
+ * Sets the update rule in memory for the submodule. You should call
+ * ggit_submodule_save() if you want to persist the new update rule.
*
- * Returns: the #GgitSubmoduleIgnore.
+ * Calling this again with GGIT_SUBMODULE_UPDATE_DEFAULT or calling
+ * ggit_submodule_reload() will revert the rule to the value that was in the
+ * original config.
+ *
+ * Returns: the old #GgitSubmoduleUpdate.
*/
-GgitSubmoduleIgnore
-ggit_submodule_get_ignore (GgitSubmodule *submodule)
+GgitSubmoduleUpdate
+ggit_submodule_set_update (GgitSubmodule *submodule,
+ GgitSubmoduleUpdate update)
{
g_return_val_if_fail (submodule != NULL, 0);
- return git_submodule_ignore (submodule->submodule);
+ return git_submodule_set_update (submodule->submodule, update);
}
/**
@@ -201,4 +383,139 @@ ggit_submodule_get_fetch_recurse (GgitSubmodule *submodule)
return git_submodule_fetch_recurse_submodules (submodule->submodule);
}
+/**
+ * ggit_submodule_set_fetch_recurse:
+ * @submodule: a #GgitSubmodule.
+ * @fetch_recurse: %TRUE to fetch recurse submodules.
+ *
+ * Sets the submodule.<name>.fetchRecurseSubmodules value for
+ * the submodule. You should call ggit_submodule_save() if you want
+ * to persist the new value.
+ *
+ * Returns: the old value.
+ */
+gboolean
+ggit_submodule_set_fetch_recurse (GgitSubmodule *submodule,
+ gboolean fetch_recurse)
+{
+ g_return_val_if_fail (submodule != NULL, FALSE);
+
+ return git_submodule_set_fetch_recurse_submodules (submodule->submodule, fetch_recurse);
+}
+
+/**
+ * ggit_submodule_init:
+ * @submodule: a #GgitSubmodule.
+ * @overwrite: forces existing entries to be updated.
+ * @error: a #GError for error reporting, or %NULL.
+ *
+ * Just like "git submodule init", this copies information about the
+ * submodule into ".git/config". You can use the accessor functions
+ * above to alter the in-memory git_submodule object and control what
+ * is written to the config, overriding what is in .gitmodules.
+ */
+void
+ggit_submodule_init (GgitSubmodule *submodule,
+ gboolean overwrite,
+ GError **error)
+{
+ gint ret;
+
+ g_return_if_fail (submodule != NULL);
+ g_return_if_fail (error == NULL || *error == NULL);
+
+ ret = git_submodule_init (submodule->submodule, overwrite);
+
+ if (ret != GIT_OK)
+ {
+ _ggit_error_set (error, ret);
+ }
+}
+
+/**
+ * ggit_submodule_sync:
+ * @submodule: a #GgitSubmodule.
+ * @error: a #GError for error reporting, or %NULL.
+ *
+ * Copies the information about the submodules URL into the checked out
+ * submodule config, acting like "git submodule sync". This is useful if
+ * you have altered the URL for the submodule (or it has been altered by a
+ * fetch of upstream changes) and you need to update your local repo.
+ */
+void
+ggit_submodule_sync (GgitSubmodule *submodule,
+ GError **error)
+{
+ gint ret;
+
+ g_return_if_fail (submodule != NULL);
+ g_return_if_fail (error == NULL || *error == NULL);
+
+ ret = git_submodule_sync (submodule->submodule);
+
+ if (ret != GIT_OK)
+ {
+ _ggit_error_set (error, ret);
+ }
+}
+
+/**
+ * ggit_submodule_reload:
+ * @submodule: a #GgitSubmodule.
+ * @error: a #GError for error reporting, or %NULL.
+ *
+ * Rereads submodule info from config, index, and HEAD.
+ * Call this if you have reason to believe that it has changed.
+ */
+void
+ggit_submodule_reload (GgitSubmodule *submodule,
+ GError **error)
+{
+ gint ret;
+
+ g_return_if_fail (submodule != NULL);
+ g_return_if_fail (error == NULL || *error == NULL);
+
+ ret = git_submodule_reload (submodule->submodule);
+
+ if (ret != GIT_OK)
+ {
+ _ggit_error_set (error, ret);
+ }
+}
+
+/**
+ * ggit_submodule_get_status:
+ * @submodule: a #GgitSubmodule.
+ * @error: a #GError for error reporting, or %NULL.
+ *
+ * Gets the status for a submodule.
+ * This looks at a submodule and tries to determine the status. It
+ * will return a combination of the `GGIT_SUBMODULE_STATUS` values.
+ * How deeply it examines the working directory to do this will depend
+ * on the #GgitSubmoduleIgnore value for the submodule - which can be
+ * set either temporarily or permanently with ggit_submodule_set_ignore().
+ *
+ * Returns: the #GgitSubmoduleStatus for @submodule.
+ */
+GgitSubmoduleStatus
+ggit_submodule_get_status (GgitSubmodule *submodule,
+ GError **error)
+{
+ gint ret;
+ GgitSubmoduleStatus status;
+
+ g_return_val_if_fail (submodule != NULL, 0);
+ g_return_val_if_fail (error == NULL || *error == NULL, 0);
+
+ ret = git_submodule_status (&status, submodule->submodule);
+
+ if (ret != GIT_OK)
+ {
+ _ggit_error_set (error, ret);
+ }
+
+ return status;
+}
+
/* ex:set ts=8 noet: */
diff --git a/libgit2-glib/ggit-submodule.h b/libgit2-glib/ggit-submodule.h
index 600d9ed..a1d2bc8 100644
--- a/libgit2-glib/ggit-submodule.h
+++ b/libgit2-glib/ggit-submodule.h
@@ -38,20 +38,55 @@ GgitSubmodule *_ggit_submodule_new (const git_submodul
GgitSubmodule *ggit_submodule_ref (GgitSubmodule *submodule);
void ggit_submodule_unref (GgitSubmodule *submodule);
+void ggit_submodule_save (GgitSubmodule *submodule,
+ GError **error);
+
+GgitRepository *ggit_submodule_get_owner (GgitSubmodule *submodule);
+
const gchar *ggit_submodule_get_name (GgitSubmodule *submodule);
const gchar *ggit_submodule_get_path (GgitSubmodule *submodule);
const gchar *ggit_submodule_get_url (GgitSubmodule *submodule);
+void ggit_submodule_set_url (GgitSubmodule *submodule,
+ const gchar *url,
+ GError **error);
+
GgitOId *ggit_submodule_get_index_oid (GgitSubmodule *submodule);
-GgitSubmoduleUpdate ggit_submodule_get_update (GgitSubmodule *submodule);
+GgitOId *ggit_submodule_get_head_oid (GgitSubmodule *submodule);
+
+GgitOId *ggit_submodule_get_workdir_oid (GgitSubmodule *submodule);
GgitSubmoduleIgnore ggit_submodule_get_ignore (GgitSubmodule *submodule);
+GgitSubmoduleIgnore ggit_submodule_set_ignore (GgitSubmodule *submodule,
+ GgitSubmoduleIgnore ignore);
+
+GgitSubmoduleUpdate ggit_submodule_get_update (GgitSubmodule *submodule);
+
+GgitSubmoduleUpdate ggit_submodule_set_update (GgitSubmodule *submodule,
+ GgitSubmoduleUpdate update);
+
gboolean ggit_submodule_get_fetch_recurse (GgitSubmodule *submodule);
+gboolean ggit_submodule_set_fetch_recurse (GgitSubmodule *submodule,
+ gboolean fetch_recurse);
+
+void ggit_submodule_init (GgitSubmodule *submodule,
+ gboolean overwrite,
+ GError **error);
+
+void ggit_submodule_sync (GgitSubmodule *submodule,
+ GError **error);
+
+void ggit_submodule_reload (GgitSubmodule *submodule,
+ GError **error);
+
+GgitSubmoduleStatus ggit_submodule_get_status (GgitSubmodule *submodule,
+ GError **error);
+
G_END_DECLS
#endif /* __GGIT_SUBMODULE_H__ */
diff --git a/libgit2-glib/ggit-types.c b/libgit2-glib/ggit-types.c
index 2d96b6c..2e194da 100644
--- a/libgit2-glib/ggit-types.c
+++ b/libgit2-glib/ggit-types.c
@@ -121,6 +121,13 @@ ASSERT_ENUM (GGIT_STATUS_WORKING_TREE_DELETED, GIT_STATUS_WT_DELETED);
ASSERT_ENUM (GGIT_STATUS_IGNORED, GIT_STATUS_IGNORED);
+ASSERT_ENUM (GGIT_SUBMODULE_IGNORE_DEFAULT, GIT_SUBMODULE_IGNORE_DEFAULT);
+ASSERT_ENUM (GGIT_SUBMODULE_IGNORE_NONE, GIT_SUBMODULE_IGNORE_NONE);
+ASSERT_ENUM (GGIT_SUBMODULE_IGNORE_UNTRACKED, GIT_SUBMODULE_IGNORE_UNTRACKED);
+ASSERT_ENUM (GGIT_SUBMODULE_IGNORE_DIRTY, GIT_SUBMODULE_IGNORE_DIRTY);
+ASSERT_ENUM (GGIT_SUBMODULE_IGNORE_ALL, GIT_SUBMODULE_IGNORE_ALL);
+
+
ASSERT_ENUM (GGIT_SUBMODULE_STATUS_IN_HEAD, GIT_SUBMODULE_STATUS_IN_HEAD);
ASSERT_ENUM (GGIT_SUBMODULE_STATUS_IN_INDEX, GIT_SUBMODULE_STATUS_IN_INDEX);
ASSERT_ENUM (GGIT_SUBMODULE_STATUS_IN_CONFIG, GIT_SUBMODULE_STATUS_IN_CONFIG);
diff --git a/libgit2-glib/ggit-types.h b/libgit2-glib/ggit-types.h
index ae33529..49073f8 100644
--- a/libgit2-glib/ggit-types.h
+++ b/libgit2-glib/ggit-types.h
@@ -492,11 +492,27 @@ typedef enum {
/**
* GgitSubmoduleIgnore:
- * FIXME
+ * GGIT_SUBMODULE_IGNORE_DEFAULT: reset to default.
+ * GGIT_SUBMODULE_IGNORE_NONE: any change or untracked == dirty.
+ * GGIT_SUBMODULE_IGNORE_UNTRACKED: dirty if tracked files change.
+ * GGIT_SUBMODULE_IGNORE_DIRTY: only dirty if HEAD moved.
+ * GGIT_SUBMODULE_IGNORE_ALL: never dirty
*
* Describes which submodules should be ignored.
*/
typedef enum {
+ GGIT_SUBMODULE_IGNORE_DEFAULT = -1,
+ GGIT_SUBMODULE_IGNORE_NONE = 0,
+ GGIT_SUBMODULE_IGNORE_UNTRACKED = 1,
+ GGIT_SUBMODULE_IGNORE_DIRTY = 2,
+ GGIT_SUBMODULE_IGNORE_ALL = 3
+} GgitSubmoduleIgnore;
+
+/**
+ * GgitSubmoduleStatus:
+ * FIXME
+ */
+typedef enum {
GGIT_SUBMODULE_STATUS_IN_HEAD = 1 << 0,
GGIT_SUBMODULE_STATUS_IN_INDEX = 1 << 1,
GGIT_SUBMODULE_STATUS_IN_CONFIG = 1 << 2,
@@ -511,7 +527,7 @@ typedef enum {
GGIT_SUBMODULE_STATUS_WD_INDEX_MODIFIED = 1 << 11,
GGIT_SUBMODULE_STATUS_WD_WD_MODIFIED = 1 << 12,
GGIT_SUBMODULE_STATUS_WD_UNTRACKED = 1 << 13
-} GgitSubmoduleIgnore;
+} GgitSubmoduleStatus;
/**
* GgitSubmoduleUpdate:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]