From 67a717dc057a5936ae1f5820fc6c470524213b97 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Thu, 9 Apr 2020 16:59:12 -0700 Subject: cleanup: remove support for ancient versions of libgit2 We require a minimum of libgit2 0.26. Signed-off-by: Dirk Hohndel --- core/save-git.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'core/save-git.c') diff --git a/core/save-git.c b/core/save-git.c index a304e0d94..7bf7b2e1d 100644 --- a/core/save-git.c +++ b/core/save-git.c @@ -1022,10 +1022,8 @@ int update_git_checkout(git_repository *repo, git_object *parent, git_tree *tree static int get_authorship(git_repository *repo, git_signature **authorp) { -#if LIBGIT2_VER_MAJOR || LIBGIT2_VER_MINOR >= 20 if (git_signature_default(authorp, repo) == 0) return 0; -#endif /* try to fetch the user info from the OS, otherwise use default values. */ struct user_info user = { .name = NULL, .email = NULL }; subsurface_user_info(&user); -- cgit v1.2.3-70-g09d2 From 7a238b614685ce7d85b1a7564871e72c960bad89 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Thu, 9 Apr 2020 17:03:43 -0700 Subject: cloud-storage: simplify creation of git authorship While having the local user information in the repo on Linux seemed clever when we implemented it, it's inconsistent with all the other platforms. Let's just not do that unless the user has indeed set a global name/email pair for git. Instead indicate if this was Subsurface or Subsurface-mobile. Signed-off-by: Dirk Hohndel --- core/android.cpp | 3 --- core/dive.h | 6 ------ core/ios.cpp | 5 ----- core/macos.c | 6 ------ core/save-git.c | 21 ++++++++------------- core/unix.c | 30 ------------------------------ core/windows.c | 3 --- 7 files changed, 8 insertions(+), 66 deletions(-) (limited to 'core/save-git.c') diff --git a/core/android.cpp b/core/android.cpp index b86f2e557..d1a1570fb 100644 --- a/core/android.cpp +++ b/core/android.cpp @@ -53,9 +53,6 @@ bool subsurface_ignore_font(const char *font) return false; } -void subsurface_user_info(struct user_info *user) -{ /* Encourage use of at least libgit2-0.20 */ } - static const char *system_default_path_append(const char *append) { // Qt appears to find a working path for us - let's just go with that diff --git a/core/dive.h b/core/dive.h index 1e5ca873d..acd0c7e72 100644 --- a/core/dive.h +++ b/core/dive.h @@ -322,12 +322,6 @@ extern int save_dive_sites_logic(const char *filename, const struct dive_site *s struct membuffer; extern void save_one_dive_to_mb(struct membuffer *b, struct dive *dive, bool anonymize); -struct user_info { - char *name; - char *email; -}; - -extern void subsurface_user_info(struct user_info *); extern void subsurface_console_init(void); extern void subsurface_console_exit(void); extern bool subsurface_user_is_root(void); diff --git a/core/ios.cpp b/core/ios.cpp index d54f2b4b8..b8fe7227e 100644 --- a/core/ios.cpp +++ b/core/ios.cpp @@ -37,11 +37,6 @@ bool subsurface_ignore_font(const char*) return false; } -void subsurface_user_info(struct user_info *) -{ - // We use of at least libgit2-0.20 -} - static const char *system_default_path_append(const char *append) { // Qt appears to find a working path for us - let's just go with that diff --git a/core/macos.c b/core/macos.c index dc07dc7b6..0ee7c1952 100644 --- a/core/macos.c +++ b/core/macos.c @@ -20,12 +20,6 @@ #include #include -void subsurface_user_info(struct user_info *info) -{ - UNUSED(info); - /* Nothing, let's use libgit2-20 on MacOS */ -} - /* macos defines CFSTR to create a CFString object from a constant, * but no similar macros if a C string variable is supposed to be * the argument. We add this here (hardcoding the default allocator diff --git a/core/save-git.c b/core/save-git.c index 7bf7b2e1d..e3564eea7 100644 --- a/core/save-git.c +++ b/core/save-git.c @@ -1024,19 +1024,14 @@ static int get_authorship(git_repository *repo, git_signature **authorp) { if (git_signature_default(authorp, repo) == 0) return 0; - /* try to fetch the user info from the OS, otherwise use default values. */ - struct user_info user = { .name = NULL, .email = NULL }; - subsurface_user_info(&user); - if (!user.name || !*user.name) - user.name = strdup("Subsurface"); - if (!user.email) - user.email = strdup("subsurface-app-account@subsurface-divelog.org"); - - /* git_signature_default() is too recent */ - int ret = git_signature_now(authorp, user.name, user.email); - free((void *)user.name); - free((void *)user.email); - return ret; + +#ifdef SUBSURFACE_MOBILE +#define APPNAME "Subsurface-mobile" +#else +#define APPNAME "Subsurface" +#endif + return git_signature_now(authorp, APPNAME, "subsurface-app-account@subsurface-divelog.org"); +#undef APPNAME } static void create_commit_message(struct membuffer *msg, bool create_empty) diff --git a/core/unix.c b/core/unix.c index 5106278a2..bcac33ff3 100644 --- a/core/unix.c +++ b/core/unix.c @@ -34,36 +34,6 @@ bool subsurface_ignore_font(const char *font) return false; } -void subsurface_user_info(struct user_info *user) -{ - struct passwd *pwd = getpwuid(getuid()); - const char *username = getenv("USER"); - - if (pwd) { - if (!empty_string(pwd->pw_gecos)) { - user->name = strdup(pwd->pw_gecos); - // We only want the name, not the office or phone number - char *c = user->name; - while (*c) { - if (*c == ',') { - *c = '\0'; - break; - } - ++c; - } - } - if (!username) - username = pwd->pw_name; - } - if (!empty_string(username)) { - char hostname[64]; - struct membuffer mb = {}; - gethostname(hostname, sizeof(hostname)); - put_format(&mb, "%s@%s", username, hostname); - user->email = detach_cstring(&mb); - } -} - static const char *system_default_path_append(const char *append) { const char *home = getenv("HOME"); diff --git a/core/windows.c b/core/windows.c index 4ca0c621a..37f4d3a63 100644 --- a/core/windows.c +++ b/core/windows.c @@ -23,9 +23,6 @@ const char current_system_divelist_default_font[] = "Segoe UI"; const char *system_divelist_default_font = non_standard_system_divelist_default_font; double system_divelist_default_font_size = -1; -void subsurface_user_info(struct user_info *user) -{ /* Encourage use of at least libgit2-0.20 */ } - extern bool isWin7Or8(); void subsurface_OS_pref_setup(void) -- cgit v1.2.3-70-g09d2 From 53fb533a99eef94d5df1a5258bc23ec123f59d6d Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Thu, 9 Apr 2020 17:05:55 -0700 Subject: cloud-storage: create consistent commit message for merges This never made sense and I think I just forgot to complete this code when I first worked on it. Now we can see which version of Subsurface or Subsurface-mobile created a merge. Signed-off-by: Dirk Hohndel --- core/git-access.c | 13 +++++++++---- core/git-access.h | 1 + core/save-git.c | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) (limited to 'core/save-git.c') diff --git a/core/git-access.c b/core/git-access.c index 982a51cfd..961c9b271 100644 --- a/core/git-access.c +++ b/core/git-access.c @@ -349,6 +349,7 @@ static int try_to_git_merge(git_repository *repo, git_reference **local_p, git_r git_commit *local_commit, *remote_commit, *base_commit; git_index *merged_index; git_merge_options merge_options; + struct membuffer msg = { 0, 0, NULL}; if (verbose) { char outlocal[41], outremote[41]; @@ -430,10 +431,12 @@ static int try_to_git_merge(git_repository *repo, git_reference **local_p, git_r goto write_error; if (git_tree_lookup(&merged_tree, repo, &merge_oid)) goto write_error; - if (git_signature_default(&author, repo) < 0) - if (git_signature_now(&author, "Subsurface", "noemail@given") < 0) - goto write_error; - if (git_commit_create_v(&commit_oid, repo, NULL, author, author, NULL, "automatic merge", merged_tree, 2, local_commit, remote_commit)) + if (get_authorship(repo, &author) < 0) + goto write_error; + const char *user_agent = subsurface_user_agent(); + put_format(&msg, "Automatic merge\n\nCreated by %s\n", user_agent); + free((void *)user_agent); + if (git_commit_create_v(&commit_oid, repo, NULL, author, author, NULL, mb_cstring(&msg), merged_tree, 2, local_commit, remote_commit)) goto write_error; if (git_commit_lookup(&commit, repo, &commit_oid)) goto write_error; @@ -450,12 +453,14 @@ static int try_to_git_merge(git_repository *repo, git_reference **local_p, git_r git_signature_free(author); if (verbose) fprintf(stderr, "Successfully merged repositories"); + free_buffer(&msg); return 0; diverged_error: return report_error(translate("gettextFromC", "Remote storage and local data diverged")); write_error: + free_buffer(&msg); return report_error(translate("gettextFromC", "Remote storage and local data diverged. Error: writing the data failed (%s)"), giterr_last()->message); } diff --git a/core/git-access.h b/core/git-access.h index 19cdde46a..8e20395a4 100644 --- a/core/git-access.h +++ b/core/git-access.h @@ -31,6 +31,7 @@ void set_git_update_cb(int(*)(const char *)); int git_storage_update_progress(const char *text); char *get_local_dir(const char *remote, const char *branch); int git_create_local_repo(const char *filename); +int get_authorship(git_repository *repo, git_signature **authorp); #ifdef __cplusplus } diff --git a/core/save-git.c b/core/save-git.c index e3564eea7..aaf8d5742 100644 --- a/core/save-git.c +++ b/core/save-git.c @@ -1020,7 +1020,7 @@ int update_git_checkout(git_repository *repo, git_object *parent, git_tree *tree return git_checkout_tree(repo, (git_object *) tree, &opts); } -static int get_authorship(git_repository *repo, git_signature **authorp) +int get_authorship(git_repository *repo, git_signature **authorp) { if (git_signature_default(authorp, repo) == 0) return 0; -- cgit v1.2.3-70-g09d2