Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
git2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
git2
Commits
fafd4710
Commit
fafd4710
authored
Sep 30, 2011
by
Vicent Marti
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
config: Proper type declarations for 64 bit ints
parent
358a15fd
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
80 additions
and
69 deletions
+80
-69
include/git2/config.h
+4
-4
src/config.c
+36
-26
src/util.c
+6
-5
src/util.h
+2
-2
tests/t15-config.c
+32
-32
No files found.
include/git2/config.h
View file @
fafd4710
...
...
@@ -166,7 +166,7 @@ GIT_EXTERN(void) git_config_free(git_config *cfg);
* @param out pointer to the variable where the value should be stored
* @return GIT_SUCCESS or an error code
*/
GIT_EXTERN
(
int
)
git_config_get_int
(
git_config
*
cfg
,
const
char
*
name
,
in
t
*
out
);
GIT_EXTERN
(
int
)
git_config_get_int
32
(
git_config
*
cfg
,
const
char
*
name
,
int32_
t
*
out
);
/**
* Get the value of a long integer config variable.
...
...
@@ -176,7 +176,7 @@ GIT_EXTERN(int) git_config_get_int(git_config *cfg, const char *name, int *out);
* @param out pointer to the variable where the value should be stored
* @return GIT_SUCCESS or an error code
*/
GIT_EXTERN
(
int
)
git_config_get_
long
(
git_config
*
cfg
,
const
char
*
name
,
long
long
*
out
);
GIT_EXTERN
(
int
)
git_config_get_
int64
(
git_config
*
cfg
,
const
char
*
name
,
int64_t
*
out
);
/**
* Get the value of a boolean config variable.
...
...
@@ -212,7 +212,7 @@ GIT_EXTERN(int) git_config_get_string(git_config *cfg, const char *name, const c
* @param value Integer value for the variable
* @return GIT_SUCCESS or an error code
*/
GIT_EXTERN
(
int
)
git_config_set_int
(
git_config
*
cfg
,
const
char
*
name
,
in
t
value
);
GIT_EXTERN
(
int
)
git_config_set_int
32
(
git_config
*
cfg
,
const
char
*
name
,
int32_
t
value
);
/**
* Set the value of a long integer config variable.
...
...
@@ -222,7 +222,7 @@ GIT_EXTERN(int) git_config_set_int(git_config *cfg, const char *name, int value)
* @param value Long integer value for the variable
* @return GIT_SUCCESS or an error code
*/
GIT_EXTERN
(
int
)
git_config_set_
long
(
git_config
*
cfg
,
const
char
*
name
,
long
long
value
);
GIT_EXTERN
(
int
)
git_config_set_
int64
(
git_config
*
cfg
,
const
char
*
name
,
int64_t
value
);
/**
* Set the value of a boolean config variable.
...
...
src/config.c
View file @
fafd4710
...
...
@@ -164,16 +164,16 @@ int git_config_delete(git_config *cfg, const char *name)
* Setters
**************/
int
git_config_set_
long
(
git_config
*
cfg
,
const
char
*
name
,
long
long
value
)
int
git_config_set_
int64
(
git_config
*
cfg
,
const
char
*
name
,
int64_t
value
)
{
char
str_value
[
32
];
/* All numbers should fit in here */
p_snprintf
(
str_value
,
sizeof
(
str_value
),
"%"
PRId64
,
value
);
return
git_config_set_string
(
cfg
,
name
,
str_value
);
}
int
git_config_set_int
(
git_config
*
cfg
,
const
char
*
name
,
in
t
value
)
int
git_config_set_int
32
(
git_config
*
cfg
,
const
char
*
name
,
int32_
t
value
)
{
return
git_config_set_
long
(
cfg
,
name
,
(
long
long
)
value
);
return
git_config_set_
int64
(
cfg
,
name
,
(
int64_t
)
value
);
}
int
git_config_set_bool
(
git_config
*
cfg
,
const
char
*
name
,
int
value
)
...
...
@@ -199,11 +199,11 @@ int git_config_set_string(git_config *cfg, const char *name, const char *value)
* Getters
***********/
int
git_config_get_
long
(
git_config
*
cfg
,
const
char
*
name
,
long
long
*
out
)
int
git_config_get_
int64
(
git_config
*
cfg
,
const
char
*
name
,
int64_t
*
out
)
{
const
char
*
value
,
*
num_end
;
int
ret
;
long
long
num
;
int64_t
num
;
ret
=
git_config_get_string
(
cfg
,
name
,
&
value
);
if
(
ret
<
GIT_SUCCESS
)
...
...
@@ -214,35 +214,45 @@ int git_config_get_long(git_config *cfg, const char *name, long long *out)
return
git__rethrow
(
ret
,
"Failed to convert value for '%s'"
,
name
);
switch
(
*
num_end
)
{
case
'\0'
:
break
;
case
'k'
:
case
'K'
:
case
'g'
:
case
'G'
:
num
*=
1024
;
break
;
/* fallthrough */
case
'm'
:
case
'M'
:
num
*=
1024
*
1024
;
break
;
case
'g'
:
case
'G'
:
num
*=
1024
*
1024
*
1024
;
break
;
default:
return
git__throw
(
GIT_EINVALIDTYPE
,
"Failed to get value for '%s'. Value is of invalid type"
,
name
);
}
num
*=
1024
;
/* fallthrough */
*
out
=
num
;
case
'k'
:
case
'K'
:
num
*=
1024
;
return
GIT_SUCCESS
;
/* check that that there are no more characters after the
* given modifier suffix */
if
(
num_end
[
1
]
!=
'\0'
)
return
git__throw
(
GIT_EINVALIDTYPE
,
"Failed to get value for '%s'. Invalid type suffix"
,
name
);
/* fallthrough */
case
'\0'
:
*
out
=
num
;
return
GIT_SUCCESS
;
default:
return
git__throw
(
GIT_EINVALIDTYPE
,
"Failed to get value for '%s'. Value is of invalid type"
,
name
);
}
}
int
git_config_get_int
(
git_config
*
cfg
,
const
char
*
name
,
in
t
*
out
)
int
git_config_get_int
32
(
git_config
*
cfg
,
const
char
*
name
,
int32_
t
*
out
)
{
long
long
tmp_long
;
int
tmp_int
,
ret
;
int64_t
tmp_long
;
int32_t
tmp_int
;
int
ret
;
ret
=
git_config_get_
long
(
cfg
,
name
,
&
tmp_long
);
ret
=
git_config_get_
int64
(
cfg
,
name
,
&
tmp_long
);
if
(
ret
<
GIT_SUCCESS
)
return
git__rethrow
(
ret
,
"Failed to convert value for '%s'"
,
name
);
...
...
@@ -284,7 +294,7 @@ int git_config_get_bool(git_config *cfg, const char *name, int *out)
}
/* Try to parse it as an integer */
error
=
git_config_get_int
(
cfg
,
name
,
out
);
error
=
git_config_get_int
32
(
cfg
,
name
,
out
);
if
(
error
==
GIT_SUCCESS
)
*
out
=
!!
(
*
out
);
...
...
src/util.c
View file @
fafd4710
...
...
@@ -46,10 +46,10 @@ int git__fnmatch(const char *pattern, const char *name, int flags)
}
}
int
git__strtol64
(
long
long
*
result
,
const
char
*
nptr
,
const
char
**
endptr
,
int
base
)
int
git__strtol64
(
int64_t
*
result
,
const
char
*
nptr
,
const
char
**
endptr
,
int
base
)
{
const
char
*
p
;
long
long
n
,
nn
;
int64_t
n
,
nn
;
int
c
,
ovfl
,
v
,
neg
,
ndig
;
p
=
nptr
;
...
...
@@ -124,10 +124,11 @@ Return:
return
GIT_SUCCESS
;
}
int
git__strtol32
(
int
*
result
,
const
char
*
nptr
,
const
char
**
endptr
,
int
base
)
int
git__strtol32
(
int
32_t
*
result
,
const
char
*
nptr
,
const
char
**
endptr
,
int
base
)
{
int
tmp_int
,
error
=
GIT_SUCCESS
;
long
long
tmp_long
;
int
error
=
GIT_SUCCESS
;
int32_t
tmp_int
;
int64_t
tmp_long
;
if
((
error
=
git__strtol64
(
&
tmp_long
,
nptr
,
endptr
,
base
))
<
GIT_SUCCESS
)
return
error
;
...
...
src/util.h
View file @
fafd4710
...
...
@@ -75,8 +75,8 @@ GIT_INLINE(void *) git__realloc(void *ptr, size_t size)
extern
int
git__prefixcmp
(
const
char
*
str
,
const
char
*
prefix
);
extern
int
git__suffixcmp
(
const
char
*
str
,
const
char
*
suffix
);
extern
int
git__strtol32
(
int
*
n
,
const
char
*
buff
,
const
char
**
end_buf
,
int
base
);
extern
int
git__strtol64
(
long
long
*
n
,
const
char
*
buff
,
const
char
**
end_buf
,
int
base
);
extern
int
git__strtol32
(
int
32_t
*
n
,
const
char
*
buff
,
const
char
**
end_buf
,
int
base
);
extern
int
git__strtol64
(
int64_t
*
n
,
const
char
*
buff
,
const
char
**
end_buf
,
int
base
);
extern
void
git__hexdump
(
const
char
*
buffer
,
size_t
n
);
extern
uint32_t
git__hash
(
const
void
*
key
,
int
len
,
uint32_t
seed
);
...
...
tests/t15-config.c
View file @
fafd4710
...
...
@@ -37,10 +37,10 @@
*/
BEGIN_TEST
(
config0
,
"read a simple configuration"
)
git_config
*
cfg
;
int
i
;
int
32_t
i
;
must_pass
(
git_config_open_ondisk
(
&
cfg
,
CONFIG_BASE
"/config0"
));
must_pass
(
git_config_get_int
(
cfg
,
"core.repositoryformatversion"
,
&
i
));
must_pass
(
git_config_get_int
32
(
cfg
,
"core.repositoryformatversion"
,
&
i
));
must_be_true
(
i
==
0
);
must_pass
(
git_config_get_bool
(
cfg
,
"core.filemode"
,
&
i
));
must_be_true
(
i
==
1
);
...
...
@@ -134,29 +134,29 @@ END_TEST
BEGIN_TEST
(
config5
,
"test number suffixes"
)
git_config
*
cfg
;
long
long
i
;
int64_t
i
;
must_pass
(
git_config_open_ondisk
(
&
cfg
,
CONFIG_BASE
"/config5"
));
must_pass
(
git_config_get_
long
(
cfg
,
"number.simple"
,
&
i
));
must_pass
(
git_config_get_
int64
(
cfg
,
"number.simple"
,
&
i
));
must_be_true
(
i
==
1
);
must_pass
(
git_config_get_
long
(
cfg
,
"number.k"
,
&
i
));
must_pass
(
git_config_get_
int64
(
cfg
,
"number.k"
,
&
i
));
must_be_true
(
i
==
1
*
1024
);
must_pass
(
git_config_get_
long
(
cfg
,
"number.kk"
,
&
i
));
must_pass
(
git_config_get_
int64
(
cfg
,
"number.kk"
,
&
i
));
must_be_true
(
i
==
1
*
1024
);
must_pass
(
git_config_get_
long
(
cfg
,
"number.m"
,
&
i
));
must_pass
(
git_config_get_
int64
(
cfg
,
"number.m"
,
&
i
));
must_be_true
(
i
==
1
*
1024
*
1024
);
must_pass
(
git_config_get_
long
(
cfg
,
"number.mm"
,
&
i
));
must_pass
(
git_config_get_
int64
(
cfg
,
"number.mm"
,
&
i
));
must_be_true
(
i
==
1
*
1024
*
1024
);
must_pass
(
git_config_get_
long
(
cfg
,
"number.g"
,
&
i
));
must_pass
(
git_config_get_
int64
(
cfg
,
"number.g"
,
&
i
));
must_be_true
(
i
==
1
*
1024
*
1024
*
1024
);
must_pass
(
git_config_get_
long
(
cfg
,
"number.gg"
,
&
i
));
must_pass
(
git_config_get_
int64
(
cfg
,
"number.gg"
,
&
i
));
must_be_true
(
i
==
1
*
1024
*
1024
*
1024
);
git_config_free
(
cfg
);
...
...
@@ -195,37 +195,37 @@ END_TEST
BEGIN_TEST
(
config9
,
"replace a value"
)
git_config
*
cfg
;
int
i
;
long
long
l
,
expected
=
+
9223372036854775803
;
int64_t
l
,
expected
=
+
9223372036854775803
;
/* By freeing the config, we make sure we flush the values */
must_pass
(
git_config_open_ondisk
(
&
cfg
,
CONFIG_BASE
"/config9"
));
must_pass
(
git_config_set_int
(
cfg
,
"core.dummy"
,
5
));
must_pass
(
git_config_set_int
32
(
cfg
,
"core.dummy"
,
5
));
git_config_free
(
cfg
);
must_pass
(
git_config_open_ondisk
(
&
cfg
,
CONFIG_BASE
"/config9"
));
must_pass
(
git_config_get_int
(
cfg
,
"core.dummy"
,
&
i
));
must_pass
(
git_config_get_int
32
(
cfg
,
"core.dummy"
,
&
i
));
must_be_true
(
i
==
5
);
git_config_free
(
cfg
);
must_pass
(
git_config_open_ondisk
(
&
cfg
,
CONFIG_BASE
"/config9"
));
must_pass
(
git_config_set_int
(
cfg
,
"core.dummy"
,
1
));
must_pass
(
git_config_set_int
32
(
cfg
,
"core.dummy"
,
1
));
git_config_free
(
cfg
);
must_pass
(
git_config_open_ondisk
(
&
cfg
,
CONFIG_BASE
"/config9"
));
must_pass
(
git_config_set_
long
(
cfg
,
"core.verylong"
,
expected
));
must_pass
(
git_config_set_
int64
(
cfg
,
"core.verylong"
,
expected
));
git_config_free
(
cfg
);
must_pass
(
git_config_open_ondisk
(
&
cfg
,
CONFIG_BASE
"/config9"
));
must_pass
(
git_config_get_
long
(
cfg
,
"core.verylong"
,
&
l
));
must_pass
(
git_config_get_
int64
(
cfg
,
"core.verylong"
,
&
l
));
must_be_true
(
l
==
expected
);
git_config_free
(
cfg
);
must_pass
(
git_config_open_ondisk
(
&
cfg
,
CONFIG_BASE
"/config9"
));
must_fail
(
git_config_get_int
(
cfg
,
"core.verylong"
,
&
i
));
must_fail
(
git_config_get_int
32
(
cfg
,
"core.verylong"
,
&
i
));
git_config_free
(
cfg
);
must_pass
(
git_config_open_ondisk
(
&
cfg
,
CONFIG_BASE
"/config9"
));
must_pass
(
git_config_set_
long
(
cfg
,
"core.verylong"
,
1
));
must_pass
(
git_config_set_
int64
(
cfg
,
"core.verylong"
,
1
));
git_config_free
(
cfg
);
END_TEST
...
...
@@ -233,11 +233,11 @@ END_TEST
BEGIN_TEST
(
config10
,
"a repo's config overrides the global config"
)
git_repository
*
repo
;
git_config
*
cfg
;
int
version
;
int
32_t
version
;
must_pass
(
git_repository_open
(
&
repo
,
REPOSITORY_FOLDER
));
must_pass
(
git_repository_config
(
&
cfg
,
repo
,
GLOBAL_CONFIG
,
NULL
));
must_pass
(
git_config_get_int
(
cfg
,
"core.repositoryformatversion"
,
&
version
));
must_pass
(
git_config_get_int
32
(
cfg
,
"core.repositoryformatversion"
,
&
version
));
must_be_true
(
version
==
0
);
git_config_free
(
cfg
);
git_repository_free
(
repo
);
...
...
@@ -246,11 +246,11 @@ END_TEST
BEGIN_TEST
(
config11
,
"fall back to the global config"
)
git_repository
*
repo
;
git_config
*
cfg
;
int
num
;
int
32_t
num
;
must_pass
(
git_repository_open
(
&
repo
,
REPOSITORY_FOLDER
));
must_pass
(
git_repository_config
(
&
cfg
,
repo
,
GLOBAL_CONFIG
,
NULL
));
must_pass
(
git_config_get_int
(
cfg
,
"core.something"
,
&
num
));
must_pass
(
git_config_get_int
32
(
cfg
,
"core.something"
,
&
num
));
must_be_true
(
num
==
2
);
git_config_free
(
cfg
);
git_repository_free
(
repo
);
...
...
@@ -258,11 +258,11 @@ END_TEST
BEGIN_TEST
(
config12
,
"delete a value"
)
git_config
*
cfg
;
int
i
;
int
32_t
i
;
/* By freeing the config, we make sure we flush the values */
must_pass
(
git_config_open_ondisk
(
&
cfg
,
CONFIG_BASE
"/config9"
));
must_pass
(
git_config_set_int
(
cfg
,
"core.dummy"
,
5
));
must_pass
(
git_config_set_int
32
(
cfg
,
"core.dummy"
,
5
));
git_config_free
(
cfg
);
must_pass
(
git_config_open_ondisk
(
&
cfg
,
CONFIG_BASE
"/config9"
));
...
...
@@ -270,8 +270,8 @@ BEGIN_TEST(config12, "delete a value")
git_config_free
(
cfg
);
must_pass
(
git_config_open_ondisk
(
&
cfg
,
CONFIG_BASE
"/config9"
));
must_be_true
(
git_config_get_int
(
cfg
,
"core.dummy"
,
&
i
)
==
GIT_ENOTFOUND
);
must_pass
(
git_config_set_int
(
cfg
,
"core.dummy"
,
1
));
must_be_true
(
git_config_get_int
32
(
cfg
,
"core.dummy"
,
&
i
)
==
GIT_ENOTFOUND
);
must_pass
(
git_config_set_int
32
(
cfg
,
"core.dummy"
,
1
));
git_config_free
(
cfg
);
END_TEST
...
...
@@ -294,12 +294,12 @@ END_TEST
BEGIN_TEST
(
config15
,
"add a variable in an existing section"
)
git_config
*
cfg
;
int
i
;
int
32_t
i
;
/* By freeing the config, we make sure we flush the values */
must_pass
(
git_config_open_ondisk
(
&
cfg
,
CONFIG_BASE
"/config10"
));
must_pass
(
git_config_set_int
(
cfg
,
"empty.tmp"
,
5
));
must_pass
(
git_config_get_int
(
cfg
,
"empty.tmp"
,
&
i
));
must_pass
(
git_config_set_int
32
(
cfg
,
"empty.tmp"
,
5
));
must_pass
(
git_config_get_int
32
(
cfg
,
"empty.tmp"
,
&
i
));
must_be_true
(
i
==
5
);
must_pass
(
git_config_delete
(
cfg
,
"empty.tmp"
));
git_config_free
(
cfg
);
...
...
@@ -307,13 +307,13 @@ END_TEST
BEGIN_TEST
(
config16
,
"add a variable in a new section"
)
git_config
*
cfg
;
int
i
;
int
32_t
i
;
git_filebuf
buf
;
/* By freeing the config, we make sure we flush the values */
must_pass
(
git_config_open_ondisk
(
&
cfg
,
CONFIG_BASE
"/config10"
));
must_pass
(
git_config_set_int
(
cfg
,
"section.tmp"
,
5
));
must_pass
(
git_config_get_int
(
cfg
,
"section.tmp"
,
&
i
));
must_pass
(
git_config_set_int
32
(
cfg
,
"section.tmp"
,
5
));
must_pass
(
git_config_get_int
32
(
cfg
,
"section.tmp"
,
&
i
));
must_be_true
(
i
==
5
);
must_pass
(
git_config_delete
(
cfg
,
"section.tmp"
));
git_config_free
(
cfg
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment