Commit Graph

101 Commits

Author SHA1 Message Date
Russell Belfer
3fe046cfdb Add BARE option to git_repository_open_ext
This adds a BARE option to git_repository_open_ext which allows
a fast open path that still knows how to read gitlinks and to
search for the actual .git directory from a subdirectory.

`git_repository_open_bare` is still simpler and faster, but having
a gitlink aware fast open is very useful for submodules where we
want to quickly be able to peek at the HEAD and index data without
doing any other meaningful repo operations.
2013-07-10 12:14:13 -07:00
Russell Belfer
d2ce27dd49 Add public API for pathspec matching
This adds a new public API for compiling pathspecs and matching
them against the working directory, the index, or a tree from the
repository.  This also reworks the pathspec internals to allow the
sharing of code between the existing internal usage of pathspec
matching and the new external API.

While this is working and the new API is ready for discussion, I
think there is still an incorrect behavior in which patterns are
always matched against the full path of an entry without taking
the subdirectories into account (so "s*" will match "subdir/file"
even though it wouldn't with core Git).  Further enhancements are
coming, but this was a good place to take a functional snapshot.
2013-07-10 20:50:31 +02:00
Russell Belfer
114f5a6c41 Reorganize diff and add basic diff driver
This is a significant reorganization of the diff code to break it
into a set of more clearly distinct files and to document the new
organization.  Hopefully this will make the diff code easier to
understand and to extend.

This adds a new `git_diff_driver` object that looks of diff driver
information from the attributes and the config so that things like
function content in diff headers can be provided.  The full driver
spec is not implemented in the commit - this is focused on the
reorganization of the code and putting the driver hooks in place.

This also removes a few #includes from src/repository.h that were
overbroad, but as a result required extra #includes in a variety
of places since including src/repository.h no longer results in
pulling in the whole world.
2013-06-10 10:10:39 -07:00
Russell Belfer
cee695ae6b Make iterators use GIT_ITEROVER & smart advance
1. internal iterators now return GIT_ITEROVER when you go past the
   last item in the iteration.
2. git_iterator_advance will "advance" to the first item in the
   iteration if it is called immediately after creating the
   iterator, which allows a simpler idiom for basic iteration.
3. if git_iterator_advance encounters an error reading data (e.g.
   a missing tree or an unreadable file), it returns the error
   but also attempts to advance past the invalid data to prevent
   an infinite loop.

Updated all tests and internal usage of iterators to account for
these new behaviors.
2013-05-31 12:18:43 -07:00
Vicent Martí
4811c1500b Merge pull request #1603 from ben/shallow
Shallow-clone detection
2013-05-24 01:14:52 -07:00
Russell Belfer
3b32b6d3cc More tests of config with various absent files
Plus a bit of extra paranoia to ensure config object has valid
contents.
2013-05-23 15:57:52 -07:00
Ben Straub
93d8f77fed Improve test failure output 2013-05-23 15:35:50 -07:00
Russell Belfer
3d1c9f612d Fix git_repository_message docs
This clarifies the docs for git_repository_message and also adds
to the tests to explicitly check NUL termination of data when the
output buffer is smaller than the message size.  There is a minor
behavior change so that a non-NULL output buffer will always be
NUL terminated (at length zero) if an error occurs.
2013-05-09 06:45:06 -07:00
Carlos Martín Nieto
a4b75dcf56 repo: unconditionally create a global config backend
When a repository is initialised, we need to probe to see if there is
a global config to load. If this is not the case, the user isn't able
to write to the global config without creating the backend and adding
it themselves, which is inconvenient and overly complex.

Unconditionally create and add a backend for the global config file
regardless of whether it exists as a convenience for users.

To enable this, we allow creating backends to files that do not exist
yet, changing the semantics somewhat, and making some tests invalid.
2013-05-07 21:42:56 +02:00
Russell Belfer
0a1755c045 Catch issue in config set with no config file
This prevents a segfault when setting a value in the config of a
repository that doesn't have a config file.
2013-04-30 03:15:45 -07:00
Carlos Martín Nieto
05b179648a Make refcounting atomic 2013-04-22 17:12:11 +02:00
Russell Belfer
1384b688d0 Move some low-level repo fns to include/git2/sys 2013-04-21 11:50:56 -07:00
Russell Belfer
9ea29c8f1d Fix fs iterator test on case sensitive fs 2013-04-18 14:59:25 -07:00
Russell Belfer
2aee1aa416 Fix uninitialized var warnings 2013-04-18 14:59:25 -07:00
Russell Belfer
627d590819 More filesystem iterator tests
Refactors the helper function that builds a directory hierarchy
and then made use of it to try more variations on filesystem
iterator tests.
2013-04-18 14:59:25 -07:00
Russell Belfer
ff0ddfa4bb Add filesystem iterator variant
This adds a new variant iterator that is a raw filesystem iterator
for scanning directories from a root.  There is still more work to
do to blend this with the working directory iterator.
2013-04-18 14:59:24 -07:00
Russell Belfer
1323c6d180 Add cl_repo_set_bool and cleanup tests
This adds a helper function for the cases where you want to
quickly set a single boolean config value for a repository.
This allowed me to remove a lot of code.
2013-03-22 14:27:56 -07:00
Russell Belfer
d85296ab9b Fix valgrind issues (and mmap fallback for diff)
This fixes a number of issues identified by valgrind - mostly
missed free calls.  Inside valgrind, mmap() may fail which causes
some of the diff tests to fail.  This adds a fallback code path
to diff_output.c:get_workdir_content() where is the mmap() fails
the code will now try to read the file data directly into allocated
memory (which is what it would do if the data needed to be filtered
anyhow).
2013-03-14 13:50:54 -07:00
Russell Belfer
bbb1364671 Fix workdir iterator bugs
This fixes two bugs with the workdir iterator depth check: first
that the depth was not being decremented and second that empty
directories were counting against the depth even though a frame
was not being created for them.

This also fixes a bug with the ENOTFOUND return code for workdir
iterators when you attempt to advance_into an empty directory.
Actually, that works correctly, but it was incorrectly being
propogated into regular advance() calls in some circumstances.

Added new tests for the above that create a huge hierarchy on
the fly and try using the workdir iterator to traverse it.
2013-03-13 14:59:51 -07:00
Russell Belfer
a5eea2d7b7 Stabilize order for equiv tree iterator entries
Given a group of case-insensitively equivalent tree iterator
entries, this ensures that the case-sensitively first trees will
be used as the representative items.  I.e. if you have conflicting
entries "A/B/x", "a/b/x", and "A/b/x", this change ensures that
the earliest entry "A/B/x" will be returned.  The actual choice
is not that important, but it is nice to have it stable and to
have it been either the first or last item, as opposed to a
random item from within the equivalent span.
2013-03-11 11:31:50 -07:00
Russell Belfer
aec4f6633c Fix tree iterator advance using wrong name compare
Tree iterator advance was moving forward without taking the
filemode of the entries into account, equating "a" and "a/".
This makes the tree entry comparison code more easily reusable
and fixes the problem.
2013-03-11 10:37:12 -07:00
Russell Belfer
92028ea585 Fix tree iterator path for tree issue + cleanups
This fixes an off by one error for generating full paths for
tree entries in tree iterators when INCLUDE_TREES is set.  Also,
contains a bunch of small code cleanups with a couple of small
utility functions and macro changes to eliminate redundant code.
2013-03-11 09:53:49 -07:00
Russell Belfer
61c7b61e6f Use correct case path in icase tree iterator
If there are case-ambiguities in the path of a case insensitive
tree iterator, it will now rewrite the entire path when it gives
the path name to an entry, so a tree with "A/b/C/d.txt" and
"a/B/c/E.txt" will give the true full paths (instead of case-
folding them both to "A/B/C/d.txt" or "a/b/c/E.txt" or something
like that.
2013-03-10 22:38:53 -07:00
Russell Belfer
a03beb7ba6 Add tests for case insensitive tree iterator
This adds a test case for ci tree iteration when there is a name
conflict.  This points out a behavior quirk in the current version
that I'd like to fix - namely, all tree entries get mapped to one
version of the case pattern in the ci code - i.e. even if you have
A/1.txt and a/2.txt, both will be reported as a/1.txt and a/2.txt
because we only copy the name of a file at a given frame once. It
would be nice to fix this, but I'm worried about how complex that
is if you get a/B/c/1.txt and A/b/C/2.txt.  It may require a walk
up the frames whenever you advance to the next item in a blended
equivalence class.
2013-03-10 21:04:35 -07:00
Russell Belfer
e40f1c2d23 Make tree iterator handle icase equivalence
There is a serious bug in the previous tree iterator implementation.
If case insensitivity resulted in member elements being equivalent
to one another, and those member elements were trees, then the
children of the colliding elements would be processed in sequence
instead of in a single flattened list.  This meant that the tree
iterator was not truly acting like a case-insensitive list.

This completely reworks the tree iterator to manage lists with
case insensitive equivalence classes and advance through the items
in a unified manner in a single sorted frame.

It is possible that at a future date we might want to update this
to separate the case insensitive and case sensitive tree iterators
so that the case sensitive one could be a minimal amount of code
and the insensitive one would always know what it needed to do
without checking flags.

But there would be so much shared code between the two, that I'm
not sure it that's a win.  For now, this gets what we need.

More tests are needed, though.
2013-03-08 16:39:57 -08:00
Russell Belfer
9bea03ce77 Add INCLUDE_TREES, DONT_AUTOEXPAND iterator flags
This standardizes iterator behavior across all three iterators
(index, tree, and working directory).  Previously the working
directory iterator behaved differently from the other two.

Each iterator can now operate in one of three modes:

1. *No tree results, auto expand trees* means that only non-
   tree items will be returned and when a tree/directory is
   encountered, we will automatically descend into it.
2. *Tree results, auto expand trees* means that results will
   be given for every item found, including trees, but you
   only need to call normal git_iterator_advance to yield
   every item (i.e. trees returned with pre-order iteration).
3. *Tree results, no auto expand* means that calling the
   normal git_iterator_advance when looking at a tree will
   not descend into the tree, but will skip over it to the
   next entry in the parent.

Previously, behavior 1 was the only option for index and tree
iterators, and behavior 3 was the only option for workdir.

The main public API implications of this are that the
`git_iterator_advance_into()` call is now valid for all
iterators, not just working directory iterators, and all the
existing uses of working directory iterators explicitly use
the GIT_ITERATOR_DONT_AUTOEXPAND (for now).

Interestingly, the majority of the implementation was in the
index iterator, since there are no tree entries there and now
have to fake them.  The tree and working directory iterators
only required small modifications.
2013-03-06 16:52:01 -08:00
Russell Belfer
169dc61607 Make iterator APIs consistent with standards
The iterator APIs are not currently consistent with the parameter
ordering of the rest of the codebase.  This rearranges the order
of parameters, simplifies the naming of a number of functions, and
makes somewhat better use of macros internally to clean up the
iterator code.

This also expands the test coverage of iterator functionality,
making sure that case sensitive range-limited iteration works
correctly.
2013-03-06 16:52:01 -08:00
Russell Belfer
18f0826408 Make mode handling during init more like git
When creating files, instead of actually using GIT_FILEMODE_BLOB
and the other various constants that happen to correspond to
mode values, apparently I should be just using 0666 and 0777, and
relying on the umask to clear bits and make the value sane.

This fixes the rules for copying a template directory and fixes
the checks to match that new behavior.  (Further changes to the
checkout logic to follow separately.)
2013-02-27 13:44:15 -08:00
Russell Belfer
0d1b094b07 Fix portability issues on Windows
The new tests were not taking core.filemode into account when
testing file modes after repo initialization.  Fixed that and some
other Windows warnings that have crept in.
2013-02-26 13:15:06 -08:00
Russell Belfer
3c42e4ef74 Fix initialization of repo directories
When PR #1359 removed the hooks from the test resources/template
directory, it made me realize that the tests for
git_repository_init_ext using templates must be pretty shabby
because we could not have been testing if the hooks were getting
created correctly.

So, this started with me recreating a couple of hooks, including
a sample and symlink, and adding tests that they got created
correctly in the various circumstances, including with the SHARED
modes, etc.  Unfortunately this uncovered some issues with how
directories and symlinks were copied and chmod'ed.  Also, there
was a FIXME in the code related to the chmod behavior as well.

Going back over the directory creation logic for setting up a
repository, I found it was a little difficult to read and could
result in creating and/or chmod'ing directories that the user
almost certainly didn't intend.

So that let to this work which makes repo initialization much
more careful (and hopefully easier to follow).  It required a
couple of extensions / changes to core fileops utilities, but I
also think those are for the better, at least for git_futils_cp_r
in terms of being careful about what actions it takes.
2013-02-26 11:43:14 -08:00
Scott J. Goldman
c9459abb61 tests: fix indentation in repo/message.c 2013-02-07 03:12:39 -08:00
Scott J. Goldman
f7b060188a tests: fix indentation in repo/init.c 2013-02-07 03:04:50 -08:00
Sebastian Bauer
5885ba112d Now checks in the template test whether the description file has
been properly copied.

This is a minimal effort to test whether the template really has
been used when creating an repo with external templates.
2013-01-13 12:26:52 +01:00
Sebastian Bauer
4a4aee1112 Added flag GIT_REPOSITORY_INIT_EXTERNAL_TEMPLATE to test_repo_init__extended_with_template().
Otherwise the template functionallity is not tested (as a TODO we
also shall test that the specified template really got copied).
2013-01-12 18:44:50 +01:00
Ben Straub
b4d136527c Deploy GIT_REPOSITORY_INIT_OPTIONS_INIT 2012-11-30 13:12:15 -08:00
Ben Straub
2508cc66eb Rename ref and reflog apis for consistency 2012-11-27 13:17:45 -08:00
Vicent Martí
c4d8df27bc Merge pull request #1097 from nulltoken/topic/head_tree_error
Make `git_repository_head_tree()` return error codes
2012-11-23 15:19:47 -08:00
Sascha Cunz
9094d30b93 Reset all static variables to NULL in clar's __cleanup
Without this change, any failed assertion in the second (or a later) test
inside a test suite has a chance of double deleting memory, resulting in
a heap corruption. See #1096 for details.

This leaves alone the test cases where we "just" use cl_git_sandbox_init()
and cl_git_sandbox_cleanup(). These methods already take good care to not
double delete a repository.

Fixes #1096
2012-11-23 11:41:56 +01:00
nulltoken
5cec896a3b repo: Make git_repository_head_tree() return error codes 2012-11-22 18:51:06 +01:00
nulltoken
a94002a983 test: Minor fixes 2012-11-22 18:50:50 +01:00
nulltoken
6091457e76 repo: ensure is_empty() checks there are no refs 2012-11-17 07:20:08 -08:00
nulltoken
5df7207a67 repo: readonly tests don't need a sandboxed repo 2012-11-17 07:20:04 -08:00
Vicent Martí
aa1c3b588e Merge pull request #1016 from arrbee/fix-checkout-dir-removal
Update checkout with new strategies & behavior
2012-11-13 14:13:47 -08:00
nulltoken
b1a3a70ed1 repository: Refine repository_head() error report 2012-11-12 00:14:51 +01:00
Russell Belfer
331e7de900 Extensions to rmdir and mkdir utilities
* Rework GIT_DIRREMOVAL values to GIT_RMDIR flags, allowing
  combinations of flags
* Add GIT_RMDIR_EMPTY_PARENTS flag to remove parent dirs that
  are left empty after removal
* Add GIT_MKDIR_VERIFY_DIR to give an error if item is a file,
  not a dir (previously an EEXISTS error was ignored, even for
  files) and enable this flag for git_futils_mkpath2file call
* Improve accuracy of error messages from git_futils_mkdir
2012-11-09 13:52:06 -08:00
Keith Dahlby
35d255fda6 repo: fix state when HEAD is not detached 2012-11-04 12:13:42 -06:00
nulltoken
31966d20e3 repo: enhance git_repository_state() detection 2012-10-27 16:45:59 +02:00
Edward Thomson
632d8b230b reset changes for merge 2012-10-24 20:24:37 -05:00
Michael Schubert
6f6b0c013c tests-clar/repo: remove unused variable 2012-10-24 15:42:09 +02:00
nulltoken
f36fb761dc tests: more git_repository_head_detached() coverage 2012-10-22 19:46:00 +02:00