Commit Graph

402 Commits

Author SHA1 Message Date
Edward Thomson
f94c9276bc example: use git_object_size_t for object size 2019-11-22 15:23:46 +11: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
Patrick Steinhardt
611fbe4f9b examples: implement SSH key credentials
Implement SSH key credentials. This allows users to use the SSH
transport with the lg2 example code.
2019-04-16 12:02:20 +02:00
Patrick Steinhardt
d9351c6556 examples: implement SSH key credentials
Implement SSH key credentials. This allows users to use the SSH
transport with the lg2 example code.
2019-04-16 11:58:13 +02:00
Patrick Steinhardt
e9aa84799a examples: support plain username credentials
Implement plain username credential types. These type of
credentials might be asked for e.g. as some kind of
pre-authentication step, before the actual credentials are
passed.
2019-04-16 11:56:57 +02:00
Patrick Steinhardt
635ec366d7 examples: honor allowed credential types when prompting user
Credential callback are being passed a bitset that indicates
which credential types are allowed in the current context. In our
examples code, we completely ignore that field and always return
username/password credentials, which doesn't necessarily make
sense e.g. when only SSH keys are allowed.

Refactor the code and only return username/password credentials
in the case where `USERPASS_PLAINTEXT` credentials are allowed.
Otherwise, return a positive error code to indicate that no
credentials could be acquired.
2019-04-16 11:53:39 +02:00
Patrick Steinhardt
b106620d03 examples: move MSVC compatibility macros into common header
We currently have two locations in our examples where we define
the same compatibility wrappers for MSVC. Move them into
"common.h" to avoid duplication and make them available to other
examples.
2019-04-16 11:52:30 +02:00
Edward Thomson
a1ef995dc0 indexer: use git_indexer_progress throughout
Update internal usage of `git_transfer_progress` to
`git_indexer_progreses`.
2019-02-22 11:25:14 +00:00
Etienne Samson
6cf4772684 examples/add: add explanatory comments and reformat 2019-02-15 12:07:07 +01:00
Patrick Steinhardt
106998fce6 examples: print available commands if no args are given 2019-02-15 12:07:07 +01:00
Patrick Steinhardt
ead10785dc examples: create common lg2 executable
Inside of our networking example code, we have a git2 executable
that acts as an entry point to all the different network
examples. As such, it is kind of the same like the normal git(1)
executable in that it simply arbitrates to the respective
subcommands.

Let's extend this approach and merge all examples into a single
standalone lg2 executable. Instead of building an executable
for all the existing examples we have, we now bundle them all
inside of the lg2 one and let them be callable via subcommands.

In the process, we can get rid of duplicated library
initialization, deinitialization and repository discovery code.
Instead of having each subcommand handle these on its own, we
simply do it inside of the single main function now.
2019-02-15 12:06:54 +01:00
Patrick Steinhardt
7562422ab9 examples: merge common network code
Right now, we have two sets of "common" code, one containing
general common code and one containing network common code. As we
intend to get rid of the network subdirectory and instead merge
all examples into a single standalone executable, this
distinction doesn't make a lot of sense now. Furthermore, the
common network code is not that big.

Let's get rid of the common network code by merging it into the
general common code.
2019-02-15 12:04:14 +01:00
Patrick Steinhardt
c4271314e1 examples: remove unused Makefile
This Makefile isn't used anymore and probably won't work anyway.
Remove it in favor of the existing CMake build instructions.
2019-02-15 12:04:14 +01:00
Patrick Steinhardt
a540e6bbcb examples: remove test script
In commit 2e2332857 (examples: a test, for rev-list, 2013-03-20),
a script was introduced with the intention of testing our
rev-list example code. Nobody uses that script, and in fact it
doesn't even properly work due to the not-so-recent addition
out-of-source builds.

Remove the script.
2019-02-15 12:04:14 +01:00
Edward Thomson
24ac9e0c97 deprecation: ensure we GIT_EXTERN deprecated funcs
Although the error functions were deprecated, we did not properly mark
them as deprecated.  We need to include the `deprecated.h` file in order
to ensure that the functions get their export attributes.

Similarly, do not define `GIT_DEPRECATE_HARD` within the library, or
those functions will also not get their export attributes.  Define that
only on the tests and examples.
2019-02-14 11:57:05 +00:00
Edward Thomson
cc5da0a63d examples: don't use deprecated types 2019-01-25 09:06:50 +00:00
Edward Thomson
fcc7dcb176 errors: remove giterr usage in examples 2019-01-22 22:30:37 +00:00
Edward Thomson
1758636b13 Merge pull request #4939 from libgit2/ethomson/git_ref
Move `git_ref_t` to `git_reference_t`
2019-01-19 01:38:34 +00:00
Edward Thomson
83151018ef object_type: convert final internal users to new names
Update some missed types that were continuing to use the old `GIT_OBJ`
names.
2019-01-17 11:03:19 +00:00
Edward Thomson
ed8cfbf041 references: use new names in internal usage
Update internal usage to use the `git_reference` names for constants.
2019-01-17 10:32:29 +00:00
Edward Thomson
50186ce88b Merge pull request #4374 from pks-t/pks/pack-file-verify
Pack file verification
2018-08-26 11:26:45 +01:00
Patrick Steinhardt
ea9e2c1a4a Merge pull request #4692 from tiennou/examples/checkout
Add a checkout example
2018-07-20 13:06:56 +02:00
Etienne Samson
b24202e154 examples: add checkout 2018-07-17 21:43:28 +02:00
Patrick Steinhardt
e1a4a8ebfc cmake: enforce C90 standard
While the aim of libgit2 was to conform to C90 code, we never instructed
the compiler to enforce C90 compliance. Thus, quite a few violations
were able to get into our code base, which have been removed with the
previous commits. As we are now able to build libgit2 with C90 enforced,
we can set the C_STANDARD property for our own build targets.

Note that we explicitly avoid setting the C standard for our third-party
dependencies. At least the zlib target does not build with C90 enforced,
and we do not want to fix them by deviating from upstream. Thus we
simply enforce no standard for them.
2018-07-13 08:25:12 +02:00
Patrick Steinhardt
c13e56f91c cmake: distinguish internal and system include directories
While we want to enforce strict C90 mode, this may cause issues with
system provided header files which are themselves not strictly
conforming. E.g. if a system header has C++ style comments, a compiler
in strict C90 mode would produce an error and abort the build. As the
user most likely doesn't want to change the system header, this would
completely break the build on such systems. One example of this is
mbedtls, which provides such header files.

The problem can be worked around by distinguishing between
system-provided and project-provided include directories. When adding
include directories via "-isystem" instead of "-I", the compiler will
skip certain checks and print out less warnings. To use system includes,
we can simply add the "SYSTEM" flag to CMake's `INCLUDE_DIRECTORIES` and
`TARGET_INCLUDE_DIRECTORIES` functions. Note that we have to split the
include directories into two variables because of this, as we definitely
still want to check for all warnings produced by our own header files.
2018-07-13 08:25:12 +02:00
Patrick Steinhardt
9994cd3f0f treewide: remove use of C++ style comments
C++ style comment ("//") are not specified by the ISO C90 standard and
thus do not conform to it. While libgit2 aims to conform to C90, we did
not enforce it until now, which is why quite a lot of these
non-conforming comments have snuck into our codebase. Do a tree-wide
conversion of all C++ style comments to the supported C style comments
to allow us enforcing strict C90 compliance in a later commit.
2018-07-13 08:25:12 +02:00
Etienne Samson
5b7ba78630 examples: add a helper for boolean-style options 2018-07-07 14:52:24 +02:00
Etienne Samson
8e063eb66b examples: make the refish resolution work with short OIDs 2018-07-07 13:10:50 +02:00