Commit Graph

24 Commits

Author SHA1 Message Date
schu
ec9079443c test_helpers: do not rely on assert
The functions loose_object_mode and loose_object_dir_mode call stat
inside an assert statement which isn't evaluated when compiling in
Release mode (NDEBUG) and leads to failing tests. Replace it.

Signed-off-by: schu <schu-github@schulog.org>
2011-10-30 13:48:00 +01:00
Vicent Martí
89fb8f025a Merge pull request #456 from brodie/perm-fixes
Create objects, indexes, and directories with the right file permissions
2011-10-28 19:04:23 -07: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
Brodie Rao
252840a59f tests: propagate errors from open_temp_repo() instead of exiting
This makes it slightly easier to debug test failures when one test
opens a repo, has a failure, and doesn't get a chance to close it for
the next test. Now, instead of getting no feedback, we at least see
test failure information.
2011-10-14 16:20:23 -07:00
Brodie Rao
01ad7b3a9e *: correct and codify various file permissions
The following files now have 0444 permissions:

- loose objects
- pack indexes
- pack files
- packs downloaded by fetch
- packs downloaded by the HTTP transport

And the following files now have 0666 permissions:

- config files
- repository indexes
- reflogs
- refs

This brings libgit2 more in line with Git.

Note that git_filebuf_commit() and git_filebuf_commit_at() have both
gained a new mode parameter.

The latter change fixes an important issue where filebufs created with
GIT_FILEBUF_TEMPORARY received 0600 permissions (due to mkstemp(3)
usage). Now we chmod() the file before renaming it into place.

Tests have been added to confirm that new commit, tag, and tree
objects are created with the right permissions. I don't have access to
Windows, so for now I've guarded the tests with "#ifndef GIT_WIN32".
2011-10-14 16:07:47 -07:00
Brodie Rao
ce8cd006ce fileops/repository: create (most) directories with 0777 permissions
To further match how Git behaves, this change makes most of the
directories libgit2 creates in a git repo have a file mode of
0777. Specifically:

- Intermediate directories created with git_futils_mkpath2file() have
  0777 permissions. This affects odb_loose, reflog, and refs.

- The top level folder for bare repos is created with 0777
  permissions.

- The top level folder for non-bare repos is created with 0755
  permissions.

- /objects/info/, /objects/pack/, /refs/heads/, and /refs/tags/ are
  created with 0777 permissions.

Additionally, the following changes have been made:

- fileops functions that create intermediate directories have grown a
  new dirmode parameter. The only exception to this is filebuf's
  lock_file(), which unconditionally creates intermediate directories
  with 0777 permissions when GIT_FILEBUF_FORCE is set.

- The test runner now sets the umask to 0 before running any
  tests. This ensurses all file mode checks are consistent across
  systems.

- t09-tree.c now does a directory permissions check. I've avoided
  adding this check to other tests that might reuse existing
  directories from the prefabricated test repos. Because they're
  checked into the repo, they have 0755 permissions.

- Other assorted directories created by tests have 0777 permissions.
2011-10-14 16:04:34 -07:00
Vicent Marti
c63aa49459 test: Abort when the temp workdir cannot be created 2011-07-07 02:54:07 +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
nulltoken
1b938a5826 Remove duplicated recursive directory removal related code 2011-07-06 12:25:27 +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
nulltoken
29e1797c14 Add remove_placeholders() test helper function which recursively removes marker files from a directory structure 2011-03-23 00:25:04 +02:00
nulltoken
f428ae615b Slightly enforce copy_recurs() behavior
The folder creation is now decorrelated from the recursive parsing of the source tree structure.
2011-03-23 00:25:04 +02:00
Vicent Marti
3dccfed163 Cleanup the testing toolkit
Tests are now declared with detailed descriptions and a short test name:

	BEGIN_TEST(the_test0, "this is an example test that does something")
		...
	END_TEST

Modules are declared through a simple macro interface:

	BEGIN_MODULE(mod_name)
		ADD_TEST(the_test0);
		...
	END_MODULE

Error messages when tests fail have been greatly improved.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2011-03-03 20:23:52 +02:00
nulltoken
e4029c5201 Added copydir_recurs() to test_helpers.c
Test helper function which recursively copies the content of a
directory. This function has been tweaked to prevent stack overflows by
reusing the same path buffers on all recursive calls.
2011-03-03 20:23:51 +02:00
nulltoken
3b3a10176e Added rmdir_recurs(), a test helper function which recursively removes the content of a directory. 2011-03-03 20:23:50 +02:00
Vicent Marti
4378e8d470 Add unit test for writing a big index file
Signed-off-by: Vicent Marti <tanoku@gmail.com>
2011-02-22 15:19:35 +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
6fd195d76c Change git_repository initialization to use a path
The constructor to git_repository is now called

	'git_repository_open(path)'

and takes a path to a git repository instead of an existing ODB object.
Unit tests have been updated accordingly and the two test repositories
have been merged into one.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2010-11-02 18:42:42 +02:00
Vicent Marti
0ba7a03186 Add unit tests for object write-back
Basic write-back & in-memory editing for objects is now tested in t0403
(commits), t0802 (tags) and t0902 (trees).

Add new helper functions in test_helpers.c to remove the loose objects
created when doing write-back tests.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2010-10-07 00:42:55 +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
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
cfe3a027ab Use a 64 bit off_t throughout the library and tests on POSIX
Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
2010-01-20 20:13:07 +00:00
Julio Espinoza-Sokal
491442f97e Factor out test helper methods for creating/deleting loose objects
Signed-off-by: Julio Espinoza-Sokal <julioes@gmail.com>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2009-03-17 19:06:37 -07:00