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
a1d35ede
Commit
a1d35ede
authored
Nov 10, 2013
by
Vicent Marti
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
config_file: style
parent
b9cb72c2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
18 deletions
+18
-18
src/config_file.c
+18
-18
No files found.
src/config_file.c
View file @
a1d35ede
...
@@ -1178,20 +1178,22 @@ static int write_section(git_filebuf *file, const char *key)
...
@@ -1178,20 +1178,22 @@ static int write_section(git_filebuf *file, const char *key)
return
result
;
return
result
;
}
}
static
int
value_needs_surrounding_quot
e
(
const
char
*
value
)
static
const
char
*
quotes_for_valu
e
(
const
char
*
value
)
{
{
const
char
*
ptr
=
value
;
const
char
*
ptr
;
if
(
*
value
==
' '
)
return
1
;
if
(
value
[
0
]
==
' '
||
value
[
0
]
==
'\0'
)
while
(
*
ptr
)
{
return
"
\"
"
;
for
(
ptr
=
value
;
*
ptr
;
++
ptr
)
{
if
(
*
ptr
==
';'
||
*
ptr
==
'#'
)
if
(
*
ptr
==
';'
||
*
ptr
==
'#'
)
return
1
;
return
"
\"
"
;
++
ptr
;
}
}
if
(
ptr
!=
value
&&
*
(
--
ptr
)
==
' '
)
return
1
;
return
0
;
if
(
ptr
[
-
1
]
==
' '
)
return
"
\"
"
;
return
""
;
}
}
/*
/*
...
@@ -1318,10 +1320,8 @@ static int config_write(diskfile_backend *cfg, const char *key, const regex_t *p
...
@@ -1318,10 +1320,8 @@ static int config_write(diskfile_backend *cfg, const char *key, const regex_t *p
/* Then replace the variable. If the value is NULL, it
/* Then replace the variable. If the value is NULL, it
* means we want to delete it, so don't write anything. */
* means we want to delete it, so don't write anything. */
if
(
value
!=
NULL
)
{
if
(
value
!=
NULL
)
{
if
(
value_needs_surrounding_quote
(
value
))
const
char
*
q
=
quotes_for_value
(
value
);
git_filebuf_printf
(
&
file
,
"
\t
%s =
\"
%s
\"\n
"
,
name
,
value
);
git_filebuf_printf
(
&
file
,
"
\t
%s = %s%s%s
\n
"
,
name
,
q
,
value
,
q
);
else
git_filebuf_printf
(
&
file
,
"
\t
%s = %s
\n
"
,
name
,
value
);
}
}
/*
/*
...
@@ -1362,6 +1362,8 @@ static int config_write(diskfile_backend *cfg, const char *key, const regex_t *p
...
@@ -1362,6 +1362,8 @@ static int config_write(diskfile_backend *cfg, const char *key, const regex_t *p
if
(
preg_replaced
)
{
if
(
preg_replaced
)
{
git_filebuf_printf
(
&
file
,
"
\n
%s"
,
write_start
);
git_filebuf_printf
(
&
file
,
"
\n
%s"
,
write_start
);
}
else
{
}
else
{
const
char
*
q
;
git_filebuf_write
(
&
file
,
reader
->
buffer
.
ptr
,
reader
->
buffer
.
size
);
git_filebuf_write
(
&
file
,
reader
->
buffer
.
ptr
,
reader
->
buffer
.
size
);
/* And now if we just need to add a variable */
/* And now if we just need to add a variable */
...
@@ -1381,10 +1383,8 @@ static int config_write(diskfile_backend *cfg, const char *key, const regex_t *p
...
@@ -1381,10 +1383,8 @@ static int config_write(diskfile_backend *cfg, const char *key, const regex_t *p
if
(
reader
->
buffer
.
size
>
0
&&
*
(
reader
->
buffer
.
ptr
+
reader
->
buffer
.
size
-
1
)
!=
'\n'
)
if
(
reader
->
buffer
.
size
>
0
&&
*
(
reader
->
buffer
.
ptr
+
reader
->
buffer
.
size
-
1
)
!=
'\n'
)
git_filebuf_write
(
&
file
,
"
\n
"
,
1
);
git_filebuf_write
(
&
file
,
"
\n
"
,
1
);
if
(
value_needs_surrounding_quote
(
value
))
q
=
quotes_for_value
(
value
);
git_filebuf_printf
(
&
file
,
"
\t
%s =
\"
%s
\"\n
"
,
name
,
value
);
git_filebuf_printf
(
&
file
,
"
\t
%s = %s%s%s
\n
"
,
name
,
q
,
value
,
q
);
else
git_filebuf_printf
(
&
file
,
"
\t
%s = %s
\n
"
,
name
,
value
);
}
}
}
}
...
...
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