nulltoken [Thu, 9 May 2013 14:42:39 +0000 (16:42 +0200)]
revparse: Introduce git_revparse_ext()
Expose a way to retrieve, along with the target git_object, the reference
pointed at by some revparse expression (`@{<-n>}` or
`<branchname>@{upstream}` syntax).
Russell Belfer [Thu, 16 May 2013 18:03:55 +0000 (11:03 -0700)]
Ensure reuc vector is always valid
In theory, if there was a problem reading the REUC data, the
read_reuc() routine could have left uninitialized and invalid
data in the git_index vector. This moves the line that inserts a
new entry into the vector down to the bottom of the routine so we
know all the content is already valid. Also, per @linquize, this
uses calloc to ensure no uninitialized data.
Russell Belfer [Thu, 16 May 2013 17:38:27 +0000 (10:38 -0700)]
Add cat-file example and increase const use in API
This adds an example implementation that emulates git cat-file.
It is a convenient and relatively simple example of getting data
out of a repository.
Implementing this also revealed that there are a number of APIs
that are still not using const pointers to objects that really
ought to be. The main cause of this is that `git_vector_bsearch`
may need to call `git_vector_sort` before doing the search, so a
const pointer to the vector is not allowed. However, for tree
objects, with a little care, we can ensure that the vector of
tree entries is always sorted and allow lookups to take a const
pointer. Also, the missing const in commit objects just looks
like an oversight.
Russell Belfer [Wed, 15 May 2013 23:25:11 +0000 (16:25 -0700)]
Update index.h docs
Move the git_index_entry to the very top, since it provides the
main structure that needs to be understood by the reader, then
move the bitmasks for the flags and the flags_extended under that
since they are details for looking at particular fields of the
structure.
Russell Belfer [Wed, 15 May 2013 16:24:51 +0000 (09:24 -0700)]
Remove entry dup/free functions and fix comments
This removes the functions to duplicate and free copies of a
git_index_entry and updates the comments to explain that you
should just use the public definition of the struct as needed.
Russell Belfer [Mon, 13 May 2013 23:09:33 +0000 (16:09 -0700)]
Add APIs to dup and free git_index_entrys
This adds git_index_entry_dup to make a copy of an existing entry
and git_index_entry_free to release the memory of the copy. It
also updates the documentation for git_index_get_bypath and
git_index_get_byindex to make it clear that the returned structure
should *not* be modified.
Russell Belfer [Mon, 13 May 2013 23:07:29 +0000 (16:07 -0700)]
Improve docs for git_index_entry flag masks
The constants for extracting data from git_index_entry flags and
flags_extended are not named in a way that makes it easy to know
where to use each one. This improves the docs for the flags (and
slightly reorganizes them), so it should be more obvious.
Russell Belfer [Wed, 15 May 2013 22:23:33 +0000 (15:23 -0700)]
Use GIT_IDXENTRY_STAGE macro
Since I added the GIT_IDXENTRY_STAGE macro to extract the stage
from a git_index_entry, we probably don't need an internal inline
function to do the same thing.
Russell Belfer [Wed, 15 May 2013 21:58:26 +0000 (14:58 -0700)]
Improve robustness of diff rename detection
Under some strange circumstances, diffs can end up listing files
that we can't actually open successfully. Instead of aborting
the git_diff_find_similar, this makes it so that those files just
won't be considered as valid rename/copy targets instead.
Russell Belfer [Wed, 15 May 2013 21:54:02 +0000 (14:54 -0700)]
Fix checkout of submodules with no .gitmodules
It is possible for there to be a submodule in a repository with
no .gitmodules file (for example, if the user forgot to commit
the .gitmodules file). In this case, core Git will just create
an empty directory as a placeholder for the submodule but
otherwise ignore it. We were generating an error and stopping
the checkout. This makes our behavior match that of core git.
Russell Belfer [Wed, 15 May 2013 21:52:12 +0000 (14:52 -0700)]
Remove old symlinks before updating
Unlike blob updates, symlink updates cannot be done "in place"
writing over an old symlink. This means that in checkout when we
realize that we can safely update a symlink, we still need to
remove the old one before writing the new.
Russell Belfer [Wed, 15 May 2013 21:50:05 +0000 (14:50 -0700)]
Fix diff crash when last item is untracked dir
When the last item in a diff was an untracked directory that only
contained ignored items, the loop to scan the contents would run
off the end of the iterator and dereference a NULL pointer. This
includes a test that reproduces the problem and a fix.
CMake: don't try to use bundled zlib when the system's path is in the cache
The code surrounding zlib bundling did not take into consideration
that ZLIB_LIBRARY gets cached, and assumed that FIND(ZLIB) would
always set ZLIB_FOUND, which does not hold true, as this variable
signifies that we have found the package and had to look at the
system, as its location was not cached.
Only use the bundled sources if the external zlib is neither
newly-found nor cached.
Russell Belfer [Sat, 11 May 2013 13:42:25 +0000 (06:42 -0700)]
Fix refdb iteration early termination bug
There was a problem found in the Rugged test suite where the
refdb_fs_backend__next function could exit too early in some
very specific hashing patterns for packed refs. This ports
the Rugged test to libgit2 and then fixes the bug.
Nobody should ever be using anything other than ALL at this level, so
remove the option altogether.
As part of this, git_reference_foreach_glob is now implemented in the
frontend using an iterator. Backends will later regain the ability of
doing the glob filtering in the backend.
Russell Belfer [Fri, 10 May 2013 16:32:42 +0000 (09:32 -0700)]
Fix diff output for renames and copies
If you use rename detection, the renamed and copied files would
not show any text diffs because the function that decides if
data should be loaded didn't know which sides of the diff to
load for those cases.
This adds a test that looks at the patch generated for diff
entries that are COPIED or RENAMED.
Russell Belfer [Fri, 10 May 2013 14:50:53 +0000 (07:50 -0700)]
Improve ignore handling in git_status_file
The git_status_file API was doing a hack to deal with files that
are inside ignored directories. The status scan was not reporting
any file in this case, so git_status_file would attempt a final
"stat()" call, and return IGNORED if the file actually existed.
On case-insensitive filesystems where core.ignorecase is set
incorrectly, this magic check can "succeed" and report a file
as ignored when it should actually return ENOTFOUND.
Now that we have the GIT_STATUS_OPT_RECURSE_IGNORED_DIRS, we can
use that flag to make sure that git_status_file() will look into
ignored directories and eliminate the hack completely, so we give
the correct error.
Russell Belfer [Thu, 9 May 2013 13:45:06 +0000 (06:45 -0700)]
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.
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.
Russell Belfer [Tue, 7 May 2013 14:15:39 +0000 (07:15 -0700)]
Fix line numbering for patches with eofnl
When a patch contained an eofnl change (i.e. the last line either
gained or lost a newline), the oldno and newno line number values
for the lines in the last hunk of the patch were not useful. This
makes them behave in a more expected manner.
Russell Belfer [Tue, 7 May 2013 11:32:17 +0000 (04:32 -0700)]
Add GIT_DIFF_LINE_CONTEXT_EOFNL
This adds a new line origin constant for the special line that
is used when both files end without a newline.
In the course of writing the tests for this, I was having problems
with modifying a file but not having diff notice because it was
the same size and modified less than one second from the start of
the test, so I decided to start working on nanosecond timestamp
support. This commit doesn't contain the nanosecond support, but
it contains the reorganization of maybe_modified and the hooks so
that if the nanosecond data were being read by stat() (or rather
being copied by git_index_entry__init_from_stat), then the nsec
would be taken into account.
This new stuff could probably use some more tests, although there
is some amount of it here.