Commit Graph

1171 Commits

Author SHA1 Message Date
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
Vicent Marti
87d82994be Make the test return an error code on failure
Signed-off-by: Vicent Marti <tanoku@gmail.com>
2011-02-02 02:32:21 +02:00
Vicent Marti
b02c371ee9 Build the new test file with CMake too
Signed-off-by: Vicent Marti <tanoku@gmail.com>
2011-02-02 02:31:58 +02:00
Vicent Marti
2a1732b439 Rewrite the unit testing suite
NIH Enterprises presents: a new testing system based on CuTesT, which is
faster than our previous one and fortunately uses no preprocessing on
the source files, which means we can run that from CMake.

The test suites have been gathered together into bigger files (one file
per suite, testing each of the different submodules of the library).

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2011-02-02 02:15:25 +02:00
John Wiegley
bf3389b930 Fixed bug where git__source_printf needs multiple attempts 2011-02-01 05:57:45 -05:00
John Wiegley
9217bbda49 Fixed a bug with the way commits are written 2011-02-01 05:04:49 -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
b70e4f8a03 Add required includes in "oid.h"
The file was previously failing to be included stand-alone.
2011-02-01 03:21:53 +02:00
Vicent Marti
2f8a8ab24b Refactor reference parsing code
Several changes have been committed to allow the user to create
in-memory references and write back to disk. Peeling of symbolic
references has been made explicit. Added getter and setter methods for
all attributes on a reference. Added corresponding documentation.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2011-01-30 02:35:29 +02:00
nulltoken
9282e921a3 Merge nulltoken's reference parsing code
All the commits have been squashed into a single one before refactoring
the final code, to keep everything tidy.

Individual commit messages are as follows:

Added repository reference looking up functionality placeholder.

Added basic reference database definition and caching infrastructure.

Removed useless constant.

Added GIT_EINVALIDREFNAME error and description. Added missing description for GIT_EBAREINDEX.

Added GIT_EREFCORRUPTED error and description.

Added GIT_ETOONESTEDSYMREF error and description.

Added resolving of direct and symbolic references.

Prepared the packed-refs parsing.

Added parsing of the packed-refs file content.

When no loose reference has been found, the full content of the packed-refs file is parsed. All of the new (i.e. not previously parsed as a loose reference) references are eagerly stored in the cached references storage.

The method packed_reference_file__parse() is in deer need of some refactoring. :-)

Extracted to a method the parsing of the peeled target of a tag.

Extracted to a method the parsing of a standard packed ref.

Fixed leaky removal of the cached references.

Ensured that a previously parsed packed reference isn't returned if a more up-to-date loose reference exists.

Enhanced documentation of git_repository_reference_lookup().

Moved some refs related constants from repository.c to refs.h.

Made parsing of a packed tag reference more robust.

Updated git_repository_reference_lookup() documentation.

Added some references to the test repository.

Added some tests covering tag references looking up.

Added some tests covering symbolic and head references looking up.

Added some tests covering packed references looking up.
2011-01-29 03:39:02 +02:00
nulltoken
f2c2471389 Made path prettifying functions return GIT_EINVALIDPATH instead of GIT_ERROR. 2011-01-29 03:29:41 +02:00
nulltoken
2e6fd09c5d Fixed naming convention related issue. 2011-01-29 03:29:33 +02:00
nulltoken
eb2f3b4790 Made git_repository_open2() and git_repository_open3() benefit from recently added path prettifying function. 2011-01-29 03:29:32 +02:00
nulltoken
618818dcb7 Added git_prettify_file_path(). 2011-01-29 03:29:32 +02:00
nulltoken
4581c22abc Optimized git_prettify_dir_path() parsing. 2011-01-29 03:29:32 +02:00
nulltoken
9dd34b1e89 Made git_repository_open() and git_repository_init() benefit from recently added path prettifying function. 2011-01-29 03:29:32 +02:00
nulltoken
ae7ffea961 Fixed a parsing issue in git_prettify_dir_path(). 2011-01-29 03:29:32 +02: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
37c2d54c85 Fix compilation on MinGW
Require <sys/types.h> to find the definition for off64_t.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2011-01-20 15:57:13 -08: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
nulltoken
e16c2f6a4c Small enhancements to git_prettify_dir_path().
- Secured buffer ahead reading.
 - Guard against potential multiple dot path traversal (cf http://cwe.mitre.org/data/definitions/33.html)
2011-01-20 13:03:49 -08:00
Vicent Marti
e08b246cec Fix signed/unsigned comparison warning
Signed-off-by: Vicent Marti <tanoku@gmail.com>
2011-01-19 17:20:39 -08:00
Vicent Marti
b5e567b9fc Merge branch 'dir-path-prettifying' of https://github.com/nulltoken/libgit2 2011-01-19 17:18:01 -08:00
Sascha Peilicke
2d5ef6ad0d Set proper shared library soname. 2011-01-18 21:35:57 +01: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
c5846fbf24 Fix typo on Commit API
Proper function is 'git_commit_time_offset'.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2011-01-13 04:34:23 +02:00
Vicent Marti
e52e38d380 Move the compat definitions to types.h
Don't need a brand new header for two typedefs when we already have a
types.h header.

Change comment style to ANSI C.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2011-01-12 01:44:06 +02:00
nulltoken
170d3f2fbb Added git_prettify_dir_path().
Clean up a provided absolute or relative directory path.

This prettification relies on basic operations such as coalescing multiple forward slashes into a single slash, removing '.' and './' current directory segments, and removing parent directory whenever '..' is encountered. If not empty, the returned path ends with a forward slash.

For instance, this will turn "d1/s1///s2/..//../s3" into "d1/s3/".

This only performs a string based analysis of the path. No checks are done to make sure the path actually makes sense from the file system perspective.
2011-01-11 20:12:53 +01:00
Alex Budovski
f0bde7fac0 Revised platform types to use 'best supported' size.
This will allow graceful migration to 64 bit file sizes and timestamps should
git's binary interface be extended to allow this.
2011-01-11 18:31:55 +11:00
Alex Budovski
e0c23b88c5 Remove unused variable. 2011-01-11 17:52:45 +11:00
Alex Budovski
0a3bcad07e Fix Windows build with forced bit truncation.
Windows uses a 64 bit time_t by default and assigning to unsigned int causes a
64 -> 32 bit truncation warning. This change forces the truncation,
acknowledging the implications detailed in the file comments. Also, blobs are
limited to 32 bit file sizes for the same reason (on all platforms).
2011-01-10 15:12:29 +11:00
Vicent Marti
073fa81241 Use generic types in git_index_entry
Off_t is not cool. It can be 32 or 64 bits depending on the platform,
but on the Index format, it's always 32 bits.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2011-01-10 05:01:38 +02:00
Vicent Marti
0740b462da Merge branch 'master' of https://github.com/Neopallium/libgit2 2011-01-08 22:24:28 +02:00
Alex Budovski
a17777d161 Fixed two buffer handling errors in vector.c
- remove() would read one-past array bounds.
- resize() would fail if the initial size was 1, because it multiplied by 1.75
  and truncated the resulting value. The buffer would always remain at size 1,
  but elements would repeatedly be appended (via insert()) causing a crash.
2011-01-08 22:17:52 +02:00
Alex Budovski
9ace34c8de Revised build configuration for MSVC.
Major changes and rationale:
- /WX: absolutely vital when compiling in C-mode as the compiler is
  incredibly lenient on what is allowed to compile. It allows functions to be
  called without prototypes declared, treating them as functions returning int
  taking an unspecified (read: unrestricted) list of arguments, without any
  type checking! It will simply issue a warning, which is easily overlooked.

  A real example: it will allow you to call ceil(1.75) without first including
  <math.h> causing UB, returning bogus results like 1023 on the machine I
  tested on.

- Release build separate from debug.
  Presently release builds don't exist.  Consequently they are completely
  untested. Many bugs may only manifest themselves in release mode. The current
  configuration sets debug-only flags like /RTC1 which are incompatible with
  optimization (/O2).

  In addition, the Windows build of libgit2 has no optimized version. This
  change resolves this.

- Added checksum generation in image headers. This is so debuggers don't
  complain about checksum mismatches and provides a small amount of consistency
  to binaries.
2011-01-08 22:17:01 +02:00