Commit Graph

1970 Commits

Author SHA1 Message Date
Edward Thomson
45dc219f65 Merge pull request #3921 from libgit2/cmn/walk-limit-enough
Improve revision walk preparation logic
2016-10-07 16:01:28 +01:00
Arthur Schreiber
ab96ca5572 Make sure we use the C locale for regcomp on macOS. 2016-10-06 13:15:31 +02:00
Carlos Martín Nieto
48c64362e4 revwalk: port over the topological sorting
After porting over the commit hiding and selection we were still left
with mistmaching output due to the topologial sort.

This ports the topological sorting code to make us match with our
equivalent of `--date-order` and `--topo-order` against the output
from `rev-list`.
2016-10-06 11:04:55 +02:00
Carlos Martín Nieto
0bd43371c2 vector, pqueue: add git_vector_reverse and git_pqueue_reverse
This is a convenience function to reverse the contents of a vector and a pqueue
in-place.

The pqueue function is useful in the case where we're treating it as a
LIFO queue.
2016-10-06 11:04:55 +02:00
Carlos Martín Nieto
6708618c10 revwalk: get closer to git
We had some home-grown logic to figure out which objects to show during
the revision walk, but it was rather inefficient, looking over the same
list multiple times to figure out when we had run out of interesting
commits. We now use the lists in a smarter way.

We also introduce the slop mechanism to determine when to stpo
looking. When we run out of interesting objects, we continue preparing
the walk for another 5 rounds in order to make it less likely that we
miss objects in situations with complex graphs.
2016-10-06 11:04:55 +02:00
Edward Thomson
565fb8dcd4 revwalk: introduce tests that hide old commits
Introduce some tests that show some commits, while hiding some commits
that have a timestamp older than the common ancestors of these two
commits.
2016-10-06 11:04:55 +02:00
Edward Thomson
9ad07fc003 Merge pull request #3923 from libgit2/ethomson/diff-read-empty-binary
Read binary patches (with no binary data)
2016-09-06 10:43:21 -05:00
Patrick Steinhardt
46035d984f Merge pull request #3882 from pks-t/pks/fix-fetch-refspec-dst-parsing
refspec: do not set empty rhs for fetch refspecs
2016-09-06 11:21:29 +02:00
Edward Thomson
adedac5aba diff: treat binary patches with no data special
When creating and printing diffs, deal with binary deltas that have
binary data specially, versus diffs that have a binary file but lack the
actual binary data.
2016-09-05 12:26:47 -05:00
Carlos Martín Nieto
40b08124f2 Merge pull request #3915 from pks-t/pks/index-collision-test-leak
tests: index: do not re-allocate index
2016-08-30 12:11:02 +02:00
Stefan Huber
88cfe61497 git_checkout_tree options fix
According to the reference the git_checkout_tree and git_checkout_head
functions should accept NULL in the opts field

This was broken since the opts field was dereferenced and thus lead to a
crash.
2016-08-30 08:04:28 +02:00
Patrick Steinhardt
86e88534d6 tests: index: do not re-allocate index
Plug a memory leak caused by re-allocating a `git_index`
structure which has already been allocated by the test suite's
initializer.
2016-08-29 13:29:01 +02:00
Edward Thomson
b859faa61c Teach git_patch_from_diff about parsed diffs
Ensure that `git_patch_from_diff` can return the patch for parsed diffs,
not just generate a patch for a generated diff.
2016-08-24 09:08:57 -05:00
Edward Thomson
c1b370e931 Merge pull request #3837 from novalis/dturner/indexv4
Support index v4
2016-08-17 09:24:44 -05:00
Edward Thomson
635a922274 Merge pull request #3895 from pks-t/pks/negate-basename-in-subdirs
ignore: allow unignoring basenames in subdirectories
2016-08-17 08:54:48 -05:00
Patrick Steinhardt
fcb2c1c895 ignore: allow unignoring basenames in subdirectories
The .gitignore file allows for patterns which unignore previous
ignore patterns. When unignoring a previous pattern, there are
basically three cases how this is matched when no globbing is
used:

1. when a previous file has been ignored, it can be unignored by
   using its exact name, e.g.

   foo/bar
   !foo/bar

2. when a file in a subdirectory has been ignored, it can be
   unignored by using its basename, e.g.

   foo/bar
   !bar

3. when all files with a basename are ignored, a specific file
   can be unignored again by specifying its path in a
   subdirectory, e.g.

   bar
   !foo/bar

The first problem in libgit2 is that we did not correctly treat
the second case. While we verified that the negative pattern
matches the tail of the positive one, we did not verify if it
only matches the basename of the positive pattern. So e.g. we
would have also negated a pattern like

    foo/fruz_bar
    !bar

Furthermore, we did not check for the third case, where a
basename is being unignored in a certain subdirectory again.

Both issues are fixed with this commit.
2016-08-12 14:47:54 +02:00
David Turner
5625d86b99 index: support index v4
Support reading and writing index v4.  Index v4 uses a very simple
compression scheme for pathnames, but is otherwise similar to index v3.

Signed-off-by: David Turner <dturner@twitter.com>
2016-08-10 14:19:30 -04:00
David Turner
aeb5ee5ab5 varint: Add varint encoding/decoding
This code is ported from git.git

Signed-off-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: David Turner <dturner@twopensource.com>
2016-08-10 14:19:06 -04:00
Edward Thomson
5961face15 Merge pull request #3893 from pks-t/pks/remove-unused-test-cb
tests: blob: remove unused callback function
2016-08-09 08:07:10 -04:00
Patrick Steinhardt
4006455f01 tests: blob: remove unused callback function 2016-08-09 10:09:23 +02:00
Edward Thomson
9bc8c80ffa odb: actually insert the empty blob in tests 2016-08-05 20:34:19 -04:00
Edward Thomson
becadafca8 odb: only provide the empty tree
Only provide the empty tree internally, which matches git's behavior.
If we provide the empty blob then any users trying to write it with
libgit2 would omit it from actually landing in the odb, which appear
to git proper as a broken repository (missing that object).
2016-08-05 19:30:56 -04:00
Carlos Martín Nieto
c550c92228 Merge pull request #3881 from pks-t/pks/fix-clar-suite-prefix-computation
clar: fix parsing of test suite prefixes
2016-08-05 18:24:28 +02:00
Edward Thomson
27051d4e31 odb: only freshen pack files every 2 seconds
Since writing multiple objects may all already exist in a single
packfile, avoid freshening that packfile repeatedly in a tight loop.
Instead, only freshen pack files every 2 seconds.
2016-08-04 15:12:04 -04:00
Edward Thomson
8f09a98e18 odb: freshen existing objects when writing
When writing an object, we calculate its OID and see if it exists in the
object database.  If it does, we need to freshen the file that contains
it.
2016-08-04 15:12:04 -04:00
Edward Thomson
78b500bf59 Merge pull request #3850 from wildart/custom-tls
Enable https transport for custom TLS streams
2016-08-04 12:45:19 -04:00
Patrick Steinhardt
1eee631d11 refspec: do not set empty rhs for fetch refspecs
According to git-fetch(1), "[t]he colon can be omitted when <dst>
is empty." So according to git, the refspec "refs/heads/master"
is the same as the refspec "refs/heads/master:" when fetching
changes. When trying to fetch from a remote with a trailing
colon with libgit2, though, the fetch actually fails while it
works when the trailing colon is left out. So obviously, libgit2
does _not_ treat these two refspec formats the same for fetches.

The problem results from parsing refspecs, where the resulting
refspec has its destination set to an empty string in the case of
a trailing colon and to a `NULL` pointer in the case of no
trailing colon. When passing this to our DWIM machinery, the
empty string gets translated to "refs/heads/", which is simply
wrong.

Fix the problem by having the parsing machinery treat both cases
the same for fetch refspecs.
2016-08-04 13:54:19 +02:00
Patrick Steinhardt
f2cab0a6fa clar: fix parsing of test suite prefixes
When passing in a specific suite which should be executed by clar
via `-stest::suite`, we try to parse this string and then include
all tests contained in this suite. This also includes all tests
in sub-suites, e.g. 'test::suite::foo'.

In the case where multiple suites start with the same _string_,
for example 'test::foo' and 'test::foobar', we fail to
distinguish this correctly. When passing in `-stest::foobar`,
we wrongly determine that 'test::foo' is a prefix and try to
execute all of its matching functions. But as no function
will now match 'test::foobar', we simply execute nothing.

To fix this, we instead have to check if the prefix is an actual
suite prefix as opposed to a simple string prefix. We do so by by
inspecting if the first two characters trailing the prefix are
our suite delimiters '::', and only consider the filter as
matching in this case.
2016-08-04 11:49:39 +02:00
Edward Thomson
498d0801a1 tests: use a size_t 2016-07-24 15:49:19 -04:00
Edward Thomson
e02f567641 repo::open: remove dead code, free buffers 2016-07-24 15:49:19 -04:00
wildart
bdec62dce1 remove conditions that prevent use of custom TLS stream 2016-07-06 13:06:25 -04:00
Edward Thomson
c18a2bc4e0 Merge pull request #3851 from txdv/get-user-agent
Add get user agent functionality.
2016-07-05 15:51:01 -04:00
Edward Thomson
b57c176aa9 Merge pull request #3846 from rkrp/fix_bug_parsing_int64min
Fixed bug while parsing INT64_MIN
2016-07-05 12:46:27 -04:00
Andrius Bentkus
f1dba14481 Add get user agent functionality. 2016-07-05 18:10:24 +03:00
Edward Thomson
ebeb56f0f5 Merge pull request #3711 from joshtriplett/git_repository_discover_default
Add GIT_REPOSITORY_OPEN_FROM_ENV flag to respect $GIT_* environment vars
2016-07-01 18:45:10 -04:00
Edward Thomson
6249d960ab index: include conflicts in git_index_read_index
Ensure that we include conflicts when calling `git_index_read_index`,
which will remove conflicts in the index that do not exist in the new
target, and will add conflicts from the new target.
2016-06-29 18:37:00 -04:00
Krishna Ram Prakash R
70b9b84179 Fixed bug while parsing INT64_MIN 2016-06-29 13:32:18 +05:30
Edward Thomson
20302aa437 Merge pull request #3223 from ethomson/apply
Reading patch files
2016-06-25 23:33:05 -04:00
Edward Thomson
1a79cd959b patch: show copy information for identical copies
When showing copy information because we are duplicating contents,
for example, when performing a `diff --find-copies-harder -M100 -B100`,
then show copy from/to lines in a patch, and do not show context.
Ensure that we can also parse such patches.
2016-06-25 23:08:30 -04:00
Edward Thomson
9eb1938134 patch::parse: test diff with exact rename and copy 2016-06-25 23:08:30 -04:00
Edward Thomson
8a670dc4c0 patch::parse: test diff with simple rename 2016-06-25 23:08:28 -04:00
Edward Thomson
e774d5af76 diff::parse tests: test parsing a diff
Test that we can create a diff file, then parse the results and
that the two are identical in-memory.
2016-06-25 23:08:04 -04:00
Josh Triplett
0dd98b6905 Add GIT_REPOSITORY_OPEN_FROM_ENV flag to respect $GIT_* environment vars
git_repository_open_ext provides parameters for the start path, whether
to search across filesystems, and what ceiling directories to stop at.
git commands have standard environment variables and defaults for each
of those, as well as various other parameters of the repository. To
avoid duplicate environment variable handling in users of libgit2, add a
GIT_REPOSITORY_OPEN_FROM_ENV flag, which makes git_repository_open_ext
automatically handle the appropriate environment variables. Commands
that intend to act just like those built into git itself can use this
flag to get the expected default behavior.

git_repository_open_ext with the GIT_REPOSITORY_OPEN_FROM_ENV flag
respects $GIT_DIR, $GIT_DISCOVERY_ACROSS_FILESYSTEM,
$GIT_CEILING_DIRECTORIES, $GIT_INDEX_FILE, $GIT_NAMESPACE,
$GIT_OBJECT_DIRECTORY, and $GIT_ALTERNATE_OBJECT_DIRECTORIES.  In the
future, when libgit2 gets worktree support, git_repository_open_env will
also respect $GIT_WORK_TREE and $GIT_COMMON_DIR; until then,
git_repository_open_ext with this flag will error out if either
$GIT_WORK_TREE or $GIT_COMMON_DIR is set.
2016-06-24 12:26:51 -07:00
Josh Triplett
39c6fca33a Add GIT_REPOSITORY_OPEN_NO_DOTGIT flag to avoid appending /.git
GIT_REPOSITORY_OPEN_NO_SEARCH does not search up through parent
directories, but still tries the specified path both directly and with
/.git appended.  GIT_REPOSITORY_OPEN_BARE avoids appending /.git, but
opens the repository in bare mode even if it has a working directory.
To support the semantics git uses when given $GIT_DIR in the
environment, provide a new GIT_REPOSITORY_OPEN_NO_DOTGIT flag to not try
appending /.git.
2016-06-24 11:44:01 -07:00
Josh Triplett
ed577134a5 Fix repository discovery with ceiling_dirs at current directory
git only checks ceiling directories when its search ascends to a parent
directory.  A ceiling directory matching the starting directory will not
prevent git from finding a repository in the starting directory or a
parent directory.  libgit2 handled the former case correctly, but
differed from git in the latter case: given a ceiling directory matching
the starting directory, but no repository at the starting directory,
libgit2 would stop the search at that point rather than finding a
repository in a parent directory.

Test case using git command-line tools:

/tmp$ git init x
Initialized empty Git repository in /tmp/x/.git/
/tmp$ cd x/
/tmp/x$ mkdir subdir
/tmp/x$ cd subdir/
/tmp/x/subdir$ GIT_CEILING_DIRECTORIES=/tmp/x git rev-parse --git-dir
fatal: Not a git repository (or any of the parent directories): .git
/tmp/x/subdir$ GIT_CEILING_DIRECTORIES=/tmp/x/subdir git rev-parse --git-dir
/tmp/x/.git

Fix the testsuite to test this case (in one case fixing a test that
depended on the current behavior), and then fix find_repo to handle this
case correctly.

In the process, simplify and document the logic in find_repo():
- Separate the concepts of "currently checking a .git directory" and
  "number of iterations left before going further counts as a search"
  into two separate variables, in_dot_git and min_iterations.
- Move the logic to handle in_dot_git and append /.git to the top of the
  loop.
- Only search ceiling_dirs and find ceiling_offset after running out of
  min_iterations; since ceiling_offset only tracks the longest matching
  ceiling directory, if ceiling_dirs contained both the current
  directory and a parent directory, this change makes find_repo stop the
  search at the parent directory.
2016-06-24 11:44:01 -07:00
Patrick Steinhardt
fe345c7306 Remove unused static functions 2016-06-21 07:58:33 +02:00
Patrick Steinhardt
8fd74c0806 Avoid old-style function definitions
Avoid declaring old-style functions without any parameters.
Functions not accepting any parameters should be declared with
`void fn(void)`. See ISO C89 $3.5.4.3.
2016-06-21 07:58:33 +02:00
Patrick Steinhardt
faebc1c6ec threads: split up OS-dependent thread code 2016-06-20 19:32:59 +02:00
Edward Thomson
bb0bd71ab4 checkout: use empty baseline when no index
When no index file exists and a baseline is not explicitly provided, use
an empty baseline instead of trying to load `HEAD`.
2016-06-15 15:47:28 -05:00
Patrick Steinhardt
292c60275e tests: fix memory leaks in checkout::typechange 2016-06-07 12:29:16 +02:00
Edward Thomson
5acf18ac63 rebase: test rebasing a new commit with subfolder
Test a rebase (both a merge rebase and an inmemory rebase) with a new
commit that adds files underneath a new subfolder.
2016-06-02 02:38:18 -05:00
Edward Thomson
91fbf9d867 test: ensure we can round-trip a written tree
Read a tree into an index, write the index, then re-open the index and
ensure that we are treesame to the original.
2016-06-02 02:37:04 -05:00
Edward Thomson
5baa20b86e round-trip trees through index_read_index
Read a tree into an index using `git_index_read_index` (by reading
a tree into a new index, then reading that index into the current
index), then write the index back out, ensuring that our new index
is treesame to the tree that we read.
2016-06-02 00:59:46 -05:00
Edward Thomson
c2f18b9b06 cleanup: unused warning 2016-06-01 10:03:51 -05:00
Edward Thomson
7166bb1665 introduce git_diff_from_buffer to parse diffs
Parse diff files into a `git_diff` structure.
2016-05-26 13:01:09 -05:00
Edward Thomson
94e488a056 patch: differentiate not found and invalid patches 2016-05-26 13:01:08 -05:00
Edward Thomson
17572f67ed git_patch_parse_ctx: refcount the context 2016-05-26 13:01:08 -05:00
Edward Thomson
9be638ecf0 git_diff_generated: abstract generated diffs 2016-05-26 13:01:08 -05:00
Edward Thomson
53571f2f0c vector: more sensible names for grow_at/shrink_at 2016-05-26 13:01:08 -05:00
Edward Thomson
440e3bae10 patch: git_patch_from_patchfile -> git_patch_from_buffer 2016-05-26 13:01:08 -05:00
Edward Thomson
e564fc65b5 git_vector_grow/shrink: correct shrink, and tests 2016-05-26 13:01:07 -05:00
Edward Thomson
0ff723cc90 apply: test postimages that grow/shrink original
Test with some postimages that actually grow/shrink from the
original, adding new lines or removing them.  (Also do so without
context to ensure that we can add/remove from a non-zero part of
the line vector.)
2016-05-26 13:01:07 -05:00
Edward Thomson
8cb27223b8 git_buf_quote/unquote: handle > \177
Parse values up to and including `\377` (`0xff`) when unquoting.
Print octal values as an unsigned char when quoting, lest `printf`
think we're talking about negatives.
2016-05-26 13:01:07 -05:00
Edward Thomson
6278fbc5dd patch parsing: squash some memory leaks 2016-05-26 13:01:07 -05:00
Edward Thomson
d3d95d5ae2 git_buf_quote: quote ugly characters 2016-05-26 13:01:06 -05:00
Edward Thomson
82175084e1 Introduce git_patch_options, handle prefixes
Handle prefixes (in terms of number of path components) for patch
parsing.
2016-05-26 13:01:06 -05:00
Edward Thomson
2f3b922ff1 patch_parse: test roundtrip patch parsing -> print 2016-05-26 13:01:05 -05:00
Edward Thomson
42b3442823 patch_parse: ensure we can parse a patch 2016-05-26 13:01:05 -05:00
Edward Thomson
8bca8b9e03 apply: move patch data to patch_common.h 2016-05-26 13:01:04 -05:00
Edward Thomson
804d5fe9f5 patch: abstract patches into diff'ed and parsed
Patches can now come from a variety of sources - either internally
generated (from diffing two commits) or as the results of parsing
some external data.
2016-05-26 13:01:04 -05:00
Edward Thomson
8d2eef27ff patch parsing: ensure empty patches are illegal 2016-05-26 13:01:04 -05:00
Edward Thomson
5d17d72621 patch parsing: parse binary patch files 2016-05-26 13:01:04 -05:00
Edward Thomson
b8dc2fdb92 zstream: fail when asked to inflate garbage
When we are provided some input buffer (with a length) to inflate,
and it contains more data than simply the deflated data, fail.
zlib will helpfully tell us when it is done reading (via Z_STREAM_END),
so if there is data leftover in the input buffer, fail lest we
continually try to inflate it.
2016-05-26 13:01:04 -05:00
Edward Thomson
5b78dbdbf3 git_buf: decode base85 inputs 2016-05-26 13:01:04 -05:00
Edward Thomson
3149ff6f66 patch application: apply binary patches
Handle the application of binary patches.  Include tests that
produce a binary patch (an in-memory `git_patch` object),
then enusre that the patch applies correctly.
2016-05-26 13:01:03 -05:00
Edward Thomson
b88f1713d0 zstream: offer inflating, git_zstream_inflatebuf
Introduce `git_zstream_inflatebuf` for simple uses.
2016-05-26 13:01:03 -05:00
Edward Thomson
0004386f29 apply: handle empty patches
When a patch is empty, simply copy the source into the destination.
2016-05-26 11:36:11 -05:00
Edward Thomson
d34f68261e Patch parsing from patch files 2016-05-26 11:36:11 -05:00
Edward Thomson
7cb904ba44 Introduce git_apply_patch
The beginnings of patch application from an existing (diff-created)
git_patch object: applies the hunks of a git_patch to a buffer.
2016-05-26 11:36:11 -05:00
Edward Thomson
e102daa4f6 Merge pull request #3798 from mmuman/stat-test-fix
test: Fix stat() test to mask out unwanted bits
2016-05-26 10:25:40 -05:00
Jason Haslam
afab1fff01 checkout: handle dirty submodules correctly
Don't generate conflicts when checking out a modified submodule and the
submodule is dirty or modified in the workdir.
2016-05-26 01:11:34 -05:00
François Revol
407f2e9fbd test: Fix stat() test to mask out unwanted bits
Haiku and Hurd both pass extra bits in struct stat::st_mode.
2016-05-24 20:01:49 +02:00
Carlos Martín Nieto
a2cb47130e tree: handle removal of all entries in the updater
When we remove all entries in a tree, we should remove that tree from
its parent rather than include the empty tree.
2016-05-24 14:30:43 +02:00
Carlos Martín Nieto
5341230536 tree: plug leaks in the tree updater 2016-05-19 15:29:53 +02:00
Carlos Martín Nieto
922496562b tree: use testrepo2 for the tree updater tests
This gives us trees with subdirectories, which the new test needs.
2016-05-19 15:21:26 +02:00
Carlos Martín Nieto
9464f9ebc1 Introduce a function to create a tree based on a different one
Instead of going through the usual steps of reading a tree recursively
into an index, modifying it and writing it back out as a tree, introduce
a function to perform simple updates more efficiently.

`git_tree_create_updated` avoids reading trees which are not modified
and supports upsert and delete operations. It is not as versatile as
modifying the index, but it makes some common operations much more
efficient.
2016-05-17 17:41:05 +02:00
Carlos Martín Nieto
17a93afa78 Merge pull request #3757 from johnhaley81/jh/fix-create-initial-commit
Fix `git_commit_create` for an initial commit
2016-05-06 18:44:37 +02:00
John Haley
5785ae9b5e Fix initial commit test
`test_commit_commit__create_initial_commit_parent_not_current` was not correctly 
testing that `HEAD` was not changed. Now we grab the oid that it was pointing to
before the call to `git_commit_create` and the oid that it's pointing to afterwards
and compare those.
2016-05-04 11:15:56 -07:00
John Haley
4f22ccb979 Add tests for creating an initial commit 2016-05-03 13:32:32 -07:00
Edward Thomson
c7b4bbffcc rebase: test rebase (merge) w/ no common ancestor 2016-05-03 15:29:44 -04:00
Edward Thomson
d383c39b3b Introduce git_signature_from_buffer
Allow users to construct a signature from the type of signature
lines that actually appear in commits.
2016-04-28 12:47:14 -04:00
Edward Thomson
b3ffd8f638 rebase::abort: test we can abort rebase by revspec
Test that we can properly abort a rebase when it is initialized by a
revspec.  This ensures that we do not conflate revspecs and refnames.
2016-04-26 11:49:05 -04:00
Carlos Martín Nieto
9068704bd8 Merge pull request #3749 from arthurschreiber/arthur/add-git-reference-dup
Allow creating copies of `git_reference` objects.
2016-04-26 11:02:45 +02:00
Carlos Martín Nieto
c30955e0c0 Merge pull request #3748 from libgit2/ethomson/rebase_detached
Rebase improvements with IDs
2016-04-26 11:02:05 +02:00
Carlos Martín Nieto
eb39284bab tag: ignore extra header fields
While no extra header fields are defined for tags, git accepts them by
ignoring them and continuing the search for the message. There are a few
tags like this in the wild which git parses just fine, so we should do
the same.
2016-04-25 12:18:32 +02:00
Arthur Schreiber
908f24fd13 Allow creating copies of git_reference objects. 2016-04-22 10:34:17 -07:00
Edward Thomson
1f84caf0c0 rebase: correctly finish rebasing detached heads
When rebasing with IDs, we do not return to the `branch`,
we remain in a detached HEAD state.
2016-04-21 18:19:05 -04:00
Edward Thomson
320f53cd6c rebase: test abort immediately after init
Instead of `open`ing a rebase and `abort`ing that, test that we can
`abort` a rebase that has just begun with `init`.
2016-04-21 18:19:05 -04:00
Edward Thomson
0bd7740173 clone test: annotate unused vars 2016-04-21 11:05:21 -04:00
Edward Thomson
1dc449105b Merge pull request #3110 from libgit2/cmn/proxy-config
Proxy configuration
2016-04-19 19:48:52 -04:00