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
986913f4
Commit
986913f4
authored
Aug 16, 2016
by
Patrick Steinhardt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
examples: general: extract function demonstrating config files
parent
176d58ba
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
14 deletions
+23
-14
examples/general.c
+23
-14
No files found.
examples/general.c
View file @
986913f4
...
...
@@ -42,6 +42,8 @@
#include <git2.h>
#include <stdio.h>
static
void
config_files
(
const
char
*
repo_path
);
// Almost all libgit2 functions return 0 on success or negative on error.
// This is not production quality error checking, but should be sufficient
// as an example.
...
...
@@ -498,22 +500,34 @@ int main (int argc, char** argv)
git_strarray_free
(
&
ref_list
);
// ### Config Files
config_files
(
repo_path
);
// The [config API][config] allows you to list and updatee config values
// in any of the accessible config file locations (system, global, local).
//
// [config]: http://libgit2.github.com/libgit2/#HEAD/group/config
// Finally, when you're done with the repository, you can free it as well.
git_repository_free
(
repo
);
printf
(
"
\n
*Config Listing*
\n
"
);
return
0
;
}
/**
* ### Config Files
*
* The [config API][config] allows you to list and updatee config values
* in any of the accessible config file locations (system, global, local).
*
* [config]: http://libgit2.github.com/libgit2/#HEAD/group/config
*/
static
void
config_files
(
const
char
*
repo_path
)
{
const
char
*
email
;
char
config_path
[
256
];
int32_t
j
;
git_config
*
cfg
;
// Open a config object so we can read global values from it.
char
config_path
[
256
];
printf
(
"
\n
*Config Listing*
\n
"
);
/**
* Open a config object so we can read global values from it.
*/
sprintf
(
config_path
,
"%s/config"
,
repo_path
);
check_error
(
git_config_open_ondisk
(
&
cfg
,
config_path
),
"opening config"
);
...
...
@@ -522,9 +536,4 @@ int main (int argc, char** argv)
git_config_get_string
(
&
email
,
cfg
,
"user.email"
);
printf
(
"Email: %s
\n
"
,
email
);
// Finally, when you're done with the repository, you can free it as well.
git_repository_free
(
repo
);
return
0
;
}
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