Commit Graph

205 Commits

Author SHA1 Message Date
Russell Belfer
ca1b6e5409 Add template dir and set gid to repo init
This extends git_repository_init_ext further with support for
initializing the repository from an external template directory
and with support for the "create shared" type flags that make a
set GID repository directory.

This also adds tests for much of the new functionality to the
existing `repo/init.c` test suite.

Also, this adds a bunch of new utility functions including a
very general purpose `git_futils_mkdir` (with the ability to
make paths and to chmod the paths post-creation) and a file
tree copying function `git_futils_cp_r`.  Also, this includes
some new path functions that were useful to keep the code
simple.
2012-08-22 16:07:19 -07:00
nulltoken
b8457baae2 portability: Improve x86/amd64 compatibility 2012-07-24 16:10:12 +02:00
Russell Belfer
b3ff1dab31 Adding git_config_foreach_match() iteration fn
Adding a new config iteration function that let's you iterate
over just the config entries that match a particular regular
expression.  The old foreach becomes a simple use of this with
an empty pattern.

This also fixes an apparent bug in the existing `git_config_foreach`
where returning a non-zero value from the iteration callback was
not correctly aborting the iteration and the returned value was
not being propogated back to the caller of foreach.

Added to tests to cover all these changes.
2012-07-10 23:19:47 -07:00
Michael Schubert
e203e9d472 config: do not set an error for GIT_ENOTFOUND
An unset config variable isn't bad per se -- let the call site set an
error in case GIT_ENOTFOUND isn't acceptable.
2012-05-19 18:57:13 +02:00
Vicent Martí
904b67e69f errors: Rename error codes 2012-05-18 01:48:50 +02:00
Vicent Martí
e172cf082e errors: Rename the generic return codes 2012-05-18 01:26:26 +02:00
Vicent Martí
29e948debe global: Change parameter ordering in API
Consistency is good.
2012-05-18 01:25:57 +02:00
Vicent Martí
3fbcac89c4 Remove old and unused error codes 2012-05-02 19:56:38 -07:00
Russell Belfer
01fed0a8f9 Convert hashtable usage over to khash
This updates khash.h with some extra features (like error checking
on allocations, ability to use wrapped malloc, foreach calls, etc),
creates two high-level wrappers around khash: `git_khash_str` and
`git_khash_oid` for string-to-void-ptr and oid-to-void-ptr tables,
then converts all of the old usage of `git_hashtable` over to use
these new hashtables.

For `git_khash_str`, I've tried to create a set of macros that
yield an API not too unlike the old `git_hashtable` API.  Since
the oid hashtable is only used in one file, I haven't bother to
set up all those macros and just use the khash APIs directly for
now.
2012-04-25 11:18:08 -07:00
Russell Belfer
7784bcbbee Refactor git_repository_open with new options
Add a new command `git_repository_open_ext` with extended options
that control how searching for a repository will be done.  The
existing `git_repository_open` and `git_repository_discover` are
reimplemented on top of it.  We may want to change the default
behavior of `git_repository_open` but this commit does not do that.

Improve support for "gitdir" files where the work dir is separate
from the repo and support for the "separate-git-dir" config.  Also,
add support for opening repos created with `git-new-workdir` script
(although I have only confirmed that they can be opened, not that
all functions work correctly).

There are also a few minor changes that came up:

- Fix `git_path_prettify` to allow in-place prettifying.

- Fix `git_path_root` to support backslashes on Win32.  This fix
  should help many repo open/discover scenarios - it is the one
  function called when opening before prettifying the path.

- Tweak `git_config_get_string` to set the "out" pointer to NULL
  if the config value is not found.  Allows some other cleanup.

- Fix a couple places that should have been calling
  `git_repository_config__weakptr` and were not.

- Fix `cl_git_sandbox_init` clar helper to support bare repos.
2012-04-11 12:11:35 -07:00
Russell Belfer
95dfb031f7 Improve config handling for diff,submodules,attrs
This adds support for a bunch of core.* settings that affect
diff and status, plus fixes up some incorrect implementations
of those settings from before.  Also, this cleans up the
handling of config settings in the new submodules code and
in the old attrs/ignore code.
2012-03-30 14:40:50 -07:00
Russell Belfer
bfc9ca595a Added submodule API and use in status
When processing status for a newly checked out repo, it is
possible that there will be submodules that have not yet been
initialized.  The only way to distinguish these from untracked
directories is to have some knowledge of submodules.  This
commit adds a new submodule API which, given a name or path,
can determine if it appears to be a submodule and can give
information about the submodule.
2012-03-28 16:45:36 -07:00
Vicent Martí
dda708e78f error-handling: On-disk config file backend
Includes:

	- Proper error reporting when encountering syntax errors in a
	config file (file, line number, column).

	- Rewritten `config_write`, now with 99% less goto-spaghetti

	- Error state in `git_filebuf`: filebuf write functions no longer
	need to be checked for error returns. If any of the writes performed
	on a buffer fail, the last call to `git_filebuf_commit` or
	`git_filebuf_hash` will fail accordingly and set the appropiate error
	message. Baller!
2012-03-09 20:09:22 +01:00
Vicent Martí
e54d8d8972 error-handling: Config 2012-03-07 01:37:09 +01:00
Vicent Martí
c5e944820a config: Refactor & add git_config_get_mapped
Sane API for real-world usage.
2012-03-01 00:52:21 +01:00
Carlos Martín Nieto
3005855f7e Implement setting multivars 2012-02-17 19:50:30 +01:00
Carlos Martín Nieto
5e0dc4af01 Support getting multivars 2012-02-17 19:43:43 +01:00
schu
5e0de32818 Update Copyright header
Signed-off-by: schu <schu-github@schulog.org>
2012-02-13 17:11:09 +01:00
Russell Belfer
2d8405025d Throw first error in chain, not rethrow.
This is the first time this error is throw, so use git__throw instead
of git__rethrow.
2012-01-05 15:03:42 -08:00
Vicent Martí
9191a6d246 Merge remote-tracking branch 'arrbee/git-attributes' into development
Conflicts:
	tests-clay/clay_main.c
2012-01-02 09:56:48 +01:00
Vicent Martí
9dd4c3e806 config: Rename the delete callback name
`delete` is a reserved keyword in C++.
2011-12-31 05:58:26 +01:00
Russell Belfer
73b51450a3 Add support for macros and cache flush API.
Add support for git attribute macro definitions.  Also, add
support for cache flush API to clear the attribute file content
cache when needed.

Additionally, improved the handling of global and system files,
making common utility functions in fileops and converting config
and attr to both use the common functions.

Adds a bunch more tests and fixed some memory leaks.  Note that
adding macros required me to use refcounted attribute assignment
definitions, which complicated, but probably improved memory usage.
2011-12-29 00:01:10 -08:00
Carlos Martín Nieto
80a665aaca config: really delete variables
Instead of just setting the value to NULL, which gives unwanted
results when asking for that variable after deleting it, delete the
variable from the list and re-write the file.
2011-12-16 02:28:39 +01:00
Russell Belfer
97769280ba Use git_buf for path storage instead of stack-based buffers
This converts virtually all of the places that allocate GIT_PATH_MAX
buffers on the stack for manipulating paths to use git_buf objects
instead.  The patch is pretty careful not to touch the public API
for libgit2, so there are a few places that still use GIT_PATH_MAX.

This extends and changes some details of the git_buf implementation
to add a couple of extra functions and to make error handling easier.

This includes serious alterations to all the path.c functions, and
several of the fileops.c ones, too.  Also, there are a number of new
functions that parallel existing ones except that use a git_buf
instead of a stack-based buffer (such as git_config_find_global_r
that exists alongsize git_config_find_global).

This also modifies the win32 version of p_realpath to allocate whatever
buffer size is needed to accommodate the realpath instead of hardcoding
a GIT_PATH_MAX limit, but that change needs to be tested still.
2011-12-07 23:08:15 -08:00
Vicent Marti
9462c47143 repository: Change ownership semantics
The ownership semantics have been changed all over the library to be
consistent. There are no more "borrowed" or duplicated references.

Main changes:

	- `git_repository_open2` and `3` have been dropped.

	- Added setters and getters to hotswap all the repository owned
	objects:

		`git_repository_index`
		`git_repository_set_index`
		`git_repository_odb`
		`git_repository_set_odb`
		`git_repository_config`
		`git_repository_set_config`
		`git_repository_workdir`
		`git_repository_set_workdir`

	Now working directories/index files/ODBs and so on can be
	hot-swapped after creating a repository and between operations.

	- All these objects now have proper ownership semantics with
	refcounting: they all require freeing after they are no longer
	needed (the repository always keeps its internal reference).

	- Repository open and initialization has been updated to keep in
	mind the configuration files. Bare repositories are now always
	detected, and a default config file is created on init.

	- All the tests affected by these changes have been dropped from the
	old test suite and ported to the new one.
2011-11-26 08:37:08 +01:00
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