Commit Graph

4856 Commits

Author SHA1 Message Date
Vicent Marti
7360122ba9 Fix file renaming in MinGW
We now use MoveFileEx, which is not assured to be atomic but works for
always (both if the destination exists, or if it doesn't) and is
available in MinGW.

Since this is a Win32 API call, complaint about lost or overwritten files
should be forwarded at Steve Ballmer.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2011-02-24 23:53:40 +02:00
Vicent Marti
3eb47c9f67 Fix renaming of files in Win32
The `rename` call doesn't quite work on Win32: expects the destination
file to not exist. We're using a native Win32 call in those cases --
that should do the trick.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2011-02-24 21:43:08 +02:00
Vicent Marti
c3be146840 Fix double-freeing file descriptors
Was crashing the Windows build.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2011-02-24 19:31:12 +02:00
Vicent Marti
fc658755bf Rewrite git_hashtable internals
The old hash table with chained buckets has been replaced by a new one
using Cuckoo hashing, which offers guaranteed constant lookup times.
This should improve speeds on most use cases, since hash tables in
libgit2 are usually used as caches where the objects are stored once and
queried several times.

The Cuckoo hash implementation is based off the one in the Basekit
library [1] for the IO language, but rewritten to support an arbritrary
number of hashes. We currently use 3 to maximize the usage of the nodes pool.

[1]: https://github.com/stevedekorte/basekit/blob/master/source/CHash.c

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2011-02-22 21:59:36 +02:00
Vicent Marti
4378e8d470 Add unit test for writing a big index file
Signed-off-by: Vicent Marti <tanoku@gmail.com>
2011-02-22 15:19:35 +02:00
Vicent Marti
5591ea15a5 Add printf method to the File Buffer
Signed-off-by: Vicent Marti <tanoku@gmail.com>
2011-02-22 15:19:23 +02:00
Olivier Ramonat
af774b012c Add --without-sqlite option to waf configure
Disable sqlite support when ./waf configure is run with --without-sqlite
2011-02-21 21:57:27 +02:00
Vicent Marti
817c28201e Rewrite all file IO for more performance
The new `git_filebuf` structure provides atomic high-performance writes
to disk by using a write cache, and optionally a double-buffered scheme
through a worker thread (not enabled yet).

Writes can be done 3-layered, like in git.git (user code -> write cache
-> disk), or 2-layered, by writing directly on the cache. This makes
index writing considerably faster.

The `git_filebuf` structure contains all the old functionality of
`git_filelock` for atomic file writes and reads. The `git_filelock`
structure has been removed.

Additionally, the `git_filebuf` API allows to automatically hash (SHA1)
all the data as it is written to disk (hashing is done smartly on big
chunks to improve performance).

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2011-02-21 18:13:43 +02:00
Vicent Marti
874c3b6f37 Fix repository initialization
Fixed several issues with path joining and bare repos.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2011-02-18 14:11:53 +02:00
Vicent Marti
cb77ad0d4e Fix segfault when iterating a revlist backwards
The `prev` and `next` pointers were not being updated after popping one
of the list elements.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2011-02-18 12:23:53 +02:00
Vicent Marti
e822508a05 Disable threaded index writing by default
The interlocking on the write threads was not being done properly (index
entries were sometimes written out of order). With proper interlocking,
the threaded write is only marginally faster on big index files, and
slower on the smaller ones because of the overhead when creating
threads.

The threaded index writing has been temporarily disabled; after more
accurate benchmarks, if might be possible to enable it again only when
writing very large index files (> 1000 entries).

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2011-02-18 10:29:55 +02:00
Vicent Marti
3ecc8b5ed9 Fix refcounting initialization
Signed-off-by: Vicent Marti <tanoku@gmail.com>
2011-02-18 00:08:34 +02:00
Vicent Marti
084c193562 Fix type truncation in index entries
64-bit types stored in memory have to be truncated into 32 bits when
writing to disk. Was causing warnings in MSVC.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2011-02-17 23:32:22 +02:00
Vicent Marti
348c7335dd Improve the performance when writing Index files
In response to issue #60 (git_index_write really slow), the write_index
function has been rewritten to improve its performance -- it should now
be in par with the performance of git.git.

On top of that, if Posix Threads are available when compiling libgit2, a
new threaded writing system will be used (3 separate threads take care
of solving byte-endianness, hashing the contents of the index and
writing to disk, respectively). For very long Index files, this method
is up to 3x times faster than git.git.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2011-02-17 23:20:47 +02:00
Tim Clem
81d0ff1ca5 fix cast in tag.h
git_tag_lookup() and git_tag_new() changed to cast GIT_OBJ_TAG to
git_otype in order to compile lib in xcode
2011-02-14 13:22:44 -08:00
Vicent Marti
d4b5a4e23a Internal changes on the backend system
The priority value for different backends has been removed from the
public `git_odb_backend` struct. We handle that internally. The priority
value is specified on the `git_odb_add_alternate`.

This is convenient because it allows us to poll a backend twice with
different priorities without having to instantiate it twice.

We also differentiate between main backends and alternates; alternates have
lower priority and cannot be written to.

These changes come with some unit tests to make sure that the backend
sorting is consistent.

The libgit2 version has been bumped to 0.4.0.

This commit changes the external API:

CHANGED:
	struct git_odb_backend
		No longer has a `priority` attribute; priority for the backend
		in managed internally by the library.

	git_odb_add_backend(git_odb *odb, git_odb_backend *backend, int priority)
		Now takes an additional priority parameter, the priority that
		will be given to the backend.

ADDED:
	git_odb_add_alternate(git_odb *odb, git_odb_backend *backend, int priority)
		Add a backend as an alternate. Alternate backends have always
		lower priority than main backends, and writing is disabled on
		them.

Signed-off-by: Vicent Marti <tanoku@gmail.com>

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2011-02-09 19:49:38 +02:00
Vicent Marti
5a800efc42 Honor alternate entries in the ODB
The alternates file is now parsed, and the alternate ODB folders are
added as separate backends. This allows the library to efficiently query
the alternate folders.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2011-02-09 12:46:54 +02:00
Vicent Marti
995f9c34a5 Use the new git__joinpath to build paths in methods
The `git__joinpath` function has been changed to use a statically
allocated buffer; we assume the buffer to be 4096 bytes, because fuck
you.

The new method also supports an arbritrary number of paths to join,
which may come in handy in the future.

Some methods which were manually joining paths with `strcpy` now use the
new function, namely those in `index.c` and `refs.c`.

Based on Emeric Fermas' original patch, which was using the old
`git__joinpath` because I'm stupid. Thanks!

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2011-02-09 12:43:19 +02:00
Vicent Marti
772c7e7623 Merge branch 'git-reference-creation-tests' of https://github.com/nulltoken/libgit2 2011-02-08 19:28:12 +02:00
Przemyslaw Pawelczyk
20e83aa4ef Further improve SQLite support for CMake users.
Unfortunately previous commit was only a partial fix, because it broke
SQLite support on platforms w/o pkg-config, e.g. Windows. To be honest
I just forgot about messy Windows.

Now if there is no pkg-config, then user must provide two variables:
SQLITE3_INCLUDE_DIRS and SQLITE3_LIBRARIES if (s)he wants to use SQLite
backend. These variables are added to cmake-gui for her/his convenience
unless they are set by FindPkgConfig module.

pkg-config should work also now in Cygwin.
2011-02-08 13:14:19 +01:00
Przemyslaw Pawelczyk
911fd45792 Fix SQLite support for CMake users.
FindPkgConfig obviously uses pkg-config's output for setting convenient
variables such as <PREFIX>_LIBRARIES or <PREFIX>_INCLUDE_DIRS. It also
sets <PREFIX>_FOUND to 1 if <PREFIX> module exists.

So why checking for SQLITE3_FOUND is better than (SQLITE3_LIBRARIES AND
SQLITE3_INCLUDE_DIRS)? Apart from obvious readability factor, latter
condition has strong assumption that both variables are filled with
appropriate paths, which is unjustifiable unless you add another
assumptions...

pkg-config by default strips -I/usr/include from Cflags and -L/usr/lib
from Libs if some environment variables are not set,
PKG_CONFIG_ALLOW_SYSTEM_CFLAGS and PKG_CONFIG_ALLOW_SYSTEM_LIBS
respectively. This behavior is sane, because it prevents polluting the
compilation and linking commands with superfluous entries.

In debian SQLITE3_INCLUDE_DIRS is empty for instance.

Remark for developers:
Always check commands invoked by CMake after changing CMakeLists.txt.

    VERBOSE=1 cmake --build .
2011-02-08 00:30:08 +01:00
nulltoken
1b7124f849 Added tests exercising git_reference_write() to create a new symbolic reference and a new object id reference. 2011-02-07 21:24:52 +01:00
Vicent Marti
122c340583 Git trees are now always lazily sorted
Removed `git_tree_add_entry_unsorted`. Now the `git_tree_add_entry`
method doesn't sort the entries array by default; entries are only
sorted lazily when required. This is done automatically by the library
(the `git_tree_sort_entries` call has been removed).

This should improve performance. No point on sorting entries all the time, anyway.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2011-02-07 18:25:42 +02:00
Vicent Marti
8212e2d7d0 Fix detection of working dir on repositories
Signed-off-by: Vicent Marti <tanoku@gmail.com>
2011-02-07 18:25:23 +02:00
Vicent Marti
9d1dcca229 Add proper version management
We now have proper sonames in Mac OS X and Linux, proper versioning on
the pkg-config file and proper DLL naming in Windows.

The version of the library is defined exclusively in 'src/git2.h'; the build scripts
read it from there automatically.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2011-02-07 10:35:58 +02:00
Vicent Marti
7a689719bd Merge branch 'master' of https://github.com/saschpe/libgit2 into saschpe-master
Conflicts:
	CMakeLists.txt
2011-02-07 09:14:45 +02:00
Vicent Marti
f443a8793f Compile the SQLite backend with CMake too
Use pkg-config to find the library in Unix systems. In Win32, just set
manually the path to your libraries.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2011-02-07 08:47:50 +02:00
Vicent Marti
becff0428e Fix compilation in MSVC
The git_odb_backend_* symbols were being redefined as external.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2011-02-07 08:09:11 +02:00
Vicent Marti
2e75e15690 Merge branch 'refs-handling-tests' of https://github.com/nulltoken/libgit2 2011-02-07 08:04:32 +02:00
Vicent Marti
e85c705f5a Merge branch 'join-path-tests' of https://github.com/nulltoken/libgit2 2011-02-07 08:04:04 +02:00
Vicent Marti
13317a5e0f Merge branch 'chobie_git_dir_fix' of https://github.com/chobie/libgit2 2011-02-07 08:03:06 +02:00
John Wiegley
e769e0255e Git does not like zero padded file attributes (git fsck) 2011-02-07 00:11:17 -05:00
John Wiegley
5bf4291637 Further correction to tree entry sorting (for git fsck) 2011-02-07 00:11:00 -05:00
Shuhei Tanuma
56ab8c5437 fix can't detect repository index issues. 2011-02-06 15:48:52 +09:00
nulltoken
fc8afc87d7 Fix a memory leak in git__joinpath() tests. 2011-02-06 07:48:17 +01:00
nulltoken
a79e8e632a Fixed a small issue in git__join_path(). Added tests to exercise git__join_path(). 2011-02-05 19:23:51 +01:00
nulltoken
ca0fb40a6f Made test index_write_test() remove the test file it has created.
It can now be run twice in a row without failing.
2011-02-05 19:23:51 +01:00
Vicent Marti
fb8dd803b7 Merge branch 'sqlite-backend' 2011-02-05 19:49:42 +02:00
Vicent Marti
c041af95a2 Add support for SQLite backends
Configure again the build system to look for SQLite3. If the library is
found, the SQLite backend will be automatically compiled.

Enjoy *very* fast reads and writes.

MASTER PROTIP: Initialize the backend with ":memory" as the path to the
SQLite database for fully-hosted in-memory repositories. Rejoice.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2011-02-05 19:45:57 +02:00
Vicent Marti
95901128b8 Move data from t03 to a separate header
Signed-off-by: Vicent Marti <tanoku@gmail.com>
2011-02-05 18:17:01 +02:00
nulltoken
1af8c7488d Enforced refs handling tests.
- Added a test to ensure that a nested symbolic reference is properly resolved.
 - Added comparisons of object ids.
2011-02-05 15:24:08 +01:00
nulltoken
40be9ae0a8 Fixes a Win32/MSVC compilation issue. 2011-02-05 15:03:48 +01:00
Vicent Marti
412b388776 Add new utility method git__joinpath
Signed-off-by: Vicent Marti <tanoku@gmail.com>
2011-02-05 13:12:02 +02:00
Vicent Marti
f725931b48 Fix directory/path manipulation methods
The `dirname` and `dirbase` methods have been replaced with the Android
implementation, which is actually compilant to some kind of standard.

A new method `topdir` has been added, which returns the topmost
directory in a path.

These changes fix issue #49:

	`gitfo_prettify_dir_path` converts "./.git/" to ".git/", so
	the code at src/repository.c:190 goes out of bounds when
	trying to find the topmost directory.

	The new `git__topdir` method handles this gracefully, and the
	fixed `git__dirname` now returns the proper value for the
	repository's working dir.

	E.g.

		/repo/.git/ ==> working dir '/repo/'
		.git/		==> working dir '.'

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2011-02-05 12:42:41 +02:00
Vicent Marti
c836c332f1 Make more methods return error codes
git_revwalk_next now returns an error code when the iteration is over.
git_repository_index now returns an error code when the index file could
not be opened.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2011-02-05 09:29:37 +02:00
Vicent Marti
4569bfa55a Keep the tree entries always internally sorted
Don't allow access to any tree entries whilst the entries array is
unsorted. We keep track on when the array is unsorted, and any methods
that access the array while it is unsorted now sort the array before
accessing it.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2011-02-05 09:11:17 +02:00
Vicent Marti
5d773a6ee8 Merge branch 'master' of https://github.com/jwiegley/libgit2 2011-02-05 09:01:10 +02:00
John Wiegley
35786cb7e8 Use Git's own tree entry sorting algorithm
If plain strcmp is used, as this code did before, the final sorting may
end up different from what git-add would do (for example, 'boost'
appearing before 'boost-build.jam', because Git sorts as if it were
spelled 'boost/').

If the sorting is incorrect like this, Git 1.7.4 insists that unmodified
files have been modified.  For example, my test repository has these
four entries:

drwxr-xr-x  199 johnw  wheel   6766 Feb  2 17:21 boost
-rw-r--r--    1 johnw  wheel    849 Feb  2 17:22 boost-build.jam
-rw-r--r--    1 johnw  wheel    989 Feb  2 17:21 boost.css
-rw-r--r--    1 johnw  wheel   6308 Feb  2 17:21 boost.png

Here is the output from git-ls-tree for these files, in a commit tree
created using git-add and git-commit:

100644 blob 8b8775433aef73e9e12609610ae2e35cf1e7ec2c    boost-build.jam
100644 blob 986c4050fa96d825a1311c8e871cdcc9a3e0d2c3    boost.css
100644 blob b4d51fcd5c9149fd77f5ca6ed2b6b1b70e8fe24f    boost.png
040000 tree 46537eeaa4d577010f19b1c9e940cae9a670ff5c    boost

Here is the output for the same commit produced using libgit2:

040000 tree c27c0fd1436f28a6ba99acd0a6c17d178ed58288	boost
100644 blob 8b8775433aef73e9e12609610ae2e35cf1e7ec2c	boost-build.jam
100644 blob 986c4050fa96d825a1311c8e871cdcc9a3e0d2c3	boost.css
100644 blob b4d51fcd5c9149fd77f5ca6ed2b6b1b70e8fe24f	boost.png

Due to this reordering, git-status claims the three blobs are always
modified, no matter what I do using git-read-tree or git-reset or
git-checkout to update the index.
2011-02-03 01:47:26 -05:00
Vicent Marti
ddc9e79ae2 Fix more issues with Win32 EOL
Signed-off-by: Vicent Marti <tanoku@gmail.com>
2011-02-02 06:16:50 +02:00
Vicent Marti
ff5873ad95 Fix EOL issues in ref parsing under Win32
Reference files can be loaded using Win32 line endings, too.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2011-02-02 04:01:14 +02:00