[libgit2-glib] Check that the entry exists before wrapping it.
- From: Ignacio Casal Quinteiro <icq src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgit2-glib] Check that the entry exists before wrapping it.
- Date: Wed, 31 Oct 2012 07:25:01 +0000 (UTC)
commit 5a5eb0526e95df1020bffc2590eb1f46c40af6a3
Author: Ignacio Casal Quinteiro <icq gnome org>
Date: Wed Oct 31 08:24:05 2012 +0100
Check that the entry exists before wrapping it.
libgit2-glib/ggit-index-entry.c | 24 ++++++++++++++++++++----
1 files changed, 20 insertions(+), 4 deletions(-)
---
diff --git a/libgit2-glib/ggit-index-entry.c b/libgit2-glib/ggit-index-entry.c
index 539e6e8..ce2383e 100644
--- a/libgit2-glib/ggit-index-entry.c
+++ b/libgit2-glib/ggit-index-entry.c
@@ -158,7 +158,7 @@ ggit_index_entries_unref (GgitIndexEntries *entries)
* Changes to the #GgitIndexEntry will be reflected in the index once written
* back to disk using ggit_index_write().
*
- * Returns: (transfer full): a #GgitIndexEntry.
+ * Returns: (transfer full): a #GgitIndexEntry or %NULL if out of bounds.
*
**/
GgitIndexEntry *
@@ -166,12 +166,21 @@ ggit_index_entries_get_by_index (GgitIndexEntries *entries,
gsize idx)
{
git_index *gidx;
+ git_index_entry *entry;
g_return_val_if_fail (entries != NULL, NULL);
gidx = _ggit_index_get_index (entries->owner);
+ entry = git_index_get_byindex (gidx, idx);
- return ggit_index_entry_new (git_index_get_byindex (gidx, idx));
+ if (entry)
+ {
+ return ggit_index_entry_new (entry);
+ }
+ else
+ {
+ return NULL;
+ }
}
/**
@@ -190,7 +199,7 @@ ggit_index_entries_get_by_index (GgitIndexEntries *entries,
* Changes to the #GgitIndexEntry will be reflected in the index once written
* back to disk using ggit_index_write().
*
- * Returns: (transfer full): a #GgitIndexEntry.
+ * Returns: (transfer full): a #GgitIndexEntry or %NULL if it was not found.
*
**/
GgitIndexEntry *
@@ -211,7 +220,14 @@ ggit_index_entries_get_by_path (GgitIndexEntries *entries,
entry = git_index_get_bypath (gidx, path, stage);
g_free (path);
- return ggit_index_entry_new (entry);
+ if (entry)
+ {
+ return ggit_index_entry_new (entry);
+ }
+ else
+ {
+ return NULL;
+ }
}
/**
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]