Commit Graph

178 Commits

Author SHA1 Message Date
Stefan Widgren
c8e02b8776 Remove extra semicolon outside of a function
Without this change, compiling with gcc and pedantic generates warning:
ISO C does not allow extra ‘;’ outside of a function.
2015-02-15 21:07:05 +01:00
Carlos Martín Nieto
a7fa970f8b Merge pull request #2895 from ethomson/alloc_overflow
allocations: test for overflow of requested size
2015-02-15 05:13:50 +01:00
Edward Thomson
f1453c59b2 Make our overflow check look more like gcc/clang's
Make our overflow checking look more like gcc and clang's, so that
we can substitute it out with the compiler instrinsics on platforms
that support it.  This means dropping the ability to pass `NULL` as
an out parameter.

As a result, the macros also get updated to reflect this as well.
2015-02-13 09:27:33 -05:00
Edward Thomson
2884cc42de overflow checking: don't make callers set oom
Have the ALLOC_OVERFLOW testing macros also simply set_oom in the
case where a computation would overflow, so that callers don't
need to.
2015-02-12 22:54:47 -05:00
Edward Thomson
392702ee2c allocations: test for overflow of requested size
Introduce some helper macros to test integer overflow from arithmetic
and set error message appropriately.
2015-02-12 22:54:46 -05:00
Yury G. Kudryashov
1713653883 Reinit reader pointer after reading included config file
Fixes #2869. If included file includes more files, it may reallocate
cfg_file->readers, hence invalidate not only `r` pointer, but `result`
pointer as well.
2015-02-13 00:15:16 +03:00
Jacques Germishuys
6f73e02605 Plug some leaks 2014-12-29 18:18:49 +02:00
Will Stamper
b874629b2d Spelling fixes 2014-12-04 21:06:59 -06:00
John Fultz
ebc13b2b7c Clean up issues include.path issues found during code review.
* Error-handling is cleaned up to only let a file-not-found error
  through, not other sorts of errors.  And when a file-not-found
  error happens, we clean up the error.
* Test now checks that file-not-found introduces no error.  And
  other minor cleanups.
2014-11-02 19:16:49 -06:00
John Fultz
727ae380a5 Make config reading continue after hitting a missing include file.
For example, if you have

[include]
path = foo

and foo didn't exist, git_config_open_ondisk() would just give up
on the rest of the file.  Now it ignores the unresolved include
without error and continues reading the rest of the file.
2014-11-01 11:21:45 -05:00
Carlos Martín Nieto
55cb499972 config: remove the refresh function and backend field
We have been refreshing on read and write for a while now, so
git_config_refresh() is at best a no-op, and might just end up wasting
cycles.
2014-10-23 19:05:02 +02:00
Alan Rogers
ad5adacb1d Patch from @carlosmn to refresh the parent config before snapshotting. 2014-10-23 15:21:30 +11:00
Linquize
0a64164700 config: Fix multiple trailing spaces before comments not completely trimmed 2014-10-04 23:27:06 +08:00
Carlos Martín Nieto
9dac1f9579 config: a multiline var can start immediately
In the check for multiline, we traverse the backslashes from the end
backwards and int the end assert that we haven't gone past the beginning
of the line. We make sure of this in the loop condition, but we also
check in the return value.

However, for certain configurations, a line in a multiline variable
might be empty to aid formatting. In that case, 'end' == 'start', since
we ended up looking at the first char which made it a multiline.

There is no need for the (end > start) check in the return, since the
loop guarantees we won't go further back than the first char in the
line, and we do accept the first char to be the final backslash.

This fixes #2483.
2014-08-09 11:06:49 +02:00
Linquize
991dab2dd0 Make sure \n is at the end of config file before a new section is written 2014-07-16 21:09:53 +08:00
Philip Kelley
4af0ef9690 Fix mutex init/free in config_file.c 2014-05-15 11:09:49 -04:00
Russell Belfer
a37aa82ea6 Some coverity inspired cleanups 2014-05-13 15:54:23 -07:00
Russell Belfer
b1914c3651 Minor fixes for warnings and error propagation 2014-05-12 10:24:46 -07:00
Carlos Martín Nieto
2280b388c9 config: share the strmap on snapshot
Now that our strmap is no longer modified but replaced, we can use the
same strmap for the snapshot's values and it will be freed when we don't
need it anymore.
2014-04-18 16:13:43 +02:00
Carlos Martín Nieto
4b99b8f528 config: refcount the values map
This is mostly groundwork to let us re-use the map in the snapshots.
2014-04-18 16:12:31 +02:00
Carlos Martín Nieto
8c1f4ab4ab config: refresh on delete
When we delete an entry, we also want to refresh the configuration to
catch any changes that happened externally.

This allows us to simplify the logic, as we no longer need to delete
these variables internally. The whole state will be refreshed and the
deleted entries won't be there.
2014-04-18 16:07:33 +02:00
Carlos Martín Nieto
523032cd24 config: refresh before reading a value
With the isolation of complex reads, we can now try to refresh the
on-disk file before reading a value from it.

This changes the semantics a bit, as before we could be sure that a
string we got from the configuration was valid until we wrote or
refreshed. This is no longer the case, as a read can also invalidate the
pointer.
2014-04-18 16:07:33 +02:00
Carlos Martín Nieto
eaf3703401 config: refresh the values on write
When writing out, parse the resulting file instead of adding or
replacing the value locally. This has the effect of reading external
changes as well.
2014-04-18 16:07:33 +02:00
Carlos Martín Nieto
0500a1ef4e config: use a snapshot for the iterator 2014-04-18 16:07:32 +02:00
Carlos Martín Nieto
bd95f836f5 config: split out the refresh step
This will be used by the writing commands in a later step.
2014-04-18 16:07:32 +02:00
Carlos Martín Nieto
c047317e40 config: make refresh atomic
Current code sets the active map to a new one and builds it whilst it's
active. This is a race condition with someone else trying to access the
same config.

Instead, let's build up our new map and swap the active and new one.
2014-04-18 16:06:04 +02:00
Carlos Martín Nieto
55ebd7d369 config: implement config snapshotting
In order to have consistent views of the config files for remotes,
submodules et al. and a configuration that represents what is currently
stored on-disk, we need a way to provide a view of the configuration
that does not change.

The goal here is to provide the snapshotting part by creating a
read-only copy of the state of the configuration at a particular point
in time, which does not change when a repository's main config changes.
2014-04-18 16:03:01 +02:00
Russell Belfer
40ed499039 Add diff threading tests and attr file cache locks
This adds a basic test of doing simultaneous diffs on multiple
threads and adds basic locking for the attr file cache because
that was the immediate problem that arose from these tests.
2014-04-17 14:43:45 -07:00
Edward Thomson
83634d38be Move system directory cache out of utils 2014-02-24 17:52:38 -08:00
Arthur Schreiber
a8e4cb11fd Fix a memory leak in config_parse. 2014-01-13 22:17:07 +01:00
Robert Konrad
6014b7b59c Fixed a compile error in VS2013. 2014-01-02 15:10:32 +01:00
Russell Belfer
9f77b3f6f5 Add config read fns with controlled error behavior
This adds `git_config__lookup_entry` which will look up a key in
a config and return either the entry or NULL if the key was not
present.  Optionally, it can either suppress all errors or can
return them (although not finding the key is not an error for this
function).  Unlike other accessors, this does not normalize the
config key string, so it must only be used when the key is known
to be in normalized form (i.e. all lower-case before the first dot
and after the last dot, with no invalid characters).

This also adds three high-level helper functions to look up config
values with no errors and a fallback value.  The three functions
are for string, bool, and int values, and will resort to the
fallback value for any error that arises.  They are:

* `git_config__get_string_force`
* `git_config__get_bool_force`
* `git_config__get_int_force`

None of them normalize the config `key` either, so they can only
be used for internal cases where the key is known to be in normal
format.
2013-12-11 10:57:49 -08:00
Vicent Marti
a1d35ede18 config_file: style 2013-11-10 16:41:41 +01:00
Vicent Martí
b9cb72c28a Merge pull request #1950 from csware/quote-config-values
Correctly quote config values while saving
2013-11-10 07:33:11 -08:00
Sven Strickroth
590c5efb3b Rename method
Signed-off-by: Sven Strickroth <email@cs-ware.de>
2013-11-07 17:51:43 +01:00
Sven Strickroth
fde9325032 Correctly quote config values while saving
If the value contains a command (; or #) char or starts or ends with space it needs to be quoted.

Signed-off-by: Sven Strickroth <email@cs-ware.de>
2013-11-07 13:31:25 +01:00
nulltoken
61080a959d Fix leaks 2013-11-05 15:10:02 +01:00
nulltoken
e8162fd091 Propagate ELOCKED error when updating the config 2013-11-05 14:03:51 +01:00
Edward Thomson
1d3a8aeb4b move mode_t to filebuf_open instead of _commit 2013-11-04 22:33:05 -05:00
Carlos Martín Nieto
a7a64d2cad remote: don't write too much when dealing with multivars
We used to move `data_start` forward, which is wrong as that needs to
point to the beginning of the buffer in order to perform size
calculations.

Introduce a `write_start` variable which indicates where we should start
writing from, which is what the `data_start` was being wrongly reused to
be.
2013-11-02 18:54:55 +01:00
Vicent Marti
b22593fb64 config_file: Style fixes 2013-11-01 17:30:41 +01:00
Daniel Rodríguez Troitiño
a71331ebc4 Fix memory leaks. 2013-11-01 00:08:52 +01:00
Daniel Rodríguez Troitiño
3793fa9b18 Fix saving remotes with several fetch/push ref specs.
At some moment git_config_delete_entry lost the ability to delete one entry of
a multivar configuration. The moment you had more than one fetch or push
ref spec for a remote you will not be able to save that remote anymore. The
changes in network::remote::remotes::save show that problem.

I needed to create a new git_config_delete_multivar because I was not able to
remove one or several entries of a multivar config with the current API.
Several tries modifying how git_config_set_multivar(..., NULL) behaved were
not successful.

git_config_delete_multivar is very similar to git_config_set_multivar, and
delegates into config_delete_multivar of config_file. This function search
for the cvar_t that will be deleted, storing them in a temporal array, and
rebuilding the linked list. After calling config_write to delete the entries,
the cvar_t stored in the temporal array are freed.

There is a little fix in config_write, it avoids an infinite loop when using
a regular expression (case for the multivars). This error was found by the
test network::remote::remotes::tagopt.
2013-11-01 00:08:52 +01:00
Linquize
566dd8cec0 Config subsection name should allow to have ']' and '\\' should allow to escape any characters 2013-10-01 09:56:17 +08:00
Vicent Martí
92d19d1671 Merge pull request #1840 from linquize/warning
Fix warning
2013-09-21 09:34:03 -07:00
Linquize
66566516ce Fix warning 2013-09-19 23:14:06 +08:00
Russell Belfer
a9f51e430f Merge git_buf and git_buffer
This makes the git_buf struct that was used internally into an
externally available structure and eliminates the git_buffer.

As part of that, some of the special cases that arose with the
externally used git_buffer were blended into the git_buf, such as
being careful about git_buf objects that may have a NULL ptr and
allowing for bufs with a valid ptr and size but zero asize as a
way of referring to externally owned data.
2013-09-17 09:31:45 -07:00
Carlos Martín Nieto
53ea051371 config: handle realloc issues from larger depths
As the include depth increases, the chance of a realloc
increases. This means that whenever we run git_array_alloc() or call
config_parse(), we need to remember what our reader's index is so we
can look it up again.
2013-09-07 20:51:26 +02:00
Carlos Martín Nieto
6978992298 config: return an error when reaching the maximum include depth 2013-09-07 20:51:26 +02:00
Carlos Martín Nieto
73fc5e01c2 config: fix variable overriding
When two or more variables of the same name exist and the user asks
for a scalar, we must return the latest value assign to it.
2013-09-07 20:51:26 +02:00