Commit Graph

178 Commits

Author SHA1 Message Date
schu
5a0659fe3b config_file.c: fix memory leaks
Signed-off-by: schu <schu-github@schulog.org>
2011-08-17 14:36:53 +02:00
Carlos Martín Nieto
f58c53ce66 Correctly detect truncated input in header parsing
If the section header is the last line in the file,
parse_section_header would incorrectly decide that the input had been
truncated.

Fix this by checking whether the actual input line is correctly
formatted.

Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-07-05 02:32:17 +02:00
Carlos Martín Nieto
6d4b609718 Add git_config_del to delete a variable
Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-07-05 02:31:26 +02:00
Vicent Marti
f79026b491 fileops: Cleanup
Cleaned up the structure of the whole OS-abstraction layer.

fileops.c now contains a set of utility methods for file management used
by the library. These are abstractions on top of the original POSIX
calls.

There's a new file called `posix.c` that contains
emulations/reimplementations of all the POSIX calls the library uses.
These are prefixed with `p_`. There's a specific posix file for each
platform (win32 and unix).

All the path-related methods have been moved from `utils.c` to `path.c`
and have their own prefix.
2011-07-05 02:04:03 +02:00
Vicent Marti
cfef5fb779 config: foreach now returns variable values too 2011-06-29 15:09:21 +02:00
Carlos Martín Nieto
b76934de6c Remove double-space
Noticed by txdv

Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-06-17 22:30:29 +02:00
Vicent Marti
c716b1878e config: Fix unitialized variable warning 2011-06-17 19:47:58 +02:00
Carlos Martín Nieto
b2e361cc5e Plug two leaks in config writing
Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-06-16 20:22:05 +02:00
Carlos Martín Nieto
711b1096f3 Indent config variables with tags
Confg variables are indended using tags and not four spaces as was
being done by the code.

Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-06-14 13:09:40 +02:00
Carlos Martín Nieto
8bb198e674 config: implement config writing
After each variable gets set, we store it in our list (not completely
in the right position, but the close enough). Then we write out the
new config file in the same way that git.git does it (keep the rest of
the file intact and insert or replace the variable in its line).

Overwriting variables and adding new ones is supported (even on new
sections), though deleting isn't yet.

Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-06-08 00:23:25 +02:00
Carlos Martín Nieto
3b3577c764 config: store new variables with the internal representation of the section
The section name should be stored in its case-sensitive variant when
we are adding a new variable. Use the internalize_section function to
do just that.

Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-06-08 00:23:12 +02:00
Carlos Martín Nieto
5ab50417b7 Remove an unfortunate optimisation from cvar_match_section
The (rather late) early-exit code, which provides a negligible
optimisation causes cvar_match_section to return false negatives when
it's called with a section name instead of a full variable name.

Remove this optimisation.

Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-06-08 00:12:26 +02:00
Carlos Martín Nieto
c7e6e95841 Don't try to parse an empty config file
Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-05-31 17:57:18 +02:00
Carlos Martín Nieto
5892277cd0 Config parse header ext: don't allow text after closing quote
Nothing is allowed betwen the closing quotation mark and the ] so
return an error if there is.

Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-05-31 17:33:24 +02:00
Carlos Martín Nieto
7288d8b65c Parse section header ext: don't leak on error
Also free the subsection if we find too many quotes

Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-05-31 17:33:24 +02:00
Carlos Martín Nieto
7bc9e2aa2f Guard against double-freeing the current section
If parse_section_header{,_ext} return an error, current_section
doesn't get allocated. Set it to NULL after freeing so we don't try to
free it again.

This fixes part 2-2 of Issue #210.

Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-05-31 17:33:23 +02:00
Carlos Martín Nieto
f2abee47d8 cfg_readline: really ignore empty lines
Simplify cfg_readline and at the same time fix it so that it does
really ignore empty lines.

This fixes point 2-1 of Issue #210

Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-05-31 17:33:23 +02:00
Carlos Martín Nieto
a5f43b9536 Config file open: don't free memory that doesn't belong to us
On error, it would free the configuration object even though it didn't
own that memory, which would cause a double-free.

This fixes the first part of Issue #210

Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-05-31 17:33:23 +02:00
nulltoken
3a1c431011 Fix compilation warnings in MSVC
This allows to successfully build libgit2 with waf on Windows.
2011-05-24 18:55:35 +02:00
Jakob Pfender
ec9edd5657 config_file.c: Move to new error handling mechanism 2011-05-23 21:38:44 +03:00
Vicent Marti
b0b527e0ad config: Cleanup & renaming of the external API
"git_config_backend" have been renamed to "git_config_file", which
implements a generic interface to access a configuration file -- be it
either on disk, from a DB or whatever mumbojumbo.

I think this makes more sense.
2011-05-20 03:20:12 +03:00
Vicent Martí
274f2c213f Merge pull request #193 from carlosmn/config
A couple of config improvements
2011-05-19 14:18:57 -07:00
Sebastian Schuberth
8133afefe3 Fix a few minor typos in comments and error messages
Regarding "initialize" vs. "initialise", www.dict.cc says the first is American
English whereas the latter in British English. For consistency, we should
stick to American English.
2011-05-19 09:34:58 +02:00
Sebastian Schuberth
765fdf4a0e Use "__inline" instead of "inline" with MSVC
MSVC supports "inline" only in C++ code, not in C code.
2011-05-18 17:31:24 +02:00
Carlos Martín Nieto
6421c49a37 Fix variable name normalization
When I changed it over to use different strings for the variable and
the name, cvar_name_normalize was left behind. Fix this and rename to
cvar_normalize_name to reflect the incompatible change.

Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-05-17 19:03:42 +02:00
Vicent Marti
128d37316b config_file: Fix compilation 2011-05-17 15:11:19 +03:00
Carlos Martín Nieto
29dca0883f Move config to the new error methods
Take this opportunity to fix an instance of returning
GIT_EOBJCORRUPTED when malloc failed.

Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-05-17 13:41:42 +02:00
Carlos Martín Nieto
c033500549 Move config to a backend structure
Configuration options can come from different sources. Currently,
there is only support for reading them from a flat file, but it might
make sense to read it from a database at some point.

Move the parsing code into src/config_file.c and create an include
file include/git2/config_backend.h to allow for other backends to be
developed.

Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-05-10 14:47:20 +02:00