Commit Graph

428 Commits

Author SHA1 Message Date
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
punkymaniac
8f52b0c553 Remove duplicate line, in example code 2021-03-17 10:48:17 +01:00
Aaron Franke
7efddeb737 Fix some typos 2021-02-15 16:01:25 -05:00
Edward Thomson
4732e03056 revspec: rename git_revparse_mode_t to git_revspec_t
The information about the type of a revision spec is not information
about the parser.  Name it accordingly, so that `git_revparse_mode_t`
is now `git_revspec_t`.  Deprecate the old name.
2021-01-31 16:36:31 +00:00
Patrick Steinhardt
939cb73fdf examples: log: fix documentation generation
Docurium seems to be confused by our use of `/** comment */;` use in the
log example. Let's just switch it around to help Docurium get this
right.
2020-06-08 15:43:34 +02:00
Edward Thomson
51eff5a58b strarray: we should dispose instead of free
We _dispose_ the contents of objects; we _free_ objects (and their
contents).  Update `git_strarray_free` to be `git_strarray_dispose`.
`git_strarray_free` remains as a deprecated proxy function.
2020-06-01 22:50:28 +01:00
Peter Salomonsen
dc2beb7e2d examples: additions and fixes
add example for git commit
fix example for git add
add example for git push
2020-04-02 18:39:37 +02:00
Edward Thomson
3f54ba8b61 credential: change git_cred to git_credential
We avoid abbreviations where possible; rename git_cred to
git_credential.

In addition, we have standardized on a trailing `_t` for enum types,
instead of using "type" in the name.  So `git_credtype_t` has become
`git_credential_t` and its members have become `GIT_CREDENTIAL` instead
of `GIT_CREDTYPE`.

Finally, the source and header files have been renamed to `credential`
instead of `cred`.

Keep previous name and values as deprecated, and include the new header
files from the previous ones.
2020-01-26 18:39:41 +00:00
Patrick Steinhardt
d2d01f7152 Merge pull request #5283 from pks-t/pks/example-checkout-remote-branch
examples: checkout: implement guess heuristic for remote branches
2019-12-13 11:49:37 +01:00
Patrick Steinhardt
dfea0713e0 Merge pull request #5272 from tiennou/examples/cli-ification
Various examples shape-ups
2019-11-28 13:51:40 +01:00
Edward Thomson
f94c9276bc example: use git_object_size_t for object size 2019-11-22 15:23:46 +11:00
Etienne Samson
fe42557a6f examples: buff up rev-list by adding OID support
This allows the example to be used as a quick revwalk test harness.
2019-11-06 11:17:56 +01:00
Etienne Samson
313908f9f5 examples: normalize decls and usage of options structs 2019-11-06 11:17:56 +01:00
Etienne Samson
4a4ad2bc83 examples: add comments to add.c 2019-11-06 11:17:55 +01:00
Etienne Samson
d4a593ef78 examples: modernize add code 2019-11-06 11:17:52 +01:00
Etienne Samson
c9a09b91c4 examples: extract argument conversion helper 2019-11-06 11:16:47 +01:00
Etienne Samson
204a464f42 examples: fixup for-each-ref style 2019-11-06 11:12:34 +01:00
Etienne Samson
c924f36a8b examples: keep track of whether we processed a "--" arg 2019-11-06 11:12:34 +01:00
Etienne Samson
025a93577d examples: move "args" to its own header 2019-11-06 11:12:34 +01:00
Etienne Samson
745ccc8ab9 examples: remove duplicate includes from common.c 2019-11-06 11:08:26 +01:00
Etienne Samson
cd5e33fbc2 global: DRY includes of assert.h 2019-11-06 11:08:23 +01:00
Etienne Samson
882220bf11 examples: add missing include barriers 2019-11-06 11:08:19 +01:00
Etienne Samson
4867523e60 examples: add *.h files to IDEs 2019-11-06 11:08:15 +01:00
Patrick Steinhardt
a9b5270b9a examples: checkout: implement guess heuristic for remote branches 2019-10-25 08:11:28 +02:00
Edward Thomson
5774b2b134 Merge pull request #5113 from pks-t/pks/stash-perf
stash: avoid recomputing tree when committing worktree
2019-08-11 23:42:45 +01:00
Patrick Steinhardt
24c491ed00 Merge pull request #5146 from scottfurry/StaticFixesExamples
Adjust printf specifiers in examples code
2019-08-02 07:58:11 +02:00
Scott Furry
73a186f28a Adjust printf specifiers in examples code
Static analysis of example code found multiple findings of `printf` usage
where filling value is members of git_indexer_progress object. Specifier
used was for signed int but git_indexer_progress members are typed as
unsigned ints. `printf` specifiers were altered to match type.
2019-08-01 12:52:12 -06:00
Patrick Steinhardt
ac171542a6 Merge pull request #5184 from novalis/fix-example
Fix example checkout to forbid rather than require --
2019-08-01 17:45:14 +02:00
Patrick Steinhardt
56e7aaf044 Merge pull request #5125 from albfan/wip/albfan/diff_buffers
Compare buffers in diff example
2019-08-01 12:40:51 +02:00
David Turner
ed387d4af6 Fix example checkout to forbid rather than require --
Make the example program for checkout follow git syntax, where
"--" indicates a file.  This was likely just a strcmp return
value confusion.
2019-07-24 12:01:27 -04:00
Patrick Steinhardt
88731e3c33 examples: implement git-stash example
Implement a new example that resembles the git-stash(1) command.
Right now, it only provides the apply, list, save and pop
subcommands without any options.

This example is mostly used to test libgit2's stashing
performance on big repositories.
2019-07-20 19:10:57 +02:00
Patrick Steinhardt
8ee3d39afd examples: implement config example
Implement a new example that resembles git-config(1). Right now,
this example can both read and set configuration keys, only.
2019-07-11 08:28:55 +02:00
Patrick Steinhardt
960d2a070f examples: consolidate includes into "common.h"
Consolidate all standard includes and defines into "common.h". This lets
us avoid having to handle platform-specific things in multiple places.
2019-07-05 14:30:48 +02:00
Alberto Fanjul
3be09b6c02 Compare buffers in diff example 2019-07-05 14:12:04 +02:00
Patrick Steinhardt
398412ccd3 Merge pull request #5143 from libgit2/ethomson/warnings
ci: build with ENABLE_WERROR on Windows
2019-07-05 11:56:16 +02:00
Patrick Steinhardt
2dea47362e examples: avoid warning when iterating over index entries
When iterating over index entries, we store the indices in an unsigned
int. As the index entrycount is a `size_t` though, this may be a loss of
precision which a compiler might rightfully complain about.

Use `size_t` instead to fix any warnings.
2019-07-05 11:28:57 +02:00
Patrick Steinhardt
abf24a30fd examples: avoid conversion warnings when calculating progress
When computing the progress, we perform some arithmetics that are
implicitly converting from `size_t` to `int`. In one case we're
calclulating a percentage, so we know that it should always be in the
range of [0,100] and thus we're fine. In the other case we convert from
bytes to kilobytes -- this should be stored in a `size_t` to avoid loss
of precision, even though it probably won't matter due to limited
download rates.
2019-07-05 11:28:57 +02:00
Patrick Steinhardt
e7bb1fe8b2 examples: avoid passing signed integer to memchr
The memchr(3P) function expects a `size_t` as its last parameter, but we
do pass it an object size, which is of signed type `git_off_t`. As we
can be sure that the result will be non-negative, let's just cast the
parameter to a `size_t`.
2019-07-05 11:28:57 +02:00
Patrick Steinhardt
976eed8078 examples: cast away constness for reallocating head arrays
When reallocating commit arrays in `opts_add_commit` and
`opts_add_refish`, respectively, we simply pass the const pointer to
`xrealloc`. As `xrealloc` expects a non-const pointer, though, this will
generate a warning with some compilers.

Cast away the constness to silence compilers.
2019-07-05 11:28:57 +02:00
Scott Furry
2ba7dbbe35 Resolve static check warnings in example code
Using cppcheck on libgit2 sources indicated two warnings in
example code.

merge.c was reported as having a memory leak. Fix applied
was to `free()` memory pointed to by `parents`.

init.c was reported as having a null pointer dereference
on variable arg. Function 'usage' was being called with
a null variable. Changed supplied parameter to empty string.
2019-06-27 04:59:28 -06:00
Edward Thomson
b6b2d9d78a examples: ssize_t is signed, not unsigned 2019-06-25 15:22:46 +01:00
Edward Thomson
cd67a9039c examples: cast away const-ness 2019-06-25 15:22:46 +01:00
Edward Thomson
1118dd9a40 examples: don't lose const 2019-06-25 15:22:46 +01:00
Edward Thomson
ede458b4e4 example: use git_off_t for the object size 2019-06-25 15:22:46 +01:00
Edward Thomson
5d92e54745 oid: is_zero instead of iszero
The only function that is named `issomething` (without underscore) was
`git_oid_iszero`.  Rename it to `git_oid_is_zero` for consistency with
the rest of the library.
2019-06-16 00:16:47 +01:00
Edward Thomson
0b5ba0d744 Rename opt init functions to options_init
In libgit2 nomenclature, when we need to verb a direct object, we name
a function `git_directobject_verb`.  Thus, if we need to init an options
structure named `git_foo_options`, then the name of the function that
does that should be `git_foo_options_init`.

The previous names of `git_foo_init_options` is close - it _sounds_ as
if it's initializing the options of a `foo`, but in fact
`git_foo_options` is its own noun that should be respected.

Deprecate the old names; they'll now call directly to the new ones.
2019-06-14 09:57:00 +01:00
Patrick Steinhardt
172786ec1b examples: use username provided via URL
The credentials callback may be passed a username in case where
the URL already includes the expected username. As we usually
cannot use a different username in such context, we should use
that one if provided and not ask the user for a diferent
username.
2019-04-16 12:03:20 +02:00