Commit Graph

44 Commits

Author SHA1 Message Date
Edward Thomson
72d49bb0de clar: update to latest version
Update to the latest version (in HEAD) of clar. This affords us improved
test directory creation, and the `cl_invoke` helper macro.
2025-01-23 10:32:52 +00:00
Edward Thomson
9ea1f6d4ed cmake: standardize iconv options 2025-01-02 11:45:47 +00:00
Edward Thomson
c4a65c34c2 cmake: standardize builtin sha1dc selection
All `USE_*` options are now `builtin`. Use that for the builtin sha1dc
implementation, keeping `CollisionDetection` for backward compatibility.
2025-01-02 11:45:47 +00:00
Edward Thomson
cd9f463294 Merge pull request #6914 from libgit2/ethomson/cmake
cmake-standard c standards
2024-10-20 23:17:32 +01:00
Edward Thomson
97734321e6 cmake: set Python policy to avoid warning
cmake warns us that we are using a deprecated python module; explicitly
accept that deprecation until they remove it entirely.
2024-10-20 01:08:19 +01:00
Edward Thomson
d090433ef1 cmake: use CMAKE_C_STANDARD and CMAKE_C_EXTENSIONS
cmake already provides a standard way for callers to override the
C_STANDARD and C_EXTENSIONS properties. Support and document those.
2024-10-19 13:18:53 +01:00
Edward Thomson
41a41b4f4a cmake: make C_STANDARD and C_EXTENSIONS configurable
Users can now set up cmake with -DC_STANDARD=... or -DC_EXTENSIONS=...
We default to C90 with C_EXTENSIONS=OFF, but callers can override if
they desire.
2024-10-18 22:26:57 +01:00
GravisZro
f1cac063ba Mandate C90 conformance
This PR ensures and enforces C90 conformance for all files C, including tests.

* Modify CMakeLists.txt to mandate C90 conformance (for better compiler compatibility)
* Update deps/ntlmclient/utf8.h to latest version
* Modify two tests and one header to use C comments instead of C++ comments
2024-10-18 22:26:57 +01:00
Edward Thomson
8d81bb57d6 hashmap: remove now-unused offmap and strmap 2024-10-02 13:07:57 +01:00
Edward Thomson
539059f6e3 hashmap: introduce git_hashmap / git_hashset
Introduce `git_hashmap` and `git_hashset` functionality that is a port
of `khash.h` to be more idiomatically libgit2. This gives us many of the
benefits of khash that we had abstracted away:

1. Typesafety on the values, since we define the structs and functions
2. Ability to create hashes on the stack
3. Ability to new up hashmaps (or sets) without the libgit2 abstraction
   wrappers that we had been adding

This uses the macros to define hashes (either the structure, or the
functions, or both) which is very much in the spirit of khash, but
the results are much more idiomatically libgit2.
2024-10-02 13:07:57 +01:00
Edward Thomson
e78eec28c3 vector: free is now dispose
In keeping with the libgit2 pattern, we _dispose_ a structure that is
not heap allocated, and _free_ a structure's contents _and the structure
itself_.
2024-09-30 21:28:36 +01:00
Edward Thomson
eebaa36f73 url: track whether url explicitly specified a port
When parsing URLs, track whether the port number was explicitly
specified or not. We track this separately from whether the port is the
_default_ port. This is so that we can discern between URLs that have
the default port explicitly specified or not.

For example: scp://host:22/foo and scp://host/foo are equivalent in
terms of functionality, but are not semantically equivalent.

A user might wish to specify scp://host:22/foo in order to explicitly
ensure that we connect on port 22, which might override (for example) a
different configuration option.
2024-07-11 11:13:20 +01:00
Edward Thomson
57870e9f4d util: clean up test resources in the sandbox
Ensure that we clean up cruft that we create for testing, so that future
tests don't have troubles.
2024-02-19 09:06:57 -08:00
Edward Thomson
bdf4d70a13 util: update win32 p_realpath to canonicalize case
The POSIX `realpath` function canonicalizes relative paths, symbolic links,
and case (on case-insensitive filesystems). For example, on macOS, if you
create some file `/private/tmp/FOO`, and you call `realpath("/tmp/foo")`,
you get _the real path_ returned of `/private/tmp/FOO`.

To emulate this behavior on win32, we call `GetFullPathName` to handle the
relative to absolute path conversion, then call `GetLongPathName` to handle
the case canonicalization.
2024-02-19 09:06:57 -08:00
Edward Thomson
f43aa1adb5 util: move path tests to path::core
Clar handles multiple levels of hierarchy in a test name _but_ it does so
assuming that there are not tests at a parent folder level. In other words,
if you have some tests at path/core.c and path/win32.c, then you cannot have
tests in path.c. If you have tests in path.c, then the things in path/*.c
will be ignored.

Move the tests in path.c into path/core.c.
2024-02-19 16:41:31 +00:00
Edward Thomson
beea99b082 path: provide an is_root helper method
We may quickly want to determine if the given path is the root path
('/') on POSIX, or the root of a drive letter (eg, 'A:/', 'C:\') on
Windows.
2024-02-19 16:41:31 +00:00
Edward Thomson
bec1d7b7b0 path: provide a helper to compute len with trailing slashes
We may need to strip multiple slashes at the end of a path; provide a
method to do so.
2024-02-19 16:41:31 +00:00
Peter Pettersson
6847eed97a tests: remove test for strcasecmp
strcasecmp is a posix function, testing it doesn't make sense.
Functions that needs unsigned compare should use git__strcasecmp()
2023-12-17 13:48:12 +01:00
Edward Thomson
cc965243d6 process: test /usr/bin/false on BSDs
Our process tests were previously testing that false is
`/bin/false` everywhere except macOS, where it exists as
`/usr/bin/false`. . Extend this to all BSDs.
2023-12-13 16:40:00 +00:00
Edward Thomson
f451cb18df errors: simplify the saved-state handling
Instead of having a separate type for saving state, we can re-use the
`git_error` structure. In practice, saving the error code along with the
`git_error` information has not proven necessary or useful, so it can be
removed to simplify down to re-using a single structure.
2023-09-03 14:00:35 +01:00
Edward Thomson
3618a2aa45 errors: never return a NULL error
Callers want to be able to simply call `git_error_last()->message`,
not have to worry about whether `git_error_last()` returns NULL or not.
2023-09-03 14:00:35 +01:00
Edward Thomson
d7060aff36 process: provide cmdline-handling and execv style
Provide both cmdline-style handling (passing it to the shell on POSIX,
or directly to CreateProcess on win32) and execv style (passing it
directly to execv on POSIX, and mangling it into a single command-line
on win32).
2023-08-30 20:46:23 +01:00
Edward Thomson
7a8c4d8bd2 process: test SIGTERM detection
We can't reliably detect SIGPIPE on close because of platform
differences. Track `pid` and send `SIGTERM` to a function and ensure
that we can detect it.
2023-08-30 20:46:22 +01:00
Edward Thomson
bc97d01c03 Introduce git_process class that invokes processes 2023-08-30 20:45:13 +01:00
Edward Thomson
8749655745 net: introduce http-biased url parsing
Introduce a url parser that defaults to treating poorly specified URLs
as http URLs. For example: `localhost:8080` is treated as
`http://localhost:8080/` by the http-biased url parsing, instead of a
URL with a scheme `localhost` and a path of `8080`..
2023-08-01 14:12:01 +01:00
Edward Thomson
8c2c0fa80a net: refactor url parsing
Refactor url parsing to simplify the state-passing (introducing a
struct) and add a path parser for future reusability.
2023-08-01 14:12:01 +01:00
Patrick Steinhardt
8e5281c88b tests: add allocation failure test for buffers
Test that `git_buf` correctly fails if no more bytes can be allocated.
This is mostly for demonstration purposes.
2023-05-15 09:30:48 +01:00
Patrick Steinhardt
90cc07711c tests: add allocator with limited number of bytes
In several circumstances, we get bug reports about things that happen in
situations where the environment is quite limited with regards to
available memory. While it's expected that functionality will fail if
memory allocations fail, the assumption is that we should do so in a
controlled way. Most importantly, we do not want to crash hard due to
e.g. accessing NULL pointers.

Naturally, it is quite hard to debug such situations. But since our
addition of pluggable allocators, we are able to implement allocators
that fail in deterministic ways, e.g. after a certain amount of bytes
has been allocated. This commit does exactly that.

To be able to properly keep track of the amount of bytes currently
allocated, allocated pointers contain tracking information. This
tracking information is currently limited to the number of bytes
allocated, so that we can correctly replenish them on calling `free` on
the pointer. In the future, it would be feasible to extend the tracked
information even further, e.g. by adding information about file and line
where the allocation has been performed. As this introduced some
overhead to allocations though, only information essential to limited
allocations is currently tracked.
2023-05-15 09:28:47 +01:00
Edward Thomson
11c89c386c net: move gitno buffer to staticstr
The `gitno` buffer interface is another layer on top of socket reads.
Abstract it a bit into a "static string" that has `git_str` like
semantics but without heap allocation which moves the actual reading
logic into the socket / stream code, and allows for easier future usage
of a static / stack-allocated `git_str`-like interface.
2023-05-13 16:42:04 +01:00
Edward Thomson
6e4bbf222d net: move rfc2818 hostname / wildcard matching to util 2023-05-13 16:42:04 +01:00
Edward Thomson
0d7f3f5291 utf8: add conversion with size and refactor names
Add functions to use convert a string with length, instead of assuming
NUL termination.

In addition, move the utf8 to 16 conversion routines into the `git_utf8`
namespace instead of using namespaceless `git__` prefixed names.
2023-03-21 09:14:06 +00:00
Edward Thomson
5c1d764910 fs_path: let root run the ownership tests
The `git_fs_path_owner_is_current_user` expects the root dir on unix
(`/`) to be owned by a non-current user. This makes sense unless root
(or euid == 0) is running the tests, which often happens during distro
build / packaging scripts. Allow them to run the tests.
2023-02-27 21:52:33 +00:00
Edward Thomson
1ee9b1fb2d url: only allow @s in usernames for ssh urls
Enforce the RFC for other protocols; Google's questionable choices about
malformed SSH protocols shouldn't impact our ability to properly parse
HTTPS.
2022-06-17 13:49:34 -04:00
Edward Thomson
373a3c9ab1 url_parse: introduce our own url parsing
Provide our own url parser, so that we can handle Google Code's "fun"
URLs that have a userinfo with an `@` in it. 😢
2022-06-17 13:49:34 -04:00
Edward Thomson
ffef8e01d3 url: test that we don't expand % encoding in paths 2022-06-17 13:49:34 -04:00
Edward Thomson
fb6c86a244 url: remove invalid scp url parsing test
The url::scp::invalid_addresses test attempts to test an invalid IPv6
address. It does not, it calls the regular URL parsing function which
treats it like a possibly invalid scheme.
2022-06-16 14:37:40 -04:00
Edward Thomson
96d2d42911 net: move url tests into util 2022-06-16 14:37:40 -04:00
Edward Thomson
bf2620bcef fs_path: refactor ownership checks into current user and system
Provide individual file ownership checks for both the current user and
the system user, as well as a combined current user and system user
check.
2022-04-11 16:49:05 -04:00
Edward Thomson
e7fce1b5e5 tests: support flaky stat
The 32-bit ARM QEMU builds are flaky when running `lstat`. Disable those
testing `lstat`'s `st_size` temporarily.
2022-04-06 15:15:26 -04:00
Edward Thomson
ce78c83b73 sha: ensure we test both cng and cryptoapi on windows
When GIT_SHA1_WIN32 or GIT_SHA256_WIN32 is used, ensure that we test
both CryptoNG ("cng") and CryptoAPI.
2022-03-23 08:39:19 -04:00
Edward Thomson
b900981cf7 sha: add sha256 algorithm
Add support for a SHA256 hash algorithm, and add the "builtin" SHA256
hash engine (from RFC 6234).
2022-03-23 08:39:19 -04:00
Edward Thomson
d9b041e6d7 assert: add ASSERT_WITH_CLEANUP
Now that we safely assert and return, we may need to be in a place where
we need to unlock mutexes or cleanup resources.  Provide
`ASSERT_WITH_CLEANUP` that permits for this behavior by taking a block.
2022-02-27 09:20:58 -05:00
Edward Thomson
d02f4f7ad7 cmake: refactor add_clar_test into separate module 2022-02-22 22:07:45 -05:00
Edward Thomson
e6d93612e8 refactor: move utility tests into util 2022-02-22 22:07:45 -05:00