Commit Graph

199 Commits

Author SHA1 Message Date
Scott J. Goldman
5425097f03 index: Speed up loading a tree into the index
The index is empty; repeated tree entries cannot collide.

cc github/gitrpc#83
2013-01-24 18:55:39 -08:00
Edward Thomson
25743bd7c5 add an index_remove_bypath that removes conflicts, renamed add_from_workdir to match 2013-01-12 13:47:56 -06:00
Edward Thomson
eb3c247a78 REUC needs to handle empty sides 2013-01-10 11:56:02 -06:00
Edward Thomson
359fc2d241 update copyrights 2013-01-08 17:31:27 -06:00
Russell Belfer
7fc0043582 Add index API to remove all files in a directory
This adds the git_index_remove_directory API plus tests.
2013-01-04 15:47:44 -08:00
Russell Belfer
6fee906c98 missing error message is confusing 2013-01-04 15:23:47 -08:00
Philip Kelley
27fe6efe85 Fix git_index sorting with core.ignorecase in git_index_read 2013-01-04 13:48:08 -05:00
Edward Thomson
e759b07217 don't walk off the end of the index 2012-12-12 17:54:12 -06:00
Russell Belfer
9950d27ab6 Clean up iterator APIs
This removes the need to explicitly pass the repo into iterators
where the repo is implied by the other parameters.  This moves
the repo to be owned by the parent struct.  Also, this has some
iterator related updates to the internal diff API to lay the
groundwork for checkout improvements.
2012-12-10 15:38:28 -08:00
Russell Belfer
a8122b5d4a Fix warnings on Win64 build 2012-11-27 13:18:29 -08:00
Russell Belfer
4604a65460 update internal index API to avoid cast 2012-11-27 13:18:29 -08:00
Russell Belfer
16248ee2d1 Fix up some missing consts in tree & index
This fixes some missed places where we can apply const-ness to
various public APIs.

There are still some index and tree APIs that cannot take const
pointers because we sort our `git_vectors` lazily and so we can't
reliably bsearch the index and tree content without applying a
`git_vector_sort()` first.

This also fixes some missed places where size_t can be used and
where const can be applied to a couple internal functions.
2012-11-27 13:18:29 -08:00
Ben Straub
f45d51ff8e API updates for index.h 2012-11-27 13:18:28 -08:00
Russell Belfer
e120123e36 API review / update for tree.h 2012-11-27 13:18:28 -08:00
Vicent Marti
cfbe4be3fb More external API cleanup
Conflicts:
	src/branch.c
	tests-clar/refs/branches/create.c
2012-11-27 13:18:27 -08:00
Russell Belfer
bad68c0a99 Add iterator for git_index object
The index iterator could previously only be created from a repo
object, but this allows creating an iterator from a `git_index`
object instead (while keeping, though renaming, the old function).
2012-11-14 22:55:40 -08:00
Carlos Martín Nieto
6132a54e0b Fix a few valgrind errors 2012-11-13 16:17:37 -08:00
Vicent Martí
aa1c3b588e Merge pull request #1016 from arrbee/fix-checkout-dir-removal
Update checkout with new strategies & behavior
2012-11-13 14:13:47 -08:00
Vicent Martí
d18713fb4a Merge pull request #1056 from nulltoken/duplicate-tree-entries
Duplicate tree entries
2012-11-10 20:24:53 -08:00
nulltoken
95d73de15f index: prefer INDEX_OWNER usage 2012-11-10 21:10:49 +01:00
nulltoken
33f95a9b32 index: refine add_from_workdir() error report 2012-11-10 21:01:05 +01:00
nulltoken
69c068c79f index: make git_index_new() work with a NULL path 2012-11-10 20:42:45 +01:00
Russell Belfer
757b406504 Fix warnings and valgrind issues
This fixes some various warnings that showed up in Travis and
a couple uses of uninitialized memory and one memory leak.
2012-11-09 14:01:44 -08:00
Russell Belfer
ad9a921b92 Rework checkout with new strategy options
This is a major reworking of checkout strategy options.  The
checkout code is now sensitive to the contents of the HEAD tree
and the new options allow you to update the working tree so that
it will match the index content only when it previously matched
the contents of the HEAD.  This allows you to, for example, to
distinguish between removing files that are in the HEAD but not
in the index, vs just removing all untracked files.

Because of various corner cases that arise, etc., this required
some additional capabilities in rmdir and other utility functions.

This includes the beginnings of an implementation of code to read
a partial tree into the index based on a pathspec, but that is
not enabled because of the possibility of creating conflicting
index entries.
2012-11-09 13:52:07 -08:00
Russell Belfer
55cbd05b18 Some diff refactorings to help code reuse
There are some diff functions that are useful in a rewritten
checkout and this lays some groundwork for that.  This contains
three main things:

1. Share the function diff uses to calculate the OID for a file
   in the working directory (now named `git_diff__oid_for_file`
2. Add a `git_diff__paired_foreach` function to iterator over
   two diff lists concurrently.  Convert status to use it.
3. Move all the string/prefix/index entry comparisons into
   function pointers inside the `git_diff_list` object so they
   can be switched between case sensitive and insensitive
   versions.  This makes them easier to reuse in various
   functions without replicating logic.  As part of this, move
   a couple of index functions out of diff.c and into index.c.
2012-11-09 13:52:07 -08:00
nulltoken
7cc1bf0fcb index: Introduce git_index_has_conflicts() 2012-11-08 21:16:48 +01:00
Edward Thomson
050cf8b8a6 freeing index entries would be helpful 2012-11-02 01:01:21 -05:00
Vicent Marti
1e808f9cda index: Add git_index_new 2012-11-01 20:28:28 +01:00
Vicent Marti
43eeca04a7 index: Fix tests 2012-11-01 20:24:43 +01:00
Vicent Marti
276ea401b3 index: Add git_index_write_tree 2012-11-01 20:17:10 +01:00
Vicent Marti
8ff0f3250a index: Switch to git_futils_filestamp 2012-11-01 20:17:09 +01:00
Russell Belfer
744cc03e2b Add git_config_refresh() API to reload config
This adds a new API that allows users to reload the config if the
file has changed on disk.  A new config callback function to
refresh the config was added.

The modified time and file size are used to test if the file needs
to be reloaded (and are now stored in the disk backend object).

In writing tests, just using mtime was a problem / race, so I
wanted to check file size as well.  To support that, I extended
`git_futils_readbuffer_updated` to optionally check file size in
addition to mtime, and I added a new function `git_filebuf_stats`
to fetch the mtime and size for an open filebuf (so that the
config could be easily refreshed after a write).

Lastly, I moved some similar file checking code for attributes
into filebuf.  It is still only being used for attrs, but it
seems potentially reusable, so I thought I'd move it over.
2012-10-30 12:11:23 -07:00
Edward Thomson
f45ec1a076 index refactoring 2012-10-29 20:04:21 -05:00
nulltoken
b1be9dd0e5 index: introduce git_index_owner() 2012-10-26 21:02:04 +02:00
Ben Straub
7d222e1312 Network progress: rename things
git_indexer_stats and friends -> git_transfer_progress*

Also made git_transfer_progress members more sanely
named.
2012-10-24 13:29:14 -07:00
nulltoken
0ae81fc479 index: remove read_tree() progress indicator
git_index_read_tree() was exposing a parameter to provide the user with
a progress indicator. Unfortunately, due to the recursive nature of the
tree walk, the maximum number of items to process was unknown. Thus,
the indicator was only counting processed entries, without providing
any information how the number of remaining items.
2012-10-19 19:36:22 -07:00
Philip Kelley
ec40b7f99f Support for core.ignorecase 2012-09-17 15:42:41 -04:00
authmillenon
0e2dd29ba5 Fix logical error in git_index_set_caps 2012-09-04 12:12:48 +02:00
Vicent Martí
f98c32f3fe Merge pull request #778 from ben/clone
Clone
2012-08-19 01:26:06 -07:00
Vicent Marti
c07d9c95f2 oid: Explicitly include oid.h for the inlined CMP 2012-08-09 15:33:04 -07:00
Ben Straub
4bf5115642 Enable stats on git_index_read_tree.
Replace with the contents of 
git_index_read_tree_with_stats() and improve
documentation comments.
2012-07-30 15:48:06 -07:00
Ben Straub
f1587b97a1 Checkout: use git_index_read_tree_with_stats.
New variant of git_index_read_tree that fills in
the 'total' field of a git_indexer_stats struct
as it's walking the tree.
2012-07-30 14:37:40 -07:00
nulltoken
b8457baae2 portability: Improve x86/amd64 compatibility 2012-07-24 16:10:12 +02:00
Vicent Marti
0e2fcca850 tree: Bring back entry_bypath
Smaller, simpler, faster.
2012-06-29 02:21:12 +02:00
Russell Belfer
da825c92d9 Make index add/append support core.filemode flag
This fixes git_index_add and git_index_append to behave more like
core git, preserving old filemode data in the index when adding
and/or appending with core.filemode = false.

This also has placeholder support for core.symlinks and
core.ignorecase, but those flags are not implemented (well,
symlinks has partial support for preserving mode information in
the same way that git does, but it isn't tested).
2012-06-19 14:27:02 -07:00
Vicent Martí
9d0011fd83 tree: Naming conventions 2012-05-16 19:24:35 +02:00
Russell Belfer
41a82592ef Ranged iterators and rewritten git_status_file
The goal of this work is to rewrite git_status_file to use the
same underlying code as git_status_foreach.

This is done in 3 phases:

1. Extend iterators to allow ranged iteration with start and
   end prefixes for the range of file names to be covered.
2. Improve diff so that when there is a pathspec and there is
   a common non-wildcard prefix of the pathspec, it will use
   ranged iterators to minimize excess iteration.
3. Rewrite git_status_file to call git_status_foreach_ext
   with a pathspec that covers just the one file being checked.

Since ranged iterators underlie the status & diff implementation,
this is actually fairly efficient.  The workdir iterator does
end up loading the contents of all the directories down to the
single file, which should ideally be avoided, but it is pretty
good.
2012-05-15 14:34:15 -07:00
Russell Belfer
7c7ff7d11e Migrate index, oid, and utils to new errors
This includes a few cleanups that came up while converting
these files.

This commit introduces a could new git error classes, including
the catchall class: GITERR_INVALID which I'm using as the class
for invalid and out of range values which are detected at too low
a level of library to use a higher level classification.  For
example, an overflow error in parsing an integer or a bad letter
in parsing an OID string would generate an error in this class.
2012-03-19 16:10:11 -07:00
Russell Belfer
deafee7bd7 Continue error conversion
This converts blob.c, fileops.c, and all of the win32 files.
Also, various minor cleanups throughout the code.  Plus, in
testing the win32 build, I cleaned up a bunch (although not
all) of the warnings with the 64-bit build.
2012-03-14 17:36:15 -07:00
Russell Belfer
ae9e29fde7 Migrating diff to new error handling
Ended up migrating a bunch of upstream functions as well
including vector, attr_file, and odb in order to get this
to work right.
2012-03-06 16:27:13 -08:00
Vicent Martí
1a48112342 error-handling: References
Yes, this is error handling solely for `refs.c`, but some of the
abstractions leak all ofer the code base.
2012-03-06 00:43:10 +01:00
Vicent Martí
13224ea4aa buffer: Unify git_fbuffer and git_buf
This makes so much sense that I can't believe it hasn't been done
before. Kill the old `git_fbuffer` and read files straight into
`git_buf` objects.

Also: In order to fully support 4GB files in 32-bit systems, the
`git_buf` implementation has been changed from using `ssize_t` for
storage and storing negative values on allocation failure, to using
`size_t` and changing the buffer pointer to a magical pointer on
allocation failure.

Hopefully this won't break anything.
2012-02-27 05:30:07 +01:00
schu
5e0de32818 Update Copyright header
Signed-off-by: schu <schu-github@schulog.org>
2012-02-13 17:11:09 +01:00
Russell Belfer
1744fafec0 Move path related functions from fileops to path
This takes all of the functions that look up simple data about
paths (such as `git_futils_isdir`) and moves them over to path.h
(becoming `git_path_isdir`).  This leaves fileops.h just with
functions that actually manipulate the filesystem or look at
the file contents in some way.

As part of this, the dir.h header which is really just for win32
support was moved into win32 (with some minor changes).
2012-01-17 15:49:47 -08:00
Russell Belfer
fa3cb0dae0 Fix memory leak in git_index_remove.
Missed freeing the entry.
2012-01-05 15:15:43 -08:00
Clemens Buchacher
599f2849ba add git_index_read_tree 2011-12-30 20:14:05 +01:00
Russell Belfer
86e356ee51 Restore missing lstat in index_entry_init
In an effort to remove duplicate code, I accidentally left
the stat structure uninitialized in this function.  This
patch restores that data gathering.
2011-12-18 12:08:50 -08:00
Russell Belfer
97769280ba Use git_buf for path storage instead of stack-based buffers
This converts virtually all of the places that allocate GIT_PATH_MAX
buffers on the stack for manipulating paths to use git_buf objects
instead.  The patch is pretty careful not to touch the public API
for libgit2, so there are a few places that still use GIT_PATH_MAX.

This extends and changes some details of the git_buf implementation
to add a couple of extra functions and to make error handling easier.

This includes serious alterations to all the path.c functions, and
several of the fileops.c ones, too.  Also, there are a number of new
functions that parallel existing ones except that use a git_buf
instead of a stack-based buffer (such as git_config_find_global_r
that exists alongsize git_config_find_global).

This also modifies the win32 version of p_realpath to allocate whatever
buffer size is needed to accommodate the realpath instead of hardcoding
a GIT_PATH_MAX limit, but that change needs to be tested still.
2011-12-07 23:08:15 -08:00
Carlos Martín Nieto
89886d0bbb Plug a bunch of leaks 2011-11-28 21:08:29 +01:00
Vicent Marti
9462c47143 repository: Change ownership semantics
The ownership semantics have been changed all over the library to be
consistent. There are no more "borrowed" or duplicated references.

Main changes:

	- `git_repository_open2` and `3` have been dropped.

	- Added setters and getters to hotswap all the repository owned
	objects:

		`git_repository_index`
		`git_repository_set_index`
		`git_repository_odb`
		`git_repository_set_odb`
		`git_repository_config`
		`git_repository_set_config`
		`git_repository_workdir`
		`git_repository_set_workdir`

	Now working directories/index files/ODBs and so on can be
	hot-swapped after creating a repository and between operations.

	- All these objects now have proper ownership semantics with
	refcounting: they all require freeing after they are no longer
	needed (the repository always keeps its internal reference).

	- Repository open and initialization has been updated to keep in
	mind the configuration files. Bare repositories are now always
	detected, and a default config file is created on init.

	- All the tests affected by these changes have been dropped from the
	old test suite and ported to the new one.
2011-11-26 08:37:08 +01:00
Russell Belfer
b762e576c6 filebuf: add GIT_FILEBUF_INIT and protect multiple opens and cleanups
Update all stack allocations of git_filebuf to use GIT_FILEBUF_INIT
and make git_filebuf_open and git_filebuf_cleanup safe to be called
multiple times on the same buffer.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2011-11-22 01:53:56 +01:00
Vicent Martí
89fb8f025a Merge pull request #456 from brodie/perm-fixes
Create objects, indexes, and directories with the right file permissions
2011-10-28 19:04:23 -07:00
Vicent Marti
3286c408ec global: Properly use git__ memory wrappers
Ensure that all memory related functions (malloc, calloc, strdup, free,
etc) are using their respective `git__` wrappers.
2011-10-28 19:02:36 -07:00
Brodie Rao
01ad7b3a9e *: correct and codify various file permissions
The following files now have 0444 permissions:

- loose objects
- pack indexes
- pack files
- packs downloaded by fetch
- packs downloaded by the HTTP transport

And the following files now have 0666 permissions:

- config files
- repository indexes
- reflogs
- refs

This brings libgit2 more in line with Git.

Note that git_filebuf_commit() and git_filebuf_commit_at() have both
gained a new mode parameter.

The latter change fixes an important issue where filebufs created with
GIT_FILEBUF_TEMPORARY received 0600 permissions (due to mkstemp(3)
usage). Now we chmod() the file before renaming it into place.

Tests have been added to confirm that new commit, tag, and tree
objects are created with the right permissions. I don't have access to
Windows, so for now I've guarded the tests with "#ifndef GIT_WIN32".
2011-10-14 16:07:47 -07:00
Vicent Marti
356f11feea index: Silence type-punned warning 2011-09-29 16:28:00 +02:00
Carlos Martín Nieto
b419fe2d8c Invalidate the path when removing from the index
Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-09-27 14:33:18 +02:00
Carlos Martín Nieto
e23ede0de5 index: invalidate added paths
When a file is updated in the index, it's path needs to be invalidated
in the tree cache as the hash is no longer correct.

Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-09-27 14:33:18 +02:00
Carlos Martín Nieto
b41713206b Move the tree cache functions to their own file
Rename git_index_tree to git_tree_cache.

Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-09-27 14:33:18 +02:00
nulltoken
ad196c6ae6 config: make git_config_[get|set]_long() able to properly deal with 8 bytes wide values
Should fix issue #419.

Signed-off-by: nulltoken <emeric.fermas@gmail.com>
2011-09-22 18:58:47 +02:00
Vicent Marti
87d9869fc3 Tabify everything
There were quite a few places were spaces were being used instead of
tabs. Try to catch them all. This should hopefully not break anything.
Except for `git blame`. Oh well.
2011-09-19 03:34:49 +03:00
Vicent Marti
bb742ede3d Cleanup legal data
1. The license header is technically not valid if it doesn't have a
copyright signature.

2. The COPYING file has been updated with the different licenses used in
the project.

3. The full GPLv2 header in each file annoys me.
2011-09-19 01:54:32 +03:00
Vicent Marti
c035ede234 Fix compilation in MinGW 2011-08-31 03:56:57 +02:00
Vicent Martí
cb1c75635e Merge pull request #335 from carlosmn/read-updated
Don't stat so much when reading references
2011-07-28 05:32:47 -07:00
Kirill A. Shutemov
76159921f4 index: rework index entry initialization routine
index_init_entry() renamed to index_entry_init(). Now it allocates entry
on its own.

git_index_add() and git_index_append() reworked accordingly.

This commit fixes warning:

/home/kas/git/public/libgit2/src/index.c: In function ‘index_init_entry’:
/home/kas/git/public/libgit2/src/index.c:452:14: warning: assignment discards ‘const’ qualifier from pointer target type [enabled by default]

Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
2011-07-25 21:12:47 +02:00
Kirill A. Shutemov
f939d39bec index: rework index_insert()
Now index_insert() takes copy of index entry, not coping it by itself.

Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
2011-07-25 21:12:47 +02:00
Kirill A. Shutemov
b2dd681512 index: introduce index_entry_free()
Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
2011-07-25 21:12:47 +02:00
Kirill A. Shutemov
51917d9ca2 index: extract index_entry_dup() from index_insert()
Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
2011-07-25 21:12:47 +02:00
Kirill A. Shutemov
7d9cc9f81a index: fix cast warnings
/home/kas/git/public/libgit2/src/index.c: In function ‘git_index_clear’:
/home/kas/git/public/libgit2/src/index.c:228:8: warning: cast discards ‘__attribute__((const))’ qualifier from pointer target type [-Wcast-qual]
/home/kas/git/public/libgit2/src/index.c:235:8: warning: cast discards ‘__attribute__((const))’ qualifier from pointer target type [-Wcast-qual]
/home/kas/git/public/libgit2/src/index.c: In function ‘index_insert’:
/home/kas/git/public/libgit2/src/index.c:392:7: warning: cast discards ‘__attribute__((const))’ qualifier from pointer target type [-Wcast-qual]
/home/kas/git/public/libgit2/src/index.c:399:7: warning: cast discards ‘__attribute__((const))’ qualifier from pointer target type [-Wcast-qual]
/home/kas/git/public/libgit2/src/index.c: In function ‘read_unmerged’:
/home/kas/git/public/libgit2/src/index.c:681:35: warning: cast discards ‘__attribute__((const))’ qualifier from pointer target type [-Wcast-qual]
/home/kas/git/public/libgit2/src/index.c: In function ‘read_entry’:
/home/kas/git/public/libgit2/src/index.c:716:33: warning: cast discards ‘__attribute__((const))’ qualifier from pointer target type [-Wcast-qual]

Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
2011-07-25 21:12:47 +02:00
Carlos Martín Nieto
7db40d450d index: use git_futils_readbuffer_updated
This helps readability a bit as well.

Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-07-23 14:30:40 +02:00
Kirill A. Shutemov
26b1b15767 index: fix memory leak
We need really free vectors on index freeing, not only clear.

Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
2011-07-19 16:09:20 +03:00
Vicent Marti
3dd26d1e36 index: Yes, we have to truncate 2011-07-13 02:15:31 +02:00
Kirill A. Shutemov
b16692faa3 index: fix potential overflow
mode field of git_index_entry_unmerged is array of unsigned ints. It's
unsafe to cast pointer to an element of the array to long int *. It may
cause overflow in git_strtol32().

Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
2011-07-13 02:03:34 +02:00
Kirill A. Shutemov
ae9f771c99 index: drop useless type casting
Type casting usually points to some trick or bug. It's better not hide
it between useless type castings.

Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
2011-07-13 02:03:34 +02:00
Kirill A. Shutemov
e1fca01477 vector: mark internal functions as static
Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
2011-07-13 02:03:34 +02:00
Kirill A. Shutemov
046dfea343 vector: avoid double asserting
index_initialize() calls assert() for arguments on its own. No need to
call it twice.

Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
2011-07-13 02:03:34 +02:00
Kirill A. Shutemov
fad6607a55 index: drop sort_index()
Remove dummy wrapper around git_vector_sort().

Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
2011-07-13 02:03:34 +02:00
Kirill A. Shutemov
07d3487761 index: do not sort index before git_vector_bsearch2()
git_vector_bsearch2() calls git_vector_sort(). No need to call it
directly.

Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
2011-07-13 02:03:34 +02:00
Kirill A. Shutemov
212b379a1f index: do not free vectors twice in git_index_free()
git_index_clear() frees index->entries and index->unmerged. No need to
free it once again.

Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
2011-07-13 02:03:34 +02:00
Vicent Marti
f0ab9fda8b index: Return GIT_ENOTFOUND when an entry cannot be opened 2011-07-09 02:40:15 +02:00
Vicent Marti
da5b1e1c73 index: Fix memory leak on OOM 2011-07-07 17:56:10 +02:00
Vicent Marti
de18f27668 vector: Timsort all of the things
Drop the GLibc implementation of Merge Sort and replace it with Timsort.

The algorithm has been tuned to work on arrays of pointers (void **),
so there's no longer a need to abstract the byte-width of each element
in the array.

All the comparison callbacks now take pointers-to-elements, not
pointers-to-pointers, so there's now one less level of dereferencing.

E.g.

	 int index_cmp(const void *a, const void *b)
	 {
	-	const git_index_entry *entry_a = *(const git_index_entry **)(a);
	+	const git_index_entry *entry_a = (const git_index_entry *)(a);

The result is up to a 40% speed-up when sorting vectors. Memory usage
remains lineal.

A new `bsearch` implementation has been added, whose callback also
supplies pointer-to-elements, to uniform the Vector API again.
2011-07-07 02:54:07 +02:00
Kirill A. Shutemov
245adf4f3c index: introduce git_index_uniq() function
It removes all entries with equal path except last added.

On large indexes git_index_append() + git_index_uniq() before writing is
*much* faster, than git_index_add().

Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
2011-07-05 17:52:39 +03:00
Kirill A. Shutemov
8cc16e29e8 index: speedup git_index_append()/git_index_append2()
git_index_find() in index_insert() is useless if replace is not
requested (append). Do not call it in this case.
It speedup git_index_append() *dramatically* on large indexes.

$ cat index_test.c

int main(int argc, char **argv)
{
        git_index *index;
        git_repository *repo;
        git_odb *odb;
        struct git_index_entry entry;
        git_oid tree_oid;
        char tree_hex[41];
        int i;

        git_repository_init(&repo, "/tmp/myrepo", 0);
        odb = git_repository_database(repo);
        git_repository_index(&index, repo);

        memset(&entry, 0, sizeof(entry));
        git_odb_write(&entry.oid, odb, "", 0, GIT_OBJ_BLOB);
        entry.path = "test.file";

        for (i = 0; i < 50000; i++)
                git_index_append2(index, &entry);

        git_tree_create_fromindex(&tree_oid, index);
        git_oid_fmt(tree_hex, &tree_oid);
        tree_hex[40] = '\0';
        printf("tree: %s\n", tree_hex);

        git_index_free(index);
        git_repository_free(repo);

        return 0;
}

Before:
$ time ./index_test
tree: 43f73659c43b651588cc81459d9e25b08721b95d
./index_test  151.19s user 0.05s system 99% cpu 2:31.78 total

After:
$ time ./index_test
tree: 43f73659c43b651588cc81459d9e25b08721b95d
./index_test  0.05s user 0.00s system 94% cpu 0.059 total

About 2573 times speedup on this test :)

Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
2011-07-05 17:52:39 +03:00
Vicent Marti
f79026b491 fileops: Cleanup
Cleaned up the structure of the whole OS-abstraction layer.

fileops.c now contains a set of utility methods for file management used
by the library. These are abstractions on top of the original POSIX
calls.

There's a new file called `posix.c` that contains
emulations/reimplementations of all the POSIX calls the library uses.
These are prefixed with `p_`. There's a specific posix file for each
platform (win32 and unix).

All the path-related methods have been moved from `utils.c` to `path.c`
and have their own prefix.
2011-07-05 02:04:03 +02:00
Kirill A. Shutemov
932d1baf29 cleanup: remove trailing spaces
Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
2011-07-01 18:02:56 +02:00
Vicent Marti
fa48608ec3 oid: Rename methods
Yeah. Finally. Fuck the old names, this ain't POSIX
and they don't make any sense at all.
2011-06-16 02:36:21 +02:00
Sebastian Schuberth
c1802641ff Prefer to use file mode defines instead of raw numbers 2011-06-10 13:56:24 +02:00
Vicent Marti
ae496955d2 windows: Fix Symlink issues
Handle Symlinks if they can be handled in Win32. This is not even
compiled. Needs review.

The lstat implementation is modified from core Git.
The readlink implementation is modified from PHP.
2011-06-08 17:03:41 +02:00
Jakob Pfender
fdd1e04ce7 fileops: Allow differentiation between deep and shallow exists()
When calling gitfo_exists() on a symbolic link, sometimes we need to
simply check whether the link exists and sometimes we need to check
whether the file pointed to by the symlink exists.

Introduce a new function gitfo_shallow_exists that only checks if the
link exists and revert gitfo_exists to the original functionality of
checking whether the file pointed to by the link exists.
2011-06-07 14:10:06 +02:00
Jakob Pfender
b74c867a1a blob: Stat path inside git_blob_create_fromfile
00582bc introduced a change that required the caller of
git_blob_create_fromfile() to pass a struct stat with the stat
information for the file. Several developers pointed out that this would
make life hard for the bindings developers as struct stat isn't widely
supported by other languages.

Make git_blob_create_fromfile() stat the path itself, eliminating the
need for the file to be stat'ed by the caller. This makes
index_init_entry() more costly as the file will be stat'ed twice but
makes life easier for everyone else.
2011-06-07 12:54:43 +02:00