Commit Graph

1216 Commits

Author SHA1 Message Date
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
Carlos Martín Nieto
2ee318a7bc Small fixes in pack_window_open
Check if the window structure has actually been allocated before
trying to access it, and don't leak said structure if the map fails.

Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-07-05 15:28:35 +02:00
Vicent Martí
d830919a2c Merge pull request #301 from carlosmn/hashtable-include-fix
Include common.h in hashtable.h
2011-07-05 06:27:56 -07:00
Carlos Martín Nieto
8f63d54cb6 Include common.h in hashtable.h
Without this, hashtable.h doesn't know what uint32_t is and the
compiler thinks that it's a function type.

Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-07-05 14:38:33 +02:00
Vicent Martí
f12aa9dc5e Merge pull request #300 from carlosmn/gsoc2011/master
A bit of networking
2011-07-05 04:31:37 -07:00
Kirill A. Shutemov
6f2b0a3ae2 examples/general: fix misc warnings
examples/general.c:393:25: warning: unused variable ‘reftarget’ [-Wunused-variable]
examples/general.c:357:19: warning: unused variable ‘e’ [-Wunused-variable]
examples/general.c:444:1: warning: control reaches end of non-void function [-Wreturn-type]

Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
2011-07-05 14:20:10 +03:00
Kirill A. Shutemov
d6d877d20f examples/general: fix warnings on not handled reference type in switch
examples/general.c:402:5: warning: enumeration value ‘GIT_REF_INVALID’ not handled in switch [-Wswitch]
examples/general.c:402:5: warning: enumeration value ‘GIT_REF_PACKED’ not handled in switch [-Wswitch]
examples/general.c:402:5: warning: enumeration value ‘GIT_REF_HAS_PEEL’ not handled in switch [-Wswitch]
examples/general.c:402:5: warning: enumeration value ‘GIT_REF_LISTALL’ not handled in switch [-Wswitch]

Signe-off-by: Kirill A. Shutemov <kirill@shutemov.name>
2011-07-05 14:20:10 +03:00
Kirill A. Shutemov
51cc50a37d examples/general: fix git_commit_create_v() arguments type
general.c:208: warning: passing argument 7 of 'git_commit_create_v' from incompatible pointer type

Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
2011-07-05 14:20:10 +03:00
nulltoken
ed72182bcf Fix MSVC compilation issue 2011-07-05 01:09:37 -07:00
Carlos Martín Nieto
7d69f78897 Add variable writing tests
Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-07-05 02:32:18 +02:00
Carlos Martín Nieto
156af801e6 Add test for section header at end of file
Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-07-05 02:32:18 +02:00
Carlos Martín Nieto
f58c53ce66 Correctly detect truncated input in header parsing
If the section header is the last line in the file,
parse_section_header would incorrectly decide that the input had been
truncated.

Fix this by checking whether the actual input line is correctly
formatted.

Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-07-05 02:32:17 +02:00
Carlos Martín Nieto
86b5ab162c git_config_add_file should rethrow
Otherwise, the information about why there was an error gets lost.

Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-07-05 02:32:17 +02:00
Carlos Martín Nieto
2601fcfc1e Add tests for deleting a config var
Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-07-05 02:32:17 +02:00
Carlos Martín Nieto
6d4b609718 Add git_config_del to delete a variable
Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-07-05 02:31:26 +02:00
Vicent Marti
9f86ec52fa signature: Fix warnings
Add extra braces to avoid ambiguous if-else.

Also, free() doesn't need a check.
2011-07-05 02:28:18 +02:00
nulltoken
a01acc47bb signature: straighten the creation of a signature
- Fails on empty name and/or email
 - Trims leading and trailing spaces of name and email
2011-07-05 02:21:26 +02:00
nulltoken
42a1b5e1ad signature: enhance relaxed parsing of bogus signatures
Final fix for issue #278
2011-07-05 02:21:26 +02:00
schu
60caf02465 t04-commit: add tests for git_signature__parse
git_signature__parse used to be very strict about what's a well-formed
signature. Add tests checking git_signature__parse can stick with
"unexpected" signatures (IOW no author name and / or no email, etc).

Signed-off-by: schu <schu-github@schulog.org>
2011-07-05 02:21:26 +02:00
schu
8b2c913acb git_signature__parse: make parsing less strict
git_signature__parse used to be very strict about what's a well-formed
signature. Since git_signature__parse is used only when reading already
existing signatures, we should not care about if it's a valid signature
too much but rather show what we got.

Reported-by: nulltoken <emeric.fermas@gmail.com>
Signed-off-by: schu <schu-github@schulog.org>
2011-07-05 02:21:25 +02:00
Vicent Marti
1bc83ff14f repository: Cleanup initialization 2011-07-05 02:09:10 +02:00
Vicent Marti
eec3fe394a fileutils: Finish dropping the old prettify_path 2011-07-05 02:09:05 +02:00
Vicent Marti
19ac1ed702 fileops: Fix stat() on directories for W32
The `stat` methods were having issues when called with a trailing slash
in Windows platforms.

We now use GetFileAttributes() where possible, which doesn't have this
restriction.
2011-07-05 02:08:09 +02:00
Vicent Marti
5ad739e832 fileops: Drop git_fileops_prettify_path
The old `git_fileops_prettify_path` has been replaced with
`git_path_prettify`. This is a much simpler method that uses the OS's
`realpath` call to obtain the full path for directories and resolve
symlinks.

The `realpath` syscall is the original POSIX call in Unix system and
an emulated version under Windows using the Windows API.
2011-07-05 02:06:26 +02: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
Vicent Marti
678e9e045b build: Move OS-specific compat to their own folders 2011-07-03 13:33:43 +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
Tim Harder
1f4f4d1704 cmake: Use system zlib if found on non-Windows systems 2011-07-01 17:41:46 +02:00
Vicent Marti
ec62685345 zlib: Declare preprocessor directives at build time 2011-07-01 17:34:27 +02:00
Vicent Marti
17d523041d build: Simplify build structure
This will make libgit2 more suitable for embedding.
2011-07-01 17:26:23 +02:00
Vicent Marti
b2cef77ccf common: Force 64 bit fileops at compile time 2011-06-30 22:28:19 +02:00
Vicent Marti
8a0620030c zlib: No visualization attributes.
The visibility attribute is a headache on many platforms like Solaris,
and not even supported on Windows.
2011-06-30 22:28:19 +02:00
Vicent Marti
637edc9c42 refs: Remove bogus assertion
The assertion in line 360 was there to check that only loose refs were
being written as loose, but there are times when we need to re-write a
packed reference as loose.
2011-06-30 22:28:19 +02:00
Vicent Marti
e0fc39da9a config: Fix unmatched parameters in docs 2011-06-30 22:28:19 +02:00
Vicent Martí
1f61e301be Merge pull request #287 from kiryl/development
filebuf: fix endless loop on writing buf > WRITE_BUFFER_SIZE
2011-06-30 07:12:42 -07:00
Vicent Martí
02bc2d2f27 Merge pull request #288 from nulltoken/patch-4
GIT_EXTERN'd  head_detached() and head_orphan()
2011-06-30 07:11:04 -07:00
nulltoken
408d733b1f repository: Make head_detached() and head_orphan() convenience methods accessible to bindings 2011-06-30 06:56:58 -07:00
Kirill A. Shutemov
fe5babacd6 filebuf: fix endless loop on writing buf > WRITE_BUFFER_SIZE
Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
2011-06-30 16:19:19 +03:00
Vicent Martí
2dfc08875a Merge pull request #284 from nulltoken/topic/hide-git-dir
Hide ".git" directory on Windows upon creation of a non bare repository
2011-06-29 12:14:29 -07:00
nulltoken
6ac91dfe52 Hide ".git" directory on Windows upon creation of a non bare repository
Directory which name starts with a dot are hidden on Linux platforms. This patch makes libgit2 behaves similarly on Windows.
2011-06-29 19:22:24 +02:00
Vicent Marti
cfef5fb779 config: foreach now returns variable values too 2011-06-29 15:09:21 +02:00
Vicent Marti
7376ad9927 refs: Remove duplicate rename method
`git_reference_rename` now takes a `force` flag
2011-06-29 11:01:35 +02:00
Carlos Martín Nieto
5f25149e46 sig: allow empty names
Signed-off-by: Carlos Martín Nieto <carlos@cmartin.tk>
2011-06-28 22:04:27 +02:00
Vicent Marti
0f489fb211 repo: Fix git_repository_is_empty 2011-06-28 21:30:38 +02:00
Vicent Marti
ab7941b5d9 test: Properly show error messages 2011-06-28 21:10:51 +02:00