Commit Graph

123 Commits

Author SHA1 Message Date
Vicent Marti
1e85d1aa03 odb: Reword errors 2011-05-23 21:09:07 +03:00
Jakob Pfender
d3d5d86d4d odb.c: Move to new error handling mechanism 2011-05-23 21:05:58 +03:00
schu
12de98c1c8 Move odb.c to the new error handling
Add missing free in git_odb_new().

Signed-off-by: schu <schu-github@schulog.org>
2011-05-18 18:11:25 +02:00
Vicent Marti
7cadd1f6a7 Check error code from git_cache_init 2011-05-15 23:46:22 +03:00
Vicent Martí
3fe2e770ca Merge pull request #184 from nulltoken/repo-error-handling
Updated fileops.c and repository.c to new error handling mechanism
2011-05-15 13:34:43 -07:00
Shuhei Tanuma
71747bcae0 fix git_otype typo when calling git_odb_read_header. 2011-05-15 20:07:54 +09:00
nulltoken
81201a4c4d Move cache.c to the new error handling 2011-05-15 06:57:34 +02:00
Carlos Martín Nieto
39e1032cfc odb backend_sort_cmp should be static
Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-05-06 12:43:37 +02:00
Sergey Nikishin
411823a3d0 Fix whole buffer writing in fake wstream 2011-04-24 18:43:08 +04:00
Vicent Marti
d69d0185d1 Add a fake wstream to the ODB
Streaming writes will no longer fail when writing to a backend that
doesn't support streaming writes but supports direct ones.
Now we create a fake stream on memory and then write it as a single
block using the backend `write` callback.
2011-04-04 13:08:54 +03:00
Vicent Marti
f6f72d7ef8 Improve the ODB writing backend
Temporary files when doing streaming writes are now stored inside the
Objects folder, to prevent issues when moving files between
disks/partitions.

Add support for block writes to the ODB again (for those backends that
cannot implement streaming).
2011-03-23 18:44:53 +02:00
Vicent Marti
1881f0783b Add getters for git_odb_object 2011-03-22 20:38:33 +02: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
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
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
ec3c7a16c2 Add new Repository initialization method
Lets the user specify the ODB that will be used by the repository
manually.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2011-01-13 04:54:14 +02:00
Vicent Marti
1f080e2da4 Fix initialization & freeing of inexistent repos
Signed-off-by: Vicent Marti <tanoku@gmail.com>
2010-12-13 03:43:56 +02: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
Vicent Marti
7d7cd8857a Decouple storage from ODB logic
Comes with two default backends: loose object and packfiles.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2010-12-06 01:14:15 +02:00
Vicent Marti
86bfec39b5 Revert changes in odb.c to eventually rebase
The odb.c will disappear after the decoupling changes.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2010-12-06 01:13:09 +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
824f4acde2 Fix redeclaration warnings in MSVC
Signed-off-by: Vicent Marti <tanoku@gmail.com>
2010-11-24 00:23:15 +02:00
Vicent Marti
8b0e448f5c Removed unreachable code (MSVC warning) 2010-11-24 00:23:15 +02:00
Vicent Marti
7a3924fc38 Fix overcomplicated return statement
Note to self: don't be stupid

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2010-11-16 02:59:24 +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
adc0327ab3 Add git_odb_read_header method to the ODB
As requested, git_odb_read_header looks up an object on the ODB, but loads
only the header information (type & size) without loading any of the
actual file contents in memory.

It is significantly faster than doing a git_odb_read if you only need an
object's information and not its contents.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2010-10-29 00:44:15 +03:00
Vicent Marti
0c3596f18a Add setter methods & write support for git_commit
All the required git_commit_set_XXX methods have been implemented; all
the attributes of a commit object can now be modified in-memory.

The new method git_object_write() automatically writes back the
in-memory changes of any object to the repository. So far it only
supports git_commit objects.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2010-09-20 02:04:06 +03:00
Vicent Marti
f49a2e4981 Give object structures more descriptive names
The 'git_obj' structure is now called 'git_rawobj', since
it represents a raw object read from the ODB.

The 'git_repository_object' structure is now called 'git_object',
since it's the base object class for all objects.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2010-09-19 03:21:06 +03:00
Vicent Marti
7e4f56a5bb Add packfile reading
Packed objects inside packfiles are now properly unpacked when calling
the git_odb__read_packed() method; delta'ed objects are also properly
generated when needed.

A new unit test 0204-readpack tries to read a couple hundred packed
objects from a standard packed repository.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2010-08-06 18:37:59 +02:00
Ramsay Jones
89217d8f1a Add functions to open a '*.pack' file and perform some basic validation
Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
2010-04-30 09:48:07 +02:00
Ramsay Jones
3cc606359d Add some more (macro) file operation wrappers
Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
2010-04-30 09:47:58 +02:00
Ramsay Jones
54b9460fee Fix the memory leak caused by failing to free the 'offset index'
Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
2010-04-30 09:47:53 +02:00
Ramsay Jones
2cdc454423 Add a pack index 'virtual function' to fetch an index entry
Given an index entry number, the idx_get() function returns an
(version agnostic) index_entry structure containing all of the
information required to unpack the corresponding object from
the '.pack' file.

Since the v1 and v2 file formats differ in the layout of the
object records, we provide two implementations of the get
function and initialise the function pointer appropriately.

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
2010-02-28 20:16:30 +00:00
Ramsay Jones
608d33fa67 Add a pack index 'virtual function' to search by file offset
In addition to searching the index by oid, we need to search by
'.pack' file offset, particularly when processing OBJ_OFS_DELTA
objects. Since the v1 and v2 file formats differ in the layout
of the object records, we provide two implementations of the
search function and initialise the (virtual) function pointer
appropriately.

Note that, as part of the creation of the 'offset index', we also
add a check that the offset data in the index is within the bounds
of the '.pack' file. Having sorted the file offsets, while creating
the index, we only need to check the smallest and largest values.

The offset index consists of the im_off_idx array, which contains
the index entry numbers sorted into file offset order, and the
im_off_next mapping array. The im_off_next array maps an index
entry number to the 'next' index entry in file offset order.

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
2010-02-28 20:13:29 +00:00
Ramsay Jones
abf5681c03 Change the interface of the pack index search function
In particular, on a successful search, we now return the index
entry number of the object rather than the '.pack' file offset.

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
2010-02-28 20:12:32 +00:00
Ramsay Jones
238e54bcff Add an 64-bit offset table index bounds check for v2 pack index
Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
2010-02-28 20:12:04 +00:00
Ramsay Jones
255a0dabb2 Add a minimum size check when opening an v2 pack index file
Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
2010-02-28 20:11:33 +00:00
Ramsay Jones
1e5dd57214 Fix some coding style issues
Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
2010-02-28 20:09:45 +00:00
Ramsay Jones
e8a952561c msvc: Fix some -W4 warnings
Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
2010-01-20 20:20:47 +00:00
Ramsay Jones
1a7bae4d0f Fix some "unused parameter" warnings with -Wextra
Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
2010-01-20 20:19:55 +00:00
Ramsay Jones
0ef9d2aa93 Fix some "signed v unsigned comparison" warnings with -Wextra
Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
2010-01-20 20:18:36 +00:00
Ramsay Jones
a4f863af4d Fix an always false comparison "unsigned < 0" warning
Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
2010-01-20 20:18:15 +00:00
Ramsay Jones
8a086f872a win32: Add support for the MS Visual C/C++ compiler
Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
2009-06-15 07:34:28 +02:00
Ramsay Jones
2bf93fa107 Correct the spelling of the FLEX_ARRAY macro
When setting the default value, the macro name was specified
as GIT_FLEX_ARRAY, which is inconsistent with it's earlier
usage in the file. This caused a compilation error, using the
MS Visual C/C++ compiler, when compiling the git_packlist
struct definition in src/odb.c.

In addition to changing the spelling of the FLEX_ARRAY macro
to GIT_FLEX_ARRAY, including it's use in src/odb.c, we also
rename the TYPEOF macro to GIT_TYPEOF.

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
2009-06-15 07:33:44 +02:00
Ramsay Jones
e17a3f5673 Implement git_odb_write()
Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Andreas Ericsson <ae@op5.se>
2009-06-05 10:22:20 +02:00
Ramsay Jones
ac04bdf6e0 Fix a usage error in a call to the object_file_name() function
In 82324ac, the new static function exists_loose() called
object_file_name() and, in order to detect an error return,
tested for a negative value. This usage is incorrect, as
the error return is indicated by a positive return value.
(A successful call is indicated by a zero return value)

The only error return from object_file_name() relates to
insufficient buffer space and the return value gives the
required minimum buffer size (which will always be >0).

If the caller requires a dynamically allocated buffer,
this allows something like the following call sequence:

    size_t len = object_file_name(NULL, 0, db->object_dir, id);
    char *buf = git__malloc(len);
    if (!buf)
        error(...);
    object_file_name(buf, len, db->object_dir,id);
    ...

No current callers take advantage of this capability.

Fix up the call site and change the return type of the
function, from int to size_t, which more accurately
reflects the implementation.

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Andreas Ericsson <ae@op5.se>
2009-06-05 10:21:11 +02:00
Ramsay Jones
79ca2edcd4 win32: Add routines to abstract memory-mapped file functions
In particular, the git__mmap() and git__munmap() routines provide
the interface to platform specific memory-mapped file facilities.
We provide implementations for unix and win32, which can be found
in their own sub-directories.

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2009-03-20 14:39:02 -07:00
Ramsay Jones
840fb8b7cb win32: fixup some headers to improve win32 compilation
Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2009-03-17 19:00:08 -07:00
Ramsay Jones
a9984a4e60 Fix some (digital-mars) compiler warnings
In particular, conditional expressions which contain an
assignment statement, where the expression type is not
explicitly made to be boolean, elicits the following
message:
    warning 2: possible unintended assignment

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2009-03-17 18:59:26 -07:00
Ramsay Jones
82324ac1a5 Add the git_odb_exists() object query function
This function determines if the given object can be found
in the object database. At present, only the local object
database is searched.

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2009-02-11 11:04:55 -08:00
Ramsay Jones
e9f5e87781 Rearrange some code to improve clarity
In particular, the test for z-stream input completion
(zs.avail_in != 0) logically belongs with the test for
the Z_STREAM_END stream status. This is also consistent
with the identical check in finish_inflate().

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2009-02-11 10:47:03 -08:00
Ramsay Jones
236e7579fe Check for error returns from inflateInit()
At present, it is sufficient to ensure that an error return
from inflateInit() is not ignored. Most error returns, like
Z_VERSION_ERROR and Z_STREAM_ERROR, indicate programming or
build errors. These errors could, perhaps, be handled with
simple asserts. However, for a Z_MEM_ERROR, we may want to
perform some further error handling in the future.

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2009-02-11 10:46:29 -08:00
Ramsay Jones
c94eb4aa76 Fix a potential memory leak
In particular, neglecting to call inflateEnd() along various
codepaths in the inflate_tail() routine, would result in the
failure to release zlib internal state.

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2009-02-11 10:45:50 -08:00
Shawn O. Pearce
bed3229b55 Precompute the fanout decoding and the oid offset in a pack-*.idx
The fanout table is fairly commonly accessed, we need to read it
twice for each object we lookup in any given pack file.  Most of
the processors running Git are running in little-endian mode, as
they are variants of the x86 platform, so reading the fanout is
a costly operation as we need to convert from network byte order
to local byte order.  By decoding the fanout table into a malloc
obtained buffer we can save these 2 decode operations per lookup
and make search go more quickly.

This also cleans up the initialization of the search functions
by cutting out a few instructions, saving a small amount of time.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2009-01-03 03:34:09 -08:00
Shawn O. Pearce
a7c60cfc6d Add basic support to read pack-*.idx v1 and v2 files
The index data is mapped into memory and then scanned using a
binary search algorithm to locate the matching entry for the
supplied git_oid.  The standard fanout hash trick is applied to
reduce the search space by 8 iterations.

Since the v1 and v2 file formats differ in their search function,
due to the different layouts used for the object records, we use
two different search implementations and a virtual function pointer
to jump to the correct version of code for the current pack index.
The single function jump per-pack should be faster then computing
a branch point inside the inner loop of a common binary search.

To improve concurrency during read operations the pack lock is only
held while verifying the index is actually open, or while opening
the index for the first time.  This permits multiple concurrent
readers to scan through the same index.

If an invalid index file is opened we close it and mark the
git_pack's invalid bit to true.  The git_pack structure is kept
around in its parent git_packlist, but the invalid bit will cause
all future readers to skip over the pack entirely.  Pruning the
invalid entries is relatively unimportant because they shouldn't
be very common, a $GIT_DIRECTORY/objects/pack directory tends to
only have valid pack files.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2009-01-03 02:56:16 -08:00
Shawn O. Pearce
098ac57a13 Refactor pack memory management and locking to be safer
Using an atomic reference counter is difficult to make
cross-platform, as the reference count implementations
are generally processor specific.  Its also hard to do
a proper multi-read/single-write implementation.

We now use a simple mutex around the reference count for the list
of packs.  Readers grab the mutex and either build the list, or
increment the existing one's reference count.  When the reader is
done with the list, the reference count is decremented.  In this way
parallel readers are able to operate on the list without worrying
about it being deallocated out from under them.

Individual pack structures are held by reference counts, but we
only care about the list the pack structure is held in.  There is
no need to increment/decrement the pack reference counts as we
scan through them during a read operation, the caller holds the
git_packlist and that is sufficient to hold the packs it references.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2009-01-03 00:02:25 -08:00
Ramsay Jones
3a33c7b37f Fix snprintf compiler warning on cygwin
As far as gcc is concerned, the "z size specifier" is available as
an extension to the language, which is available with or without any
-std= switch.  (I think you have to go back to 2.95 for a version
of gcc which doesn't work.)  Many other compilers have this as an
extension as well (ie without the equivalent of -std=c99).

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2009-01-02 21:53:47 -08:00
Shawn O. Pearce
b438016ecd Find pack files in $GIT_DIR/objects/pack directory on git_odb_open
Currently we only catalog the available pack files into a table,
storing their path names relative to the pack directory.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2008-12-31 16:20:05 -08:00
Shawn O. Pearce
5614dc18f6 Add basic locking to the git_odb structure
We grab the lock while accessing the alternates list, ensuring that
we only initialize it once for the given git_odb.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2008-12-31 13:37:00 -08:00
Shawn O. Pearce
d44cfd460e Cleanup our header inclusion order to ensure pthread.h is early
If we are using threads we need to make sure pthread.h comes
in before just about anything else.  Some platforms enable
macros that alter what other headers define.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2008-12-31 13:16:31 -08:00
Shawn O. Pearce
64a47c0142 Wrap malloc and friends and report out of memory as GIT_ENOMEM
We now forbid direct use of malloc, strdup or calloc within the
library and instead use wrapper functions git__malloc, etc. to
invoke the underlying library malloc and set git_errno to a no
memory error code if the allocation fails.

In the future once we have pack objects in memory we are likely
to enhance these routines with garbage collection logic to purge
cached pack data when allocations fail.  Because the size of the
function will grow somewhat large, we don't want to mark them for
inline as gcc tends to aggressively inline, creating larger than
expected executables.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2008-12-30 23:28:30 -08:00
Shawn O. Pearce
ffb55c532c Rename the path of the objects directory to be more specific
We're likely to add additional path data, like the path of the
refs or the path to the config file into the git_odb structure,
as it may grow into the repository wrapper.  Changing the name
of the objects directory reference makes it more clear should
we later add something else.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2008-12-30 22:29:04 -08:00
Shawn O. Pearce
4c67e2e95f Change git_odb__read_packed to return ENOTFOUND until implemented
We didn't search for the object, so we cannot possibly promise it
to the caller of git_odb_read().

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2008-12-30 22:25:30 -08:00
Shawn O. Pearce
064301cc35 Fix size_t snprintf warning by using PRIuPTR format macro
This is the correct C99 format code for the size_t type when passed
as an argument to the *printf family.  If the platform doesn't
define it, we assume %lu and just cross our fingers that its the
proper setting for a size_t on this system.  On most sane platforms,
"unsigned long" is the underlying type of "size_t".

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2008-12-30 22:07:56 -08:00
Ramsay Jones
c960d6a3f9 Add a routine to determine a git_oid given an git_obj
Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2008-12-30 07:52:55 -08:00
Ramsay Jones
3d3552e8fd Implement git_odb__read_loose()
Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2008-12-19 07:23:00 -08:00
Ramsay Jones
7b6e8067ec Add some git_otype string conversion and testing routines
Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2008-12-10 11:49:06 -08:00
Andreas Ericsson
dff79e27d3 Rename "git_sobj" "git_obj"
The 's' never really made sense, since it's not a "small"
object at all, but rather a plain object. As such, it should
have a "plain" object name.

Signed-off-by: Andreas Ericsson <ae@op5.se>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2008-11-18 10:32:53 -08:00
Shawn O. Pearce
1699efc421 Implement some of the basic git_odb open and close API
Far from being complete, but its a good start.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2008-11-03 18:52:32 -08:00
Shawn O. Pearce
50298f44a4 Switch the license from BSD to GPL+libgcc exception
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2008-11-01 15:55:47 -07:00
Shawn O. Pearce
d1ea30c399 Move include files to include/git/, drop git_ prefix from file names
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2008-11-01 15:42:23 -07:00