diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2014-04-14 14:33:46 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2014-04-14 16:07:59 -0700 |
commit | a3aacfc6c2cbeccb81e18d6906fcc47cf01456a0 (patch) | |
tree | e5d5554cfd5883fbcf650e6a1bb041e1c8575ed9 /save-git.c | |
parent | 7e1d8724c5e9800ade5590ff96d8290196755036 (diff) | |
download | subsurface-a3aacfc6c2cbeccb81e18d6906fcc47cf01456a0.tar.gz |
git-save: improve commit authorship data
We used to always just commit as "subsurface@hohndel.org" because
libgit-19 doesn't have the interfaces to do user name lookup. This does
better if you have libgit-20, using "git_signature_default()" to get the
actual user that does the saving.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'save-git.c')
-rw-r--r-- | save-git.c | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/save-git.c b/save-git.c index 2e8b608f8..76175a197 100644 --- a/save-git.c +++ b/save-git.c @@ -815,6 +815,24 @@ static int update_git_checkout(git_repository *repo, git_object *parent, git_tre return git_checkout_tree(repo, (git_object *) tree, &opts); } +static int get_authorship(git_repository *repo, git_signature **authorp) +{ +#if LIBGIT2_VER_MAJOR || LIBGIT2_VER_MINOR >= 20 + return git_signature_default(authorp, repo); +#else + /* Default name information, with potential OS overrides */ + struct user_info user = { + .name = "Subsurface", + .email = "subsurace@hohndel.org" + }; + + subsurface_user_info(&user); + + /* git_signature_default() is too recent */ + return git_signature_now(authorp, user.name, user.email); +#endif +} + static int create_new_commit(git_repository *repo, const char *branch, git_oid *tree_id) { int ret; @@ -853,8 +871,7 @@ static int create_new_commit(git_repository *repo, const char *branch, git_oid * if (git_tree_lookup(&tree, repo, tree_id)) return report_error("Could not look up newly created tree"); - /* git_signature_default() is too recent */ - if (git_signature_now(&author, "Subsurface", "subsurface@hohndel.org")) + if (get_authorship(repo, &author)) return report_error("No user name configuration in git repo"); /* If the parent commit has the same tree ID, do not create a new commit */ @@ -897,6 +914,8 @@ static int create_new_commit(git_repository *repo, const char *branch, git_oid * return report_error("Failed to update branch '%s'", branch); set_git_id(&commit_id); + git_signature_free(author); + return 0; } |