Commit Graph

474 Commits

Author SHA1 Message Date
qaqland
196c465995 examples: correct git_commit_time comment 2025-12-31 16:36:04 +08:00
Edward Thomson
c26d8a8b54 sha256: further API simplifications for OID parsing
Introduce `git_oid_from_string`, `git_oid_from_prefix`, and
`git_oid_from_raw`, all of which take a `git_oid_t` that indicates what
type of OID should be parsed (SHA1 or SHA256).

This allows users to continue to use `git_oid_fromstr` without any code
changes, while remaining in a SHA1 world.

Note that these are not perfect analogs to the `fromstr` APIs.

* `git_oid_from_string` now takes a NUL terminated string, instead of
  allowing for non-NUL terminated strings. Adding a NUL check feels like
  an important safety consideration for C strings.
* `git_oid_from_prefix` should be used for an OID substring and length.

Previous usages of `git_oid_fromstr` with non-NUL terminated strings
should move to `git_oid_from_prefix` with the hexsize for the given OID
type.
2025-01-02 13:13:59 +00:00
Edward Thomson
56e2a85643 sha256: simplify API changes for sha256 support
There are several places where users may want to specify the type of
object IDs (sha1 or sha256) that should be used, for example, when
dealing with repositories, indexes, etc.

However, given that sha256 support remains disappointingly uncommon in
the wild, we should avoid hard API breaks when possible. Instead, update
these APIs to have an "extended" format (eg, `git_odb_open_ext`) that
provides an options structure with oid type information.

This allows callers who do care about sha256 to use it, and callers who
do not to avoid gratuitous API breakage.
2025-01-02 13:13:59 +00:00
Edward Thomson
9aa5faa38b indexer: move oid_type into the opts structure
Object ID type should be an option within the options structure; move it
there.
2024-12-18 16:27:46 +00:00
Edward Thomson
708d64f1e8 index: provide a index_options structure when opening
Instead of simply taking the oid type, future-proof our index opening
and creation functionality by taking an options structure.
2024-12-18 16:12:21 +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
c1b2b25ebc remote: add update_refs callback
Add an `update_refs` callback that includes the refspec; `update_tips`
is retained for backward compatibility.
2024-10-19 23:42:26 +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
9cea29d154 blame: update API
Use `size_t` for sizes, standardize naming with the rest of the library.
2024-10-18 10:02:02 +01:00
Edward Thomson
f3518eee26 Merge pull request #6706 from u-quark/signature-use-env-vars
Use environment variables when creating signatures
2024-07-10 08:31:15 +01:00
Edward Thomson
649ef1cca6 signature: add git_signature_default_from_env
People who are doing a commit expect a unified timestamp between
author and committer information when we're using the current timestamp.
Provide a single function that returns both author and committer
information so that they can have an identical timestamp when none is
specified in the environment.
2024-06-14 14:55:37 +02:00
Edward Thomson
49d3fadfca Revert "commit: fix const declaration"
This reverts commit cf19ddc522, which
was breaking for several projects.
2024-06-13 15:20:40 +02:00
qaqland
322ea80231 examples: fix memory leak in for-each-ref.c 2024-05-08 11:08:26 +08:00
Edward Thomson
c95e8e344a Merge pull request #6359 from albfan/fix-log-example
fix log example
2024-03-09 21:39:50 +00:00
Sven Strickroth
6c7df67071 Consistently use libgit2.org
Signed-off-by: Sven Strickroth <email@cs-ware.de>
2024-03-01 14:45:08 +01:00
Sven Strickroth
bd242a05e2 Fix broken links
Signed-off-by: Sven Strickroth <email@cs-ware.de>
2024-02-24 14:35:10 +01:00
Edward Thomson
cf19ddc522 commit: fix const declaration
commit functions should take an array of const pointers, not a const
array.
2024-01-15 00:15:10 +00:00
u_quark
94125fb5c7 Fix clang tests: uninitialized variable 2024-01-14 11:07:13 +00:00
u_quark
f62abd00db Use environment variables when creating signatures
When creating an action signature (e.g. for a commit author and
committer) read the following environment variables that can override
the configuration options:

 * `GIT_AUTHOR_NAME` is the human-readable name in the "author" field.
 * `GIT_AUTHOR_EMAIL` is the email for the "author" field.
 * `GIT_AUTHOR_DATE` is the timestamp used for the "author" field.
 * `GIT_COMMITTER_NAME` sets the human name for the "committer" field.
 * `GIT_COMMITTER_EMAIL` is the email address for the "committer" field.
 * `GIT_COMMITTER_DATE` is used for the timestamp in the "committer"
   field.
 * `EMAIL` is the fallback email address in case the user.email
   configuration value isn't set. If this isn't set, Git falls back to
   the system user and host names.

This is taken from the git documentation chapter "10.8 Environment
Variables":

https://git-scm.com/book/en/v2/Git-Internals-Environment-Variables

This PR adds support for reading these environment variables by adding
two new functions `git_signature_default_author` and
`git_signature_default_committer` and deprecates the
`git_signature_default` function.

Fixes: https://github.com/libgit2/libgit2/issues/3751

Prior work:
 * https://github.com/libgit2/libgit2/pull/4409
 * https://github.com/libgit2/libgit2/pull/5479
 * https://github.com/libgit2/libgit2/pull/6290
2024-01-14 11:07:13 +00:00
Edward Thomson
198a1b209a Merge pull request #5904 from pluehne/support-authentication-in-push-example
Support authentication in push example
2023-12-21 23:58:46 +00:00
Edward Thomson
156e08998c Merge pull request #6699 from libgit2/ethomson/bitfield
examples: use unsigned int for bitfields
2023-12-20 12:23:09 +00:00
Edward Thomson
f004096fff examples: use unsigned int for bitfields 2023-12-20 12:08:21 +00:00
Antonin Delpeuch
687da95ec8 blame example: Fix support for line range in CLI
The -L option announced by the CLI was ignored so far.
2023-09-23 12:00:19 +02:00
Edward Thomson
db2a794dda diff: parse patches with sha256 2023-04-10 14:21:16 +01:00
Edward Thomson
523f893f6f index: add sha256 support 2023-04-10 11:02:12 +01:00
Edward Thomson
fe2ee3a018 object: lookup sha256 objects
This is much of the plumbing for the object database to support SHA256,
and for objects to be able to parse SHA256 versions of themselves.
2023-02-12 22:02:00 +00:00
Alberto Fanjul
c97989e48d Add oneline option 2022-07-18 08:02:41 +02:00
Alberto Fanjul
6b86332465 parse arguments correctly 2022-07-18 07:57:21 +02:00
Alberto Fanjul
d9de12f88b fix log example 2022-07-17 23:52:22 +02:00
Edward Thomson
b43567d655 sha256: indirection for experimental functions
The experimental function signature is only available when
`GIT_EXPERIMENTAL_SHA256` is enabled.
2022-07-13 22:50:33 -04:00
Edward Thomson
3fbf580c91 oid: give oids a type
`git_oid`s now have a type, and we require the oid type when creating
the object id from creation functions.
2022-06-20 17:05:29 -04:00
Edward Thomson
0acaf3a8eb oid: define GIT_OID_SHA1_ZERO
Callers should not assume the layout of the oid structure; provide them
a macro that defines the null / zero sha1 object id.
2022-06-14 22:29:57 -04:00
Edward Thomson
dbc4ac1c76 oid: GIT_OID_*SZ is now GIT_OID_SHA1_*SIZE
In preparation for SHA256 support, `GIT_OID_RAWSZ` and `GIT_OID_HEXSZ`
need to indicate that they're the size of _SHA1_ OIDs.
2022-06-14 22:29:57 -04:00
Edward Thomson
91ba089663 cmake: rename git2internal target to libgit2
The `git2internal` target is actually the git library; call it such so
that IDE users have visibility into it.
2022-02-22 22:07:44 -05:00
Edward Thomson
5fcfada500 cmake: document CMakeLists.txt hierarchy 2022-02-22 22:07:44 -05:00
Ashok P. Nadkarni
aab7c0babc Free parent and ref in lg2_commit before returning. 2022-02-14 13:57:07 +05:30
apnadkarni
77ef1a6e14 Update common.h 2022-02-13 14:11:46 +05:30
Edward Thomson
d2458af7b7 indexer: use a byte array for checksum
The index's checksum is not an object ID, so we should not use the
`git_oid` type.  Use a byte array for checksum calculation and storage.

Deprecate the `git_indexer_hash` function.  Callers should use the new
`git_indexer_name` function which provides a unique packfile name.
2022-01-27 20:15:09 -05:00
Dimitris Apostolou
90df43022a Fix typos 2022-01-05 16:35:52 +02:00
Peter Pettersson
7dcc29fc46 Make enum in src,tests and examples C90 compliant by removing trailing comma. 2021-11-15 16:45:40 +01:00
Edward Thomson
395b3dc403 cmake: refactor global variables
Update the global variables `LIBGIT2_OBJECTS` to
`LIBGIT2_DEPENDENCY_OBJECTS` for clarity and consistency.
2021-11-14 07:25:41 -05:00
Edward Thomson
eabbee0454 example: declare print_usage function 2021-11-11 17:21:32 -05:00
Edward Thomson
8be226148f examples: remove unused function 2021-11-11 17:21:32 -05:00
Edward Thomson
52693ab44e cmake: stylistic refactoring
Ensure that we always use lowercase function names, and that we do not
have spaces preceding open parentheses, for consistency.
2021-10-18 08:30:14 -04:00
Edward Thomson
f0e693b18a str: introduce git_str for internal, git_buf is external
libgit2 has two distinct requirements that were previously solved by
`git_buf`.  We require:

1. A general purpose string class that provides a number of utility APIs
   for manipulating data (eg, concatenating, truncating, etc).
2. A structure that we can use to return strings to callers that they
   can take ownership of.

By using a single class (`git_buf`) for both of these purposes, we have
confused the API to the point that refactorings are difficult and
reasoning about correctness is also difficult.

Move the utility class `git_buf` to be called `git_str`: this represents
its general purpose, as an internal string buffer class.  The name also
is an homage to Junio Hamano ("gitstr").

The public API remains `git_buf`, and has a much smaller footprint.  It
is generally only used as an "out" param with strict requirements that
follow the documentation.  (Exceptions exist for some legacy APIs to
avoid breaking callers unnecessarily.)

Utility functions exist to convert a user-specified `git_buf` to a
`git_str` so that we can call internal functions, then converting it
back again.
2021-10-17 09:49:01 -04:00
Paymon MARANDI
581cfbda85 examples: Free the git_config and git_config_entry after use 2021-09-24 14:14:59 -04:00
Crayon
59af78a48f Fix typo in general.c 2021-07-28 01:58:32 -04:00
Patrick Lühne
7ed00c5c92 Support authentication in push example
This adds basic support for user/password and SSH authentication to the
push example. Authentication is implemented by using the cred_acquire_cb
credential callback defined in examples/common.c.

Co-authored-by: Marius Knaust <marius.knaust@gmail.com>
2021-06-02 16:36:17 +02:00