summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2017-10-07 02:06:43 +0100
committerGitHub <noreply@github.com>2017-10-07 02:06:43 +0100
commit58deac7758296f115bcbc3a7bbcfcae3eda07f0a (patch)
treed748c7923f508df92cc4fbe978ba26412c6c1421
parente523826c4ec2b7e8757f31490ba41005420d1c52 (diff)
parentf4770e47573c2e8dff00e8e7263ef8f30421aaed (diff)
downloadlibgit2-58deac7758296f115bcbc3a7bbcfcae3eda07f0a.tar.gz
Merge pull request #4370 from libgit2/example_general
Fix Issue #4047 Check return codes and free objects
-rw-r--r--examples/general.c31
1 files changed, 28 insertions, 3 deletions
diff --git a/examples/general.c b/examples/general.c
index ff984a36c..0780d3d49 100644
--- a/examples/general.c
+++ b/examples/general.c
@@ -724,6 +724,7 @@ static void config_files(const char *repo_path, git_repository* repo)
int32_t autocorrect;
git_config *cfg;
git_config *snap_cfg;
+ int error_code;
printf("\n*Config Listing*\n");
@@ -740,9 +741,33 @@ static void config_files(const char *repo_path, git_repository* repo)
git_config_get_string(&email, snap_cfg, "user.email");
printf("Email: %s\n", email);
- /**
- * Remember to free the configurations after usage.
- */
+ error_code = git_config_get_int32(&autocorrect, cfg, "help.autocorrect");
+ switch (error_code)
+ {
+ case 0:
+ printf("Autocorrect: %d\n", autocorrect);
+ break;
+ case GIT_ENOTFOUND:
+ printf("Autocorrect: Undefined\n");
+ break;
+ default:
+ check_error(error_code, "get_int32 failed");
+ }
git_config_free(cfg);
+
+ check_error(git_repository_config_snapshot(&snap_cfg, repo), "config snapshot");
+ error_code = git_config_get_string(&email, snap_cfg, "user.email");
+ switch (error_code)
+ {
+ case 0:
+ printf("Email: %s\n", email);
+ break;
+ case GIT_ENOTFOUND:
+ printf("Email: Undefined\n");
+ break;
+ default:
+ check_error(error_code, "get_string failed");
+ }
+
git_config_free(snap_cfg);
}