Commit Graph

159 Commits

Author SHA1 Message Date
nulltoken
1c3edb3078 tree: prevent git_tree_entry_free() from segfaulting when being passed a NULL tree_entry 2012-07-12 22:29:53 +02:00
Vicent Marti
46ea40d995 tree: Rename entry_copy to entry_dup 2012-06-29 17:08:36 +02:00
Vicent Marti
0e2fcca850 tree: Bring back entry_bypath
Smaller, simpler, faster.
2012-06-29 02:21:12 +02:00
Vicent Marti
b93688d06d Merge remote-tracking branch 'yorah/fix/notes-creation' into development
Conflicts:
	src/notes.c
2012-06-19 02:33:03 +02:00
nulltoken
b0b3b4e39e treebuilder: prevent git_treebuilder_free() from segfaulting when being passed a NULL treebuilder 2012-06-08 20:34:13 +02:00
Vicent Martí
3f0358604e misc: Fix warnings from PVS Studio trial 2012-06-07 22:43:48 +02:00
Vicent Martí
904b67e69f errors: Rename error codes 2012-05-18 01:48:50 +02:00
Vicent Martí
e172cf082e errors: Rename the generic return codes 2012-05-18 01:26:26 +02:00
Vicent Martí
9d0011fd83 tree: Naming conventions 2012-05-16 19:24:35 +02:00
Vicent Martí
cedf9ca955 tree: Kill the git_tree_diff functions
These are deprecated and replaced with the diffing code in git2/diff.h
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
Vicent Martí
3fbcac89c4 Remove old and unused error codes 2012-05-02 19:56:38 -07:00
Vicent Martí
40879facad Merge branch 'new-error-handling' into development
Conflicts:
	.travis.yml
	include/git2/diff.h
	src/config_file.c
	src/diff.c
	src/diff_output.c
	src/mwindow.c
	src/path.c
	tests-clar/clar_helpers.c
	tests-clar/object/tree/frompath.c
	tests/t00-core.c
	tests/t03-objwrite.c
	tests/t08-tag.c
	tests/t10-refs.c
	tests/t12-repo.c
	tests/t18-status.c
	tests/test_helpers.c
	tests/test_main.c
2012-05-02 15:59:02 -07:00
Vicent Martí
b88021463f Merge remote-tracking branch 'carlosmn/remaining-errors' into new-error-handling
Conflicts:
	src/refspec.c
2012-05-01 19:16:14 -07:00
nulltoken
fa6420f73e buf: deploy git_buf_len() 2012-04-30 07:12:37 +02:00
Carlos Martín Nieto
3aa351ea0f error handling: move the missing parts over to the new error handling 2012-04-26 15:38:42 +02:00
Russell Belfer
44ef8b1b30 Fix warnings on 64-bit windows builds
This fixes all the warnings on win64 except those in deps, which
come from the regex code.
2012-04-17 10:47:39 -07:00
Vicent Martí
181bbf1498 tree: Fix homing entry search 2012-03-28 19:12:13 +02:00
Vicent Martí
cb8a79617b error-handling: Repository
This also includes droping `git_buf_lasterror` because it makes no sense
in the new system. Note that in most of the places were it has been
dropped, the code needs cleanup. I.e. GIT_ENOMEM is going away, so
instead it should return a generic `-1` and obviously not throw
anything.
2012-03-07 00:11:43 +01:00
Carlos Martín Nieto
82ccb87ef6 tree: break out on write error
If write_tree() returs an error, we used to set the error message and
continued looping. Exit the loop so we return the error.
2012-02-23 23:00:45 +01:00
schu
5e0de32818 Update Copyright header
Signed-off-by: schu <schu-github@schulog.org>
2012-02-13 17:11:09 +01:00
schu
b3408e3e66 treebuilder: remove needless variable entry_count
Signed-off-by: schu <schu-github@schulog.org>
2012-02-05 14:59:45 +01:00
Carlos Martín Nieto
9269ccce14 diff-index: fix leak
The buffer wasn't getting freed if the last difference was a deletion.
2012-01-19 23:47:15 +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
Clemens Buchacher
1f783edf17 do not use full path in diff-index
Currently, diff_index passes the full relative path from the
repository root to the callback. In case of an addition, it passes
the tree entry instead of the index entry.

This change fixes the path used for addition, and it passes only
the basename of the path. This mimics the current behavior of
git_tree_diff.
2011-12-30 20:14:05 +01:00
Clemens Buchacher
a26a156349 move entry_is_tree to tree.h 2011-12-30 20:14:01 +01:00
Vicent Marti
7af26f8f58 Fix tree-diff with the new path API 2011-12-14 03:24:16 +01:00
Vicent Marti
40e73d6f88 Merge remote-tracking branch 'arrbee/git-buf-for-paths' into development
Conflicts:
	tests-clay/clay_main.c
2011-12-09 01:38:46 +01: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
Vicent Marti
e923868766 tree: recursive diff-index
Signed-off-by: Carlos Martín Nieto <carlos@cmartin.tk>
Signed-off-by: Vicent Marti <tanoku@gmail.com>

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# Author:    Carlos Martín Nieto <carlos@cmartin.tk>
#
# On branch development
# Your branch is ahead of 'origin/development' by 11 commits.
#
# Changes to be committed:
#   (use "git reset HEAD^1 <file>..." to unstage)
#
#	modified:   include/git2/tree.h
#	modified:   src/tree.c
#	modified:   tests-clay/clay_main.c
#	modified:   tests-clay/object/tree/diff.c
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#	0001-remote-Cleanup-the-remotes-code.patch
#	466.patch
#	466.patch.1
#	488.patch
#	Makefile
#	libgit2.0.15.0.dylib
#	libgit2.0.dylib
#	libgit2.dylib
#	libgit2_clay
#	libgit2_test
#	tests-clay/object/tree/
2011-12-03 18:06:34 +01:00
Carlos Martín Nieto
a1fdea2855 tree: implement tree diffing
For each difference in the trees, the callback gets called with the
relevant information so the user can fill in their own data
structures.

Signed-off-by: Carlos Martín Nieto <carlos@cmartin.tk>
2011-12-03 17:47:06 +01:00
Vicent Marti
45e79e3701 Rename all _close methods
There's no difference between `_free` and `_close` semantics: keep
everything with the same name to avoid confusions.
2011-11-26 08:48:00 +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
Vicent Marti
2ba14f2367 tree: Add payload to git_tree_walk 2011-11-18 01:40:35 +01:00
Vicent Marti
9432af36fc Rename git_tree_frompath to git_tree_get_subtree
That makes more sense to me.
2011-11-18 01:40:35 +01: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
Vicent Marti
da37654d04 tree: Add traversal in post-order 2011-10-27 22:33:31 -07:00
Vicent Marti
28c1451a7c tree: Fix name lookups once and for all
Double-pass binary search. Jeez.
2011-10-20 02:40:14 +02:00
Vicent Marti
8cf2de078d tree: Fix lookups by entry name 2011-10-19 01:34:42 +02:00
nulltoken
3fa735ca3b tree: Add git_tree_frompath() which, given a relative path to a tree entry, retrieves the tree object containing this tree entry 2011-10-13 23:30:07 +02:00
Vicent Marti
8e9bfa4cf0 tree: Fix check for valid attributes 2011-09-27 14:33:19 +02:00
Vicent Marti
9ef9e8c3ad tree: Use an internal append functiont to add new entries 2011-09-27 14:33:18 +02:00
Carlos Martín Nieto
8255c69b10 Make use of the tree cache
Taking advantage of the tree cache, git_tree_create_fromindex becomes
comparable in speed to git write-tree when the cache is available.

Signed-off-by: Carlos Martín Nieto <carlos@cmartin.tk>
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 Martí
71a4c1f16f Merge pull request #384 from kiryl/warnings
Add more -W flags to CFLAGS
2011-09-18 20:07:59 -07:00
Vicent Martí
ae996e029f Merge pull request #394 from carlosmn/tree-fromindex
Use git_treebuilder to write the index as a tree
2011-09-18 19:59:34 -07: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
Carlos Martín Nieto
4a619797ec tree: use git_treebuilder to write the index as a tree
There is no point in reinventing the wheel when using the treebuilder
is much more straightforward and makes the code more readable. There
is no optimisation, and the performance is no worse than when writing
the tree object ourselves.
2011-09-10 02:05:38 +02:00
Kirill A. Shutemov
d568d5856b CMakefile: add -Wmissing-prototypes and fix warnings
Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
2011-08-30 23:55:22 +03:00
Kirill A. Shutemov
0b2c406187 CMakefile: add -Wstrict-aliasing=2 and fix warnings
Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
2011-08-30 23:06:04 +03:00
Luc Bertrand
8f643ce8e3 Remove duplicated sort 2011-08-03 13:44:28 +02:00
Kirill A. Shutemov
0cbbdc26a9 tree: fix cast warnings
/home/kas/git/public/libgit2/src/tree.c: In function ‘entry_search_cmp’:
/home/kas/git/public/libgit2/src/tree.c:47:36: warning: cast discards ‘__attribute__((const))’ qualifier from pointer target type [-Wcast-qual]
/home/kas/git/public/libgit2/src/tree.c: In function ‘git_treebuilder_remove’:
/home/kas/git/public/libgit2/src/tree.c:443:31: 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
nulltoken
f4ad64c109 tree: fix insertion of entries with invalid filenames 2011-07-13 07:58:17 +02:00
Vicent Marti
e6629d8313 tree: More accurate matching on entries
The old matcher was returning fake matches when given stupid entry
names. E.g.

	`git2` could be matched by `git2   /`, `git2/foobar`, git2/////`
	and other stupid stuff
2011-07-13 03:36:03 +02:00
Vicent Marti
761aa2aa35 tree: Fix wrong sort order when querying entries
Fixes #127 (that was quite an outstanding issue).

Rationale:

The tree objects on Git are stored and read following a very specific
sorting algorithm that places folders before files. That original sort
was the sort we were storing on memory, but this sort was being queried
with a binary search that used a simple `strcmp` for comparison, so
there were many instances where the search was failing.

Obviously, the most straightforward way to fix this is changing the
binary search CB to use the same comparison method as the sorting CB.
The problem with this is that the binary search callback compares a path
and an entry, so there is no way to know if the given path is a folder
or a standard file.

How do we work around this? Instead of splitting the `entry_byname`
method in two (one for searching directories and one for searching
normal files), we just assume that the path we are searching for is of
the same kind as the path it's being compared at the moment.

	return git_futils_cmp_path(
		ksearch->filename, ksearch->filename_len, entry->attr & 040000,
        entry->filename, entry->filename_len, entry->attr & 040000);

Since there cannot be a folder and a regular file with the same name on
the same tree, the most basic equality check will always fail
for all comparsions, until our path is compared with the actual entry we
are looking for; in this case, the matching will succeed with the file
type of the entry -- whatever it was initially.

I hope that makes sense.

PS: While I was at it, I switched the cmp methods to use cached values
for the length of each filename. That makes searches and sorts
retardedly fast -- I was wondering the reason of the performance hiccups
on massive trees; it's because of 2*strlen for each comparsion call.
2011-07-13 02:49:47 +02:00
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
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
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
Vicent Martí
1097dacd7d Merge pull request #240 from Romain-Geissler/tree-object-type
Tree: Added a function that returns the type of a tree entry.
2011-06-06 18:33:38 -07:00
Romain Geissler
ff9a4c130d Tree: Added a function that returns the type of a tree entry. 2011-06-06 17:14:30 +02:00
Romain Geissler
c5d8745fca Tree: Some more size_t to unsigned int type change. 2011-06-06 10:55:54 +02:00
Romain Geissler
e5c8009731 Tree: API uniformasation: Use unsigned int for all index number. 2011-06-05 21:18:05 +02:00
Jakob Pfender
bc06a4eeec tree.c: Move to new error handling mechanism 2011-05-23 21:38:39 +03:00
schu
d6de92b6fe Move tree.c to the new error handling
Signed-off-by: schu <schu-github@schulog.org>
2011-05-11 12:40:04 +02:00
Sergey Nikishin
555ce56819 Fix tree-entry attribute convertion (fix corrupted trees)
Magic constant replaced by direct to-string covertion because of:
1) with value length 6 (040000 - subtree) final tree will be corrupted;
2) for wrong values length <6 final tree will be corrupted too.
2011-04-26 15:32:11 +04:00
Vicent Marti
c6e65acae6 Properly check strtol for errors
We are now using a custom `strtol` implementation to make sure we're not
missing any overflow errors.
2011-04-09 15:22:11 -07:00
Shuhei Tanuma
98ac678085 fix git_treebuilder_insert probrem.
couldn't add new entry when inserting new one with `git_treebuilder_insert`.
2011-04-08 03:30:47 +03:00
Vicent Marti
0ad6efa110 Build & write custom trees in memory 2011-04-04 19:25:33 +03:00
Vicent Marti
29e1789b34 Fix the git_tree_write implementation 2011-04-04 12:14:43 +03:00
Sarath Lakshman
47d8ec56e9 New external API method: git_tree_create
Creates a tree by scanning the index file. The method handles recursive
creation of trees for subdirectories and adds them to the parent tree.
2011-04-03 17:18:56 +05:30
Vicent Marti
720d5472f8 Change parse methods to const buffer
Signed-off-by: Vicent Marti <tanoku@gmail.com>
2011-04-02 12:42:04 +03:00
Vicent Marti
72a3fe42fb I broke your bindings
Hey. Apologies in advance -- I broke your bindings.

This is a major commit that includes a long-overdue redesign of the
whole object-database structure. This is expected to be the last major
external API redesign of the library until the first non-alpha release.

Please get your bindings up to date with these changes. They will be
included in the next minor release. Sorry again!

Major features include:

	- Real caching and refcounting on parsed objects
	- Real caching and refcounting on objects read from the ODB
	- Streaming writes & reads from the ODB
	- Single-method writes for all object types
	- The external API is now partially thread-safe

The speed increases are significant in all aspects, specially when
reading an object several times from the ODB (revwalking) and when
writing big objects to the ODB.

Here's a full changelog for the external API:

blob.h
------

	- Remove `git_blob_new`
	- Remove `git_blob_set_rawcontent`
	- Remove `git_blob_set_rawcontent_fromfile`
	- Rename `git_blob_writefile` -> `git_blob_create_fromfile`
	- Change `git_blob_create_fromfile`:
		The `path` argument is now relative to the repository's working dir
	- Add `git_blob_create_frombuffer`

commit.h
--------

	- Remove `git_commit_new`
	- Remove `git_commit_add_parent`
	- Remove `git_commit_set_message`
	- Remove `git_commit_set_committer`
	- Remove `git_commit_set_author`
	- Remove `git_commit_set_tree`

	- Add `git_commit_create`
	- Add `git_commit_create_v`
	- Add `git_commit_create_o`
	- Add `git_commit_create_ov`

tag.h
-----

	- Remove `git_tag_new`
	- Remove `git_tag_set_target`
	- Remove `git_tag_set_name`
	- Remove `git_tag_set_tagger`
	- Remove `git_tag_set_message`

	- Add `git_tag_create`
	- Add `git_tag_create_o`

tree.h
------

	- Change `git_tree_entry_2object`:
		New signature is `(git_object **object_out, git_repository *repo, git_tree_entry *entry)`

	- Remove `git_tree_new`
	- Remove `git_tree_add_entry`
	- Remove `git_tree_remove_entry_byindex`
	- Remove `git_tree_remove_entry_byname`
	- Remove `git_tree_clearentries`
	- Remove `git_tree_entry_set_id`
	- Remove `git_tree_entry_set_name`
	- Remove `git_tree_entry_set_attributes`

object.h
------------

	- Remove `git_object_new
	- Remove `git_object_write`

	- Change `git_object_close`:
		This method is now *mandatory*. Not closing an object causes a
		memory leak.

odb.h
-----

	- Remove type `git_rawobj`
	- Remove `git_rawobj_close`
	- Rename `git_rawobj_hash` -> `git_odb_hash`
	- Change `git_odb_hash`:
		New signature is `(git_oid *id, const void *data, size_t len, git_otype type)`

	- Add type `git_odb_object`
	- Add `git_odb_object_close`

	- Change `git_odb_read`:
		New signature is `(git_odb_object **out, git_odb *db, const git_oid *id)`
	- Change `git_odb_read_header`:
		New signature is `(size_t *len_p, git_otype *type_p, git_odb *db, const git_oid *id)`
	- Remove `git_odb_write`
	- Add `git_odb_open_wstream`
	- Add `git_odb_open_rstream`

odb_backend.h
-------------

	- Change type `git_odb_backend`:
		New internal signatures are as follows

			int (* read)(void **, size_t *, git_otype *, struct git_odb_backend *, const git_oid *)
			int (* read_header)(size_t *, git_otype *, struct git_odb_backend *, const git_oid *)
			int (* writestream)(struct git_odb_stream **, struct git_odb_backend *, size_t, git_otype)
			int (* readstream)( struct git_odb_stream **, struct git_odb_backend *, const git_oid *)

	- Add type `git_odb_stream`
	- Add enum `git_odb_streammode`

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2011-03-20 21:45:11 +02:00
Vicent Marti
b5c5f0f808 Fix headers for the new Revision Walker
The "oid.h" header is now included instead of "object.h".

The old "revwalk.h" header has been removed; it was empty.
2011-03-16 23:59:09 +02:00
Vicent Marti
545a6915eb Change interface for Tree Index attr (always unsigned)
Signed-off-by: Vicent Marti <tanoku@gmail.com>
2011-03-05 13:46:37 +02:00
Sakari Jokinen
9de27ad0c4 Check for valid range of attributes for tree entry 2011-03-05 13:46:27 +02:00
Vicent Marti
48c27f86bb Implement reference counting for git_objects
All `git_object` instances looked up from the repository are reference
counted. User is expected to use the new `git_object_close` when an
object is no longer needed to force freeing it.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2011-03-03 20:23:52 +02:00
Vicent Marti
86d7e1ca6f Fix searching in git_vector
We now store only one sorting callback that does entry comparison. This
is used when sorting the entries using a quicksort, and when looking for
a specific entry with the new search methods.

The following search methods now exist:

	git_vector_search(vector, entry)
	git_vector_search2(vector, custom_search_callback, key)

	git_vector_bsearch(vector, entry)
	git_vector_bsearch2(vector, custom_search_callback, key)

The sorting state of the vector is now stored internally.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2011-03-03 20:23:52 +02:00
Vicent Marti
5de079b86d Change the object creation/lookup API
The methods previously known as

	git_repository_lookup
	git_repository_newobject
	git_repository_lookup_ref

are now part of their respective namespaces:

	git_object_lookup
	git_object_new
	git_reference_lookup

This makes the API more consistent with the new references API.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2011-03-03 20:23:52 +02:00
Vicent Marti
ccef1c9dc2 Move the path comparison method to fileops.c
Signed-off-by: Vicent Marti <tanoku@gmail.com>
2011-03-03 20:23:50 +02: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
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
nulltoken
40be9ae0a8 Fixes a Win32/MSVC compilation issue. 2011-02-05 15:03:48 +01: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
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
John Wiegley
89f9fc6f4b Make git_tree_clear_entries visible to the user 2011-02-01 05:04:49 -05:00
John Wiegley
75e051c682 Added git_tree_add_entry_unsorted and git_tree_sort_entries 2011-02-01 05:04:43 -05:00
Vicent Marti
b29e8f1930 Return the created entry in git_tree_add_entry()
Yes, we are breaking the API. Alpha software, deal with it.

We need a way of getting a pointer to each newly added entry to the
index, because manually looking up the entry after creation is
outrageously expensive.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2011-01-29 02:12:59 +02:00
Vicent Marti
c8f5ff8f65 Fix initialization of in-memory trees
In-memory tree objects were not being properly initialized, because the
internal entries vector was created on the 'parse' method.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2011-01-20 14:43:27 -08:00
Vicent Marti
44908fe763 Change the library include file
Libgit2 is now officially include as

	#include "<git2.h>"

or indidividual files may be included as

	#include <git2/index.h>

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2010-12-06 23:03:16 +02:00
Vicent Marti
d12299fe22 Change include structure for the project
The maze with include dependencies has been fixed.
There is now a global include:

	#include <git.h>

The git_odb_backend API has been exposed.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2010-12-06 01:14:15 +02:00
nulltoken
6f02c3bad8 Small source code readability improvements.
Replaced magic number "0" with GIT_SUCCESS constant wherever it made sense.
2010-12-05 20:18:56 +01:00
Vicent Marti
c4034e63f3 Refactor all 'vector' functions into common code
All the operations on the 'git_index_entry' array and the
'git_tree_entry' array have been refactored into common code in the
src/vector.c file.

The new vector methods support:
	- insertion:	O(1) (avg)
	- deletion:		O(n)
	- searching:	O(logn)
	- sorting:		O(logn)
	- r. access:	O(1)

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2010-12-02 04:31:54 +02:00
Vicent Marti
1795f87952 Improve error handling
All initialization functions now return error codes instead of pointers.
Error codes are now properly propagated on most functions. Several new
and more specific error codes have been added in common.h

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2010-11-05 03:20:17 +02:00
Vicent Marti
585190183b Fix internal memory management on the library
String mememory is now managed in a much more sane manner.

Fixes include:

	- git_person email and name is no longer limited to 64 characters
	- git_tree_entry filename is no longer limited to 255 characters
	- raw objects are properly opened & closed the minimum amount of
	times required for parsing
	- unit tests no longer leak
	- removed 5 other misc memory leaks as reported by Valgrind
	- tree writeback no longer segfaults on rare ocassions

The git_person struct is no longer public. It is now managed by the
library, and getter methods are in place to access its internal
attributes.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2010-10-28 02:07:18 +03:00
Vicent Marti
e4def81aab Fix issue 3 (memory corruption resize_tree_array)
The tree array wasn't being initialized when instantiating a tree object
in memory instead of loading it from disk.

New unit tests added to check for the problem.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2010-10-08 13:52:17 +03:00
Vicent Marti
c4b5bedc97 Fix possible segfaults in src/tree.c (issue 1)
git_tree_entry_byname was dereferencing a NULL pointer when the searched
file couldn't be found on the tree.

New test cases have been added to check for entry access methods.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2010-10-07 00:14:09 +03:00
Vicent Marti
2a884588b4 Add write-back support for git_tree
All the setter methods for git_tree have been added, including the
setters for attributes on each git_tree_entry and methods to add/remove
entries of the tree.

Modified trees and trees created in-memory from scratch can be written
back to the repository using git_object_write().

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2010-09-21 17:17:10 +03:00