Commit Graph

180 Commits

Author SHA1 Message Date
Vicent Marti
3286c408ec global: Properly use git__ memory wrappers
Ensure that all memory related functions (malloc, calloc, strdup, free,
etc) are using their respective `git__` wrappers.
2011-10-28 19:02:36 -07:00
Vicent Marti
11d51ca631 windows: Add support for non-UTF codepages
Our previous assumption that all paths in Windows are encoded in UTF-8
is rather weak, specially when considering that Git is
encoding-agnostic.

These set of functions allow the user to change the library's active
codepage globally, so it is possible to access paths and files on all
international versions of Windows.

Note that the default encoding here is UTF-8 because we assume that 99%
of all Git repositories will be in UTF-8.

Also, if you use non-ascii characters in paths, anywhere, please burn on
a fire.
2011-10-26 17:43:44 -07:00
Vicent Marti
fafd471021 config: Proper type declarations for 64 bit ints 2011-09-30 16:08:41 +02:00
Carlos Martín Nieto
358a15fd65 config: fix check for environment string expansion
If ExpandEnvironmentStringsW is successful, it returns the amount of
characters written, including the NUL terminator.

Thanks to Emeric for reading the MSDN documentation correctly.

Signed-off-by: Carlos Martín Nieto <carlos@cmartin.tk>
2011-09-30 15:46:49 +02:00
Vicent Marti
6c8b458dcc mingw: Fix compilation warnings 2011-09-29 17:04:45 +02:00
Vicent Marti
780bea6e26 mingw: Fix printf identifiers 2011-09-29 16:23:24 +02:00
Carlos Martín Nieto
a5b0e7f8bc Really fix MSVC
These was left over from the previous PRs.

Signed-off-by: Carlos Martín Nieto <carlos@cmartin.tk>
2011-09-27 20:08:15 +02:00
Carlos Martín Nieto
4c562347ae Add git_config_find_system
This allows the library to guess where the system configuration file
should be located.

Signed-off-by: Carlos Martín Nieto <carlos@cmartin.tk>
2011-09-27 14:39:38 +02:00
Vicent Marti
01d7fded1b Revert "Rewrite getenv to use Win32 version on Windows"
This reverts commit e1b8644467.
2011-09-27 14:33:18 +02:00
nulltoken
ad196c6ae6 config: make git_config_[get|set]_long() able to properly deal with 8 bytes wide values
Should fix issue #419.

Signed-off-by: nulltoken <emeric.fermas@gmail.com>
2011-09-22 18:58:47 +02:00
Paul Betts
e1b8644467 Rewrite getenv to use Win32 version on Windows 2011-09-21 12:00:34 -07:00
Vicent Martí
b3c524d104 Merge pull request #399 from carlosmn/free-null
Add checks for NULL to the config and remote free functions
2011-09-18 19:46:12 -07:00
Vicent Marti
87d9869fc3 Tabify everything
There were quite a few places were spaces were being used instead of
tabs. Try to catch them all. This should hopefully not break anything.
Except for `git blame`. Oh well.
2011-09-19 03:34:49 +03:00
Vicent Marti
bb742ede3d Cleanup legal data
1. The license header is technically not valid if it doesn't have a
copyright signature.

2. The COPYING file has been updated with the different licenses used in
the project.

3. The full GPLv2 header in each file annoys me.
2011-09-19 01:54:32 +03:00
Carlos Martín Nieto
2aae218881 Add checks for NULL to the config and remote free functions
Signed-off-by: Carlos Martín Nieto <carlos@cmartin.tk>
2011-09-13 02:05:12 +02:00
Vicent Marti
84dd3820d4 posix: Properly handle snprintf in all platforms 2011-08-18 02:35:28 +02:00
Vicent Marti
b08683ffb2 config: Rename del to `delete 2011-07-12 02:38:20 +02:00
Vicent Marti
de18f27668 vector: Timsort all of the things
Drop the GLibc implementation of Merge Sort and replace it with Timsort.

The algorithm has been tuned to work on arrays of pointers (void **),
so there's no longer a need to abstract the byte-width of each element
in the array.

All the comparison callbacks now take pointers-to-elements, not
pointers-to-pointers, so there's now one less level of dereferencing.

E.g.

	 int index_cmp(const void *a, const void *b)
	 {
	-	const git_index_entry *entry_a = *(const git_index_entry **)(a);
	+	const git_index_entry *entry_a = (const git_index_entry *)(a);

The result is up to a 40% speed-up when sorting vectors. Memory usage
remains lineal.

A new `bsearch` implementation has been added, whose callback also
supplies pointer-to-elements, to uniform the Vector API again.
2011-07-07 02:54:07 +02:00
Carlos Martín Nieto
86b5ab162c git_config_add_file should rethrow
Otherwise, the information about why there was an error gets lost.

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
Vicent Marti
19cb6857a4 config: Bring back git_config_open_global
Scott commands, I obey.
2011-06-18 01:50:48 +02:00
Vicent Marti
dbe70bd5c3 config: Fix compilation in MSVC 2011-06-18 01:12:58 +02:00
Vicent Marti
4007044553 config: Typorrrrl 2011-06-18 00:55:03 +02:00
Vicent Marti
07ff881750 config: Cleanup external API
Do not mess with environment variables anymore. The new external API has
more helper methods, and everything is explicit.
2011-06-18 00:39:39 +02:00
Carlos Martín Nieto
f3dad3acd7 Add fall-back support to the configuration
If a config has several files, we need to check all of them before we
can say that a variable doesn't exist.

Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-06-17 22:30:30 +02:00
Jakob Pfender
68384a27e5 config.c: Fix format string error 2011-05-23 20:45:13 +03:00
Vicent Marti
5c36f6dbe8 config: Cleanup 2011-05-23 20:43:19 +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 Marti
8adbf2ed12 Rewrite git_config_open_global
We have a lot of utility methods that make path building trivial. Use
them!
2011-05-20 02:58:33 +03:00
Carlos Martín Nieto
32234541f6 Implement git_config_open_global
Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-05-17 14:31:57 +02:00
Vicent Marti
0da2c70067 utils: Move git__str[n]tolower 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
Carlos Martín Nieto
094aaaaee9 config: store the section name separately
The section and variable names use different rules, so store them as
two different variables internally.

This will simplify the configuration-writing code as well later on,
but even with parsing, the code is simpler.

Take this opportunity to add a variable to the list directly when
parsing instead of passing through config_set.
2011-05-05 16:18:11 +02:00
Carlos Martín Nieto
0130d8184e Fix git__strntolower
Obviously, the whole string should be lower-cased and not just the
last char.

Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-04-27 11:20:38 +02:00
Carlos Martín Nieto
a68cf94b37 Fix const char ** warning
Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-04-19 16:40:52 +02:00
Carlos Martín Nieto
a99264bff6 config: allow uppercase number suffixes
Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-04-19 16:34:22 +02:00
Carlos Martín Nieto
52ca4f8a39 Use internal strtol
Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-04-11 17:51:05 +02:00
Carlos Martín Nieto
631752aaf6 Fix number suffix detection
Allow a number not to have a suffix. This broke when adding the
suffixes.

Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-04-11 17:50:22 +02:00
Carlos Martín Nieto
b075b9910c Add getting and setting of long int variables
long int is a safer type than int unless the user knows that the
variable is going to be quite small.

The code has been reworked to use strtol instead of the more
complicated sscanf.

Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-04-07 17:17:18 +02:00
Carlos Martín Nieto
7a4dfd6028 Simplify error path in config_set
Many error paths freed their local data althought it is freed later on
when the end of the function notices that there was an error. This can
cause double frees and invalid memory access.

Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-04-07 17:15:38 +02:00
Carlos Martín Nieto
493384e39c config: make cvar_free behave more like other free functions
Make cvar_free return void instad of the next element, as it was
mostly a hack to make cvar_list_free shorter but it's now using the
list macros.

Also check if the input is NULL and return immediately in that case.

Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-04-07 17:15:38 +02:00
Carlos Martín Nieto
6b45cb8a89 config: use and implement list macros
Use list macros instead of manually changing the head and/or tail of
the variable list.
2011-04-07 17:15:30 +02:00
Carlos Martín Nieto
0d280ea457 config: use snprintf instead of sprintf
Due to the preconditions, there should never be an error, but it pays
to be paranoid.

Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-04-06 16:31:06 +02:00
Carlos Martín Nieto
956ad0ed6f config: free the file buffer earlier
There is no need to keep config file in memory until the the
configuration is freed. Free the buffer immediately after the
configuration has been parsed.

Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-04-06 15:51:10 +02:00
Carlos Martín Nieto
acab3bc474 config: move str(n)tolower to the git__ namespace
Non-static functions in a library should always have a prefix
namespace.

Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-04-06 15:31:42 +02:00
Carlos Martín Nieto
aa793424d3 config: coding style fixes 2011-04-06 15:29:01 +02:00
Carlos Martín Nieto
6776fd514b config: really compare the variable name case-insensitively
Make cvar_name_match really compare the last part of the variable
ignoring the case.

Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-04-06 15:29:01 +02:00
Carlos Martín Nieto
2470be13f2 config: variable name on its own means true
If a variable name appears on its own in a line, it's assumed the
value is true. Store the variable name as NULL in that case.

Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-04-04 17:06:31 +02:00
Carlos Martín Nieto
9b7a6a9980 config: check for EOF before newline
If a line ends at EOF there is no need to check for the newline
character and doing so will cause us to read memory beyond the
allocatd memory as we check for the Windows-style new-line, which is
two bytes long.

Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-04-04 16:17:39 +02:00
Carlos Martín Nieto
72946881b5 config: support multiline values
If a variable value has the traditional continuation character (\) as
the last non-space character in the line, then we continue reading the
value on the next line.

Using more than two lines is also supported.

Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-04-04 15:33:26 +02:00
Carlos Martín Nieto
2454ce784f config: don't mix buffer reading methods
Make header and variable parse functions use their own buffers instead
of giving them the line they need to read as a parameter which they
mostly ignore.

This is in preparation for multiline configuration variables.

Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-04-04 15:33:26 +02:00
Carlos Martín Nieto
9f1b54d6d0 config: also free the file buffer on error
On error, the buffer containing the file contents also needs to be
freed.

Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-04-04 15:33:26 +02:00
Carlos Martín Nieto
fe116e261f config: Fix typo and remove debug statement
Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-04-04 15:33:26 +02:00
Carlos Martín Nieto
11d0e70578 Add support for subsections
A variable name is stored internally with its section the way it
appeared in the configuration file in order to have the information
about what parts are case-sensitive inline.

Really implement parse_section_header_ext and move the assignment of
variables to config_parse.

The variable name matching is now done in a case-away way by
cvar_name_match and cvar_section_match. Before the user sees it, it's
normalized to the two- or three-dot version.

Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-03-31 15:21:54 +02:00
Carlos Martín Nieto
6482929b5f move build_varname above parse_section 2011-03-31 15:05:12 +02:00
Carlos Martín Nieto
d7354d70b0 build_varname: lowercase the variable name
Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-03-31 15:05:12 +02:00
Carlos Martín Nieto
0bbaf9aaef config_parse: no need to check if current_section is non-null
Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-03-31 15:05:12 +02:00
Carlos Martín Nieto
923fe4557f Add strtolower and strntolower functions
As parts of variable names are case-sensitive, we need these functions.

Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-03-31 15:05:12 +02:00
Carlos Martín Nieto
df22949a35 config_set: really replace the value on overwrite
Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-03-31 15:05:12 +02:00
Carlos Martín Nieto
8ecc5ae5cb git_config_set_int: use the right buffer
Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-03-30 16:50:28 +02:00
Carlos Martín Nieto
dadc0158fb config: use a singly-linked list instead of a hash table
Such a list preserves the order the variables were first read in which
will be useful later for merging different data-sets. Furthermore,
reading and writing out the same configuration should not reorganize
the variables, which could happen when iterating through all the items
in a hash table.

A hash table is overkill for this small a data-set anyway.

Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-03-30 15:44:23 +02:00
Carlos Martín Nieto
d28830c255 Store the parsed variables
Store the key-value pair as strings.

Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-03-30 13:43:01 +02:00
Carlos Martín Nieto
934fcf78f2 Initialise the config reader in config_parse
git_config_open shouldn't have to initialise variables that are only
used inside config_parse and its callees.

Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-03-30 13:42:25 +02:00
Carlos Martín Nieto
2974aa94c3 Determine variable type at runtime
Config variables should be interpreted at run-time, as we don't know if a
zero means false or zero, or if yes means true or "yes".

As a variable has no intrinsic type, git_cvtype is gone and the public
API takes care of enforcing a few rules.

Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-03-30 13:42:24 +02:00
Carlos Martín Nieto
2e445cacd2 build_varname: allocate memory
Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-03-30 11:34:04 +02:00
Carlos Martín Nieto
9a3c5e55fd Expose config API for setters, getters and foreach
These functions can be used to query or modify the variables in a
given configuration. No sanity checking is done on the variable names.

This is mostly meant as an API preview.

Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-03-29 18:13:47 +02:00
Carlos Martín Nieto
26faa3668f Add build_varname to make a full var name
Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-03-29 18:13:47 +02:00
Carlos Martín Nieto
e15afc8e7c cvar_free: also free the config var's name
Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-03-29 18:07:01 +02:00
Carlos Martín Nieto
3d23b74af7 Free the config var hash contents in git_config_free
Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-03-29 13:50:37 +02:00
Carlos Martín Nieto
9f7f4122cf Don't leak if config parsing fails
Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-03-29 12:19:53 +02:00
Carlos Martín Nieto
4e02504f52 Move config to support the new hash code
The hashes have been copied from the references code

Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-03-29 12:17:29 +02:00
Carlos Martín Nieto
3b4835c25a Correctly parse the section header
If cfg_readline consumes the line, then parse_section_header will read
past it and if we read a character, parse_variable won't have the full
name.

This solution is a bit hackish, but it's the simplest way to get the
code to parse correctly.

Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-03-28 18:07:22 +02:00
Carlos Martín Nieto
908afb771a parse_section_header: save the name where it belongs
Save the location of the name in section_out instead of returning it
as an int. Use the return code to signal success or failure.

Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-03-28 17:53:04 +02:00
Carlos Martín Nieto
e4c796f1a2 Read and parse the confguration when openingt the config file
Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-03-28 17:51:18 +02:00
Carlos Martín Nieto
a69053c715 Convert config.c to LF
Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-03-28 17:12:53 +02:00
Carlos Martín Nieto
5d4cd00305 Move the struct declaration outside config.c
Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-03-28 17:03:08 +02:00
Vicent Marti
a3002d5694 First version - WIP
Signed-off-by: Vicent Marti <tanoku@gmail.com>
2011-03-06 00:21:48 +02:00