diff options
| author | Jakob Pfender <jpfender@elegosoft.com> | 2011-03-24 15:32:24 +0100 |
|---|---|---|
| committer | Vicent Marti <tanoku@gmail.com> | 2011-03-25 00:49:47 +0200 |
| commit | 3bdc0d4c8c3a51e6b338c8166d98d5b82cb01a43 (patch) | |
| tree | 1f2bdbebaf942d5acfdde6e49b1634cdc8076778 /src/index.c | |
| parent | f3cf7f6df1d2e2fcbd4f22dae318fbc4570833d8 (diff) | |
| download | libgit2-3bdc0d4c8c3a51e6b338c8166d98d5b82cb01a43.tar.gz | |
index.c: Read index after initialization
The current behaviour of git_index_open{bare,inrepo}() is unexpected.
When an index is opened, an in-memory index object is created that is
linked to the index discovered by git_repository_open(). However, this
index object is empty, as the on-disk index is not read. To fully open
the on-disk index file, git_index_read() has to be called. This leads to
confusing behaviour. Consider the following code:
git_index *idx;
git_index_open_inrepo(&idx, repo);
git_index_write(idx);
You would expect this to have no effect, as the index is never
ostensibly manipulated. However, what actually happens is that the index
entries are removed from the on-disk index because the empty in-memory
index object created by open_inrepo() is written back to the disk.
This patch reads the index after opening it.
Diffstat (limited to 'src/index.c')
| -rw-r--r-- | src/index.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/src/index.c b/src/index.c index 34208731c..7e4d6bbc7 100644 --- a/src/index.c +++ b/src/index.c @@ -148,7 +148,7 @@ static int index_initialize(git_index **index_out, git_repository *owner, const index->on_disk = 1; *index_out = index; - return GIT_SUCCESS; + return git_index_read(index); } int git_index_open_bare(git_index **index_out, const char *index_path) |
