diff options
| author | Kirill A. Shutemov <kirill@shutemov.name> | 2011-07-18 03:53:24 +0300 |
|---|---|---|
| committer | Vicent Marti <tanoku@gmail.com> | 2011-07-25 21:12:47 +0200 |
| commit | 51917d9ca252744764acfaafb303be2f6cdefb85 (patch) | |
| tree | ee0e28ed00408592fc5119574f7ed3a17c5366b2 /src/index.c | |
| parent | 7d9cc9f81a2eaa0f24b82a618410cd8187ec1c05 (diff) | |
| download | libgit2-51917d9ca252744764acfaafb303be2f6cdefb85.tar.gz | |
index: extract index_entry_dup() from index_insert()
Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
Diffstat (limited to 'src/index.c')
| -rw-r--r-- | src/index.c | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/src/index.c b/src/index.c index bdae26c77..2eb080924 100644 --- a/src/index.c +++ b/src/index.c @@ -331,6 +331,24 @@ git_index_entry *git_index_get(git_index *index, unsigned int n) return git_vector_get(&index->entries, n); } +static git_index_entry *index_entry_dup(const git_index_entry *source_entry) +{ + git_index_entry *entry; + + entry = git__malloc(sizeof(git_index_entry)); + if (!entry) + return NULL; + + memcpy(entry, source_entry, sizeof(git_index_entry)); + + /* duplicate the path string so we own it */ + entry->path = git__strdup(entry->path); + if (!entry->path) + return NULL; + + return entry; +} + static int index_insert(git_index *index, const git_index_entry *source_entry, int replace) { git_index_entry *entry; @@ -343,15 +361,8 @@ static int index_insert(git_index *index, const git_index_entry *source_entry, i if (source_entry->path == NULL) return git__throw(GIT_EMISSINGOBJDATA, "Failed to insert into index. Entry has no path"); - entry = git__malloc(sizeof(git_index_entry)); - if (entry == NULL) - return GIT_ENOMEM; - - memcpy(entry, source_entry, sizeof(git_index_entry)); - - /* duplicate the path string so we own it */ - entry->path = git__strdup(entry->path); - if (entry->path == NULL) + entry = index_entry_dup(source_entry); + if (!entry) return GIT_ENOMEM; /* make sure that the path length flag is correct */ |
