Commit Graph

1510 Commits

Author SHA1 Message Date
Vicent Marti
afeecf4f26 odb: Direct writes are back
DIRECT WRITES ARE BACK AND FASTER THAN EVER. The streaming writer to the
ODB was an overkill for the smaller objects like Commit and Tags; most
of the streaming logic was taking too long.

This commit makes Commits, Tags and Trees to be built-up in memory, and
then written to disk in 2 pushes (header + data), instead of streaming
everything.

This is *always* faster, even for big files (since the git_filebuf class
still does streaming writes when the memory cache overflows). This is
also a gazillion lines of code smaller, because we don't have to
precompute the final size of the object before starting the stream (this
was kind of defeating the point of streaming, anyway).

Blobs are still written with full streaming instead of loading them in
memory, since this is still the fastest way.

A new `git_buf` class has been added. It's missing some features, but
it'll get there.
2011-07-09 02:40:16 +02:00
Vicent Marti
2fc78e700c posix: Portable vsnprintf
Our good, lovely folks at Microsoft decided that there was no good
reason to make `vsnprintf` compilant with the C standard, so that
function in Windows returns -1 on overflow, instead of returning the
actual byte count needed to write the full string.

We now handle this situation more gracefully with the POSIX
compatibility layer, by returning the needed byte size using an
auxiliary method instead of blindly resizing the target buffer until it
fits.

This means we can now support `printf`s of any size by allocating a
temporary buffer. That's good.
2011-07-09 02:40:16 +02:00
Vicent Marti
d483a911b8 signature: Fix optional header 2011-07-09 02:40:16 +02:00
schu
27df4275f2 reflog: add API to read or write a reference log
So far libgit2 didn't support reference logs (reflog). Add a new
git_reflog_* API for basic reading and writing of reflogs:

* git_reflog_read
* git_reflog_write
* git_reflog_free

Signed-off-by: schu <schu-github@schulog.org>
2011-07-09 02:40:16 +02:00
schu
6727e30028 git_signature__write: make header optionally
Signed-off-by: schu <schu-github@schulog.org>
2011-07-09 02:40:16 +02:00
Vicent Marti
f0ab9fda8b index: Return GIT_ENOTFOUND when an entry cannot be opened 2011-07-09 02:40:15 +02:00
Vicent Martí
d102bbba46 Merge pull request #309 from schu/rr-flaw
reference_rename: fix flaw in force-renaming
2011-07-08 09:21:30 -07:00
Vicent Martí
44b75a13ff Merge pull request #308 from schu/unused-but-set-var
tsort: remove unused but set variable
2011-07-08 09:21:13 -07:00
schu
7329433944 reference_rename: fix flaw in force-renaming
reference_rename didn't respect the force flag. Fixed.

Reported-by: nulltoken <emeric.fermas@gmail.com>
Signed-off-by: schu <schu-github@schulog.org>
2011-07-07 21:31:59 +02:00
nulltoken
6d4f090df6 reference_renaming: add additional tests
Add some more test checking forced reference renaming.

Signed-off-by: nulltoken <emeric.fermas@gmail.com>
Acked-by: schu <schu-github@schulog.org>
2011-07-07 21:29:14 +02:00
schu
d4cb0ee85c tsort: remove unused but set variable
Signed-off-by: schu <schu-github@schulog.org>
2011-07-07 18:14:53 +02:00
Vicent Marti
da5b1e1c73 index: Fix memory leak on OOM 2011-07-07 17:56:10 +02:00
nulltoken
2b5af615e1 tag: add pattern based retrieval of list of tag names 2011-07-07 15:37:07 +02:00
nulltoken
417a581d92 tsort: fix wrong header inclusion 2011-07-07 15:36:58 +02:00
Vicent Marti
c1e857484e test-core: Fix warning in uniq test 2011-07-07 12:23:47 +02:00
nulltoken
bdcc46111c Fix MSVC compilation warnings 2011-07-07 12:12:34 +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
Vicent Marti
c63aa49459 test: Abort when the temp workdir cannot be created 2011-07-07 02:54:07 +02:00
Vicent Martí
dbede305bf Merge pull request #306 from carlosmn/development
Fix network MSYS compilation
2011-07-06 16:58:06 -07:00
Vicent Martí
1af935a39a Merge pull request #307 from nulltoken/patch-1
Fix MSVC compilation warnings
2011-07-06 12:29:22 -07:00
nulltoken
26911cbd92 Fix MSVC compilation warnings 2011-07-06 12:27:51 -07:00
Vicent Martí
bf9a2e98b8 Merge pull request #296 from kiryl/index-optimization
Index optimization
2011-07-06 10:55:06 -07:00
Vicent Marti
c68dee2a74 revwalk: Properly mark uninteresting commits 2011-07-06 19:46:41 +02:00
Vicent Marti
858dba58bf refs: Cleanup reference renaming
`git_futils_rmdir_r`: rename, clean up.

`git_reference_rename`: cleanup. Do not use 3x4096 buffers on the stack
or things will get ugly very fast. We can reuse the same buffer.
2011-07-06 18:08:13 +02:00
Vicent Martí
b8e2db5f94 Merge pull request #303 from schu/ref-rename
reference_rename: git compliant reference renaming v2
2011-07-06 06:54:11 -07:00
Carlos Martín Nieto
39cdf27280 Fix network MSYS compilation
MSYS/MinGW uses winsock but obviously doesn't set _MSC_VER. Use _WIN32
to decide whether to use winsock or BSD headers. Also remove these
headers from src/transport_git.c altogether, as they are not needed.

MSYS is very conservative, so we have to tell it that we don't care
about versions of Windows lower than WindowsXP. We also need to tell
CMake to add ws2_32 to the libraries list and we shouldn't add the
-fPIC option, to MSYS because it complains that it does it anyway.

Signed-off-by: Carlos Martín Nieto <carlos@cmartin.tk>
2011-07-06 12:48:23 +02:00
nulltoken
1b938a5826 Remove duplicated recursive directory removal related code 2011-07-06 12:25:27 +02:00
nulltoken
1ee5fd903d Fix windows specific issues
- msvc compilation warnings
 - not released file handle that prevents file removal
2011-07-06 12:25:27 +02:00
schu
0ffcf78a30 reference_rename: git compliant reference renaming
So far libgit2 didn't handle the following scenarios:

* Rename of reference m   -> m/m
* Rename of reference n/n -> n

Fixed.

Since we don't write reflogs, we have to delete any old reflog for the
renamed reference. Otherwise git.git will possibly fail when it finds
invalid logs.

Reported-by: nulltoken <emeric.fermas@gmail.com>
Signed-off-by: schu <schu-github@schulog.org>
2011-07-06 12:25:27 +02:00
schu
7ea50f6077 Add tests for git_futils_rmdir_resurs()
Signed-off-by: schu <schu-github@schulog.org>
2011-07-06 12:25:27 +02:00
schu
42b3a46097 fileops: add git_futils_rmdir_recurs()
git_futils_rmdir_recurs() shall remove the given directory and all
subdirectories. This happens only if the directories are empty.

Signed-off-by: schu <schu-github@schulog.org>
2011-07-06 12:25:27 +02:00
schu
e190da78f3 fileops: add convenience function is_dot_or_dotdot()
Signed-off-by: schu <schu-github@schulog.org>
2011-07-06 12:25:27 +02:00
schu
a6e0f315f5 Add test case checking renaming of a branch to a new name prefixed with
the old name succeeds, e.g. refs/heads/foo -> refs/heads/foo/bar

Reported-by: nulltoken <emeric.fermas@gmail.com>
Signed-off-by: schu <schu-github@schulog.org>
2011-07-06 12:25:27 +02:00
Vicent Marti
e1bf24c862 build: Add simple Makefile for embedding the library
Run `make -f Makefile.embed` to get a `libgit2.a` with no dependencies
and no configuration on any Unix-like system.

The generated library can be linked with any piece of software without
licensing issues.

Have fun.
2011-07-06 02:17:15 +02:00
Vicent Marti
1e3300d840 fnmatch: Fix compilation under Windows 2011-07-06 01:44:15 +02:00
Vicent Marti
e9c6571d7f fnmatch: Use native on Unix, emulate on Win32 2011-07-06 01:04:04 +02:00
Carlos Martín Nieto
6507743400 Also update local_connect's unused var name for MSVC
Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-07-05 21:50:51 +02:00
Vicent Martí
3827c923b8 Merge pull request #305 from nulltoken/patch-6
repository: fix typo'ed assert
2011-07-05 12:32:20 -07:00
nulltoken
7a44cc41f4 repository: fix typo'ed assert 2011-07-05 11:00:32 -07:00
Vicent Martí
0838ccc2fb Merge pull request #304 from carlosmn/config
Restore config10 test file
2011-07-05 10:50:13 -07:00
Carlos Martín Nieto
7a7ef2dceb Restore config10 test file
Removing a section variable doesn't remove its section
header. Overwrite the config10 file so there are no changes after the
test is run.

Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-07-05 17:47:10 +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
476c42acc5 vector: implement git_vector_uniq()
The routine remove duplictes from the vector. Only the last added element
of elements with equal keys remains in the vector.

Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
2011-07-05 17:52:39 +03:00
Kirill A. Shutemov
0b0a6b115d vector, index: use git__msort() for vector sorting
Index operation use git_vector_sort() to sort index entries. Since index
support adding duplicates (two or more entries with the same path), it's
important to preserve order of elements. Preserving order of elements
allows to make decisions based on order. For example it's possible to
implement function witch removes all duplicates except last added.

Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
2011-07-05 17:52:39 +03:00
Kirill A. Shutemov
c20ffa6104 util: introduce merge sort routine
In some cases it's important to preserve order of elements with equal
keys (stable sort). qsort(3) doesn't define order of elements with
equal keys.

git__msort() implements merge sort which is stable sort.

Implementation taken from git. Function renamed git_qsort() -> git__msort().

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
178376025c repository: Fix unused parameter in Unix systems 2011-07-05 15:38:26 +02:00
Vicent Martí
2f3f28b462 Merge pull request #302 from carlosmn/development
Small fixes in pack_window_open
2011-07-05 06:35:45 -07:00
Vicent Martí
e45e548a7e Merge pull request #299 from kiryl/examples-general-warnings
Fix warning in examples/general.c
2011-07-05 06:33:28 -07:00
Vicent Martí
71a8e48455 Merge pull request #297 from nulltoken/patch-5
Fix MSVC compilation issue
2011-07-05 06:32:58 -07:00