Commit Graph

9731 Commits

Author SHA1 Message Date
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
Edward Thomson
37e9278220 Merge pull request #3834 from pks-t/pks/cleanups
Cleanups
2016-06-21 13:26:29 -04:00
Edward Thomson
6944fd325d Merge pull request #3833 from pks-t/pks/msys-conditional-fpic
cmake: do not use -fPIC for MSYS2
2016-06-21 13:23:04 -04: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
b6a2fd0e0d cmake: do not use -fPIC for MSYS2
The MSYS2 build system automatically compiles all code with position-independent
code. When we manually add the -fPIC flag to the compiler flags, MSYS2 will
loudly complain about PIC being the default and thus not required.

Fix the annoyance by stripping -fPIC in MSYS2 enviroments like it is already
done for MinGW.
2016-06-21 07:50:02 +02:00
Edward Thomson
bb0edf87ce Merge pull request #3830 from pks-t/pks/thread-namespacing
Thread namespacing
2016-06-20 22:50:46 -04:00
Edward Thomson
2976dcf8ff README: update "Getting Help" section 2016-06-20 15:05:02 -04:00
Edward Thomson
738ca6eec2 README: update bindings
Drop node-gitteh.  Replace outdated PowerShell bindings with PSGit.
2016-06-20 14:30:33 -04:00
Edward Thomson
0820d0c87c README: improve contributing paragraph 2016-06-20 14:24:17 -04:00
Edward Thomson
69d1197100 README: disambiguate what to distribute source of
Indicate that if you make changes to libgit2 that you must distribute
the source _to libgit2_, not the source _of your program_.
2016-06-20 14:16:50 -04:00
Patrick Steinhardt
aab266c932 threads: add platform-independent thread initialization function 2016-06-20 20:07:33 +02:00
Patrick Steinhardt
8aaa9fb623 win32: rename pthread.{c,h} to thread.{c,h}
The old pthread-file did re-implement the pthreads API with exact symbol
matching. As the thread-abstraction has now been split up between Unix- and
Windows-specific files within the `git_` namespace to avoid symbol-clashes
between libgit2 and pthreads, the rewritten wrappers have nothing to do with
pthreads anymore.

Rename the Windows-specific pthread-files to honor this change.
2016-06-20 19:50:18 +02:00
Patrick Steinhardt
a342e870fc threads: remove now-useless typedefs 2016-06-20 19:50:16 +02:00
Patrick Steinhardt
4f10c1e65c threads: remove unused function pthread_num_processors_np
The function pthread_num_processors_np is currently unused and superseded by the
function `git_online_cpus`. Remove the function.
2016-06-20 19:50:11 +02:00
Patrick Steinhardt
6551004fb1 threads: split up OS-dependent rwlock code 2016-06-20 19:49:40 +02:00
Patrick Steinhardt
139bffa074 threads: split up OS-dependent thread-condition code 2016-06-20 19:49:34 +02:00
Patrick Steinhardt
20d078dff1 threads: remove unused function pthread_cond_broadcast 2016-06-20 19:48:19 +02:00
Patrick Steinhardt
1c13540510 threads: split up OS-dependent mutex code 2016-06-20 19:34:51 +02:00
Patrick Steinhardt
faebc1c6ec threads: split up OS-dependent thread code 2016-06-20 19:32:59 +02:00
Edward Thomson
c80efb5f6d Merge pull request #3818 from meatcoder/fix_odb_read_error
Fix truncation of SHA in error message for git_odb_read
2016-06-20 11:16:49 -04:00
Sim Domingo
2076d3291c fix error message SHA truncation in git_odb__error_notfound() 2016-06-20 11:15:23 -04:00
Edward Thomson
24d10cac12 Merge pull request #3827 from dbrnz/basic_auth
HTTP authentication scheme name is case insensitive.
2016-06-20 11:09:31 -04:00
David Brooks
6c9eb86f22 HTTP authentication scheme name is case insensitive. 2016-06-19 11:46:43 +01:00
Carlos Martín Nieto
69c71f2917 Merge pull request #3823 from libgit2/ethomson/checkout_no_index
checkout: use empty baseline when no index file exists
2016-06-17 15:45:55 +02:00
Carlos Martín Nieto
3e9830d7bc Merge pull request #3822 from libgit2/ethomson/checkout_head_docs
documentation: improve docs for `checkout_head`
2016-06-16 08:53:30 +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
Edward Thomson
b926648839 documentation: improve docs for checkout_head
`git_checkout_head` is sadly misunderstood as something that can
switch branches.  It cannot.  Update the documentation to reflect this.
2016-06-15 15:23:39 -05:00
Edward Thomson
abb6f72aaa Merge pull request #3812 from stinb/fetch-tag-update-callback
fetch: Fixed spurious update callback for existing tags.
2016-06-14 11:42:00 -10:00
Jason Haslam
7f9673e415 fetch: Fixed spurious update callback for existing tags. 2016-06-14 14:46:12 -06:00
Edward Thomson
2a09de91a8 Merge pull request #3816 from pks-t/pks/memory-leaks
Memory leak fixes
2016-06-14 04:33:55 -10:00
Edward Thomson
65e4ab7a33 Merge pull request #3814 from pks-t/pks/invalid-memrefs
Fix invalid memory references
2016-06-14 04:10:11 -10:00
Patrick Steinhardt
43c55111d9 winhttp: plug several memory leaks 2016-06-07 15:36:13 +02:00
Patrick Steinhardt
432af52b37 global: clean up crt only after freeing tls data
The thread local storage is used to hold some global state that
is dynamically allocated and should be freed upon exit. On
Windows, we clean up the C run-time right after execution of
registered shutdown callbacks and before cleaning up the TLS.

When we clean up the CRT, we also cause it to analyze for memory
leaks. As we did not free the TLS yet this will lead to false
positives.

Fix the issue by first freeing the TLS and cleaning up the CRT
only afterwards.
2016-06-07 12:55:17 +02:00
Patrick Steinhardt
292c60275e tests: fix memory leaks in checkout::typechange 2016-06-07 12:29:16 +02:00
Patrick Steinhardt
4d8fe1cda0 coverity: model functions printing into git_buf
The `git_buf` structure seems to be too complicated to correctly
grasp for Coverity. As such, add simpler models trying to guide
Coverity and remove false positives related to these functions.
2016-06-07 09:22:02 +02:00
Patrick Steinhardt
956f1e2387 coverity: add user model
The static analysis engine coverity allows for user models
overriding how it treats functions when analyzing code. Like
this, one can greatly reduce the rate of false positives and thus
make it easier to spot actual errors.

Add a user model that overrides function models for `git_buf_len`
and `git_vector_insert`, which together amount for a majority of
false positives.
2016-06-07 09:20:51 +02:00
Patrick Steinhardt
13deb8745d index: fix NULL pointer access in index_remove_entry
When removing an entry from the index by its position, we first
retrieve the position from the index's entries and then try to
remove the retrieved value from the index map with
`DELETE_IN_MAP`. When `index_remove_entry` returns `NULL` we try
to feed it into the `DELETE_IN_MAP` macro, which will
unconditionally call `idxentry_hash` and then happily dereference
the `NULL` entry pointer.

Fix the issue by not passing a `NULL` entry into `DELETE_IN_MAP`.
2016-06-07 09:14:14 +02:00
Patrick Steinhardt
7d02019a07 transports: smart: fix potential invalid memory dereferences
When we receive a packet of exactly four bytes encoding its
length as those four bytes it can be treated as an empty line.
While it is not really specified how those empty lines should be
treated, we currently ignore them and do not return an error when
trying to parse it but simply advance the data pointer.

Callers invoking `git_pkt_parse_line` are currently not prepared
to handle this case as they do not explicitly check this case.
While they could always reset the passed out-pointer to `NULL`
before calling `git_pkt_parse_line` and determine if the pointer
has been set afterwards, it makes more sense to update
`git_pkt_parse_line` to set the out-pointer to `NULL` itself when
it encounters such an empty packet. Like this it is guaranteed
that there will be no invalid memory references to free'd
pointers.

As such, the issue has been fixed such that `git_pkt_parse_line`
always sets the packet out pointer to `NULL` when an empty packet
has been received and callers check for this condition, skipping
such packets.
2016-06-07 09:14:14 +02:00
Edward Thomson
f0ee795ccb Merge pull request #3808 from ethomson/read_index_fixes
`git_index_read_index` fixes
2016-06-02 03:08:26 -05:00
Edward Thomson
46082c384f index_read_index: invalidate new paths in tree cache
When adding a new entry to an existing index via `git_index_read_index`,
be sure to remove the tree cache entry for that new path.  This will
mark all parent trees as dirty.
2016-06-02 02:38:55 -05: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
9167c1450e index_read_index: set flags for path_len correctly
Update the flags to reset the path_len (to emulate `index_insert`)
2016-06-02 02:36:50 -05:00
Edward Thomson
046ec3c9d6 index_read_index: differentiate on mode
Treat index entries with different modes as different, which they
are, at least for the purposes of up-to-date calculations.
2016-06-02 02:36:46 -05:00
Edward Thomson
93de20b8d2 index_read_index: reset error correctly
Clear any error state upon each iteration.  If one of the iterations
ends (with an error of `GIT_ITEROVER`) we need to reset that error to 0,
lest we stop the whole process prematurely.
2016-06-02 02:36:44 -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
0aaba44593 Merge pull request #3796 from mmuman/haiku
Preliminary Haiku port
2016-06-01 11:33:58 -05:00
Edward Thomson
efb432c9b9 Merge pull request #3801 from ethomson/warning
cleanup: unused warning
2016-06-01 11:05:45 -05:00