diff options
Diffstat (limited to 'core/git-access.c')
-rw-r--r-- | core/git-access.c | 43 |
1 files changed, 9 insertions, 34 deletions
diff --git a/core/git-access.c b/core/git-access.c index 3688cb90c..0db4faf8e 100644 --- a/core/git-access.c +++ b/core/git-access.c @@ -286,28 +286,6 @@ int credential_https_cb(git_cred **out, return git_cred_userpass_plaintext_new(out, username, password); } -#define KNOWN_CERT "\xfd\xb8\xf7\x73\x76\xe2\x75\x53\x93\x37\xdc\xfe\x1e\x55\x43\x3d\xf2\x2c\x18\x2c" -int certificate_check_cb(git_cert *cert, int valid, const char *host, void *payload) -{ - UNUSED(payload); - if (same_string(host, "cloud.subsurface-divelog.org") && cert->cert_type == GIT_CERT_X509) { - SHA_CTX ctx; - unsigned char hash[21]; - git_cert_x509 *cert509 = (git_cert_x509 *)cert; - SHA1_Init(&ctx); - SHA1_Update(&ctx, cert509->data, cert509->len); - SHA1_Final(hash, &ctx); - hash[20] = 0; - if (verbose > 1) - if (same_string((char *)hash, KNOWN_CERT)) { - fprintf(stderr, "cloud certificate considered %s, forcing it valid\n", - valid ? "valid" : "not valid"); - return 1; - } - } - return valid; -} - static int update_remote(git_repository *repo, git_remote *origin, git_reference *local, git_reference *remote, enum remote_transport rt) { UNUSED(repo); @@ -329,7 +307,6 @@ static int update_remote(git_repository *repo, git_remote *origin, git_reference opts.callbacks.credentials = credential_ssh_cb; else if (rt == RT_HTTPS) opts.callbacks.credentials = credential_https_cb; - opts.callbacks.certificate_check = certificate_check_cb; if (git_remote_push(origin, &refspec, &opts)) { if (is_subsurface_cloud) @@ -349,6 +326,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]; @@ -359,11 +337,7 @@ static int try_to_git_merge(git_repository *repo, git_reference **local_p, git_r } git_merge_init_options(&merge_options, GIT_MERGE_OPTIONS_VERSION); -#if !LIBGIT2_VER_MAJOR && LIBGIT2_VER_MINOR > 23 merge_options.flags = GIT_MERGE_FIND_RENAMES; -#else - merge_options.tree_flags = GIT_MERGE_TREE_FIND_RENAMES; -#endif merge_options.file_favor = GIT_MERGE_FILE_FAVOR_UNION; merge_options.rename_threshold = 100; if (git_commit_lookup(&local_commit, repo, local_id)) { @@ -434,10 +408,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; @@ -454,12 +430,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); } @@ -584,7 +562,6 @@ static int check_remote_status(git_repository *repo, git_remote *origin, const c opts.callbacks.credentials = credential_ssh_cb; else if (rt == RT_HTTPS) opts.callbacks.credentials = credential_https_cb; - opts.callbacks.certificate_check = certificate_check_cb; git_storage_update_progress(translate("gettextFromC", "Store data into cloud storage")); error = git_remote_push(origin, &refspec, &opts); } else { @@ -648,7 +625,6 @@ int sync_with_remote(git_repository *repo, const char *remote, const char *branc opts.callbacks.credentials = credential_ssh_cb; else if (rt == RT_HTTPS) opts.callbacks.credentials = credential_https_cb; - opts.callbacks.certificate_check = certificate_check_cb; git_storage_update_progress(translate("gettextFromC", "Successful cloud connection, fetch remote")); error = git_remote_fetch(origin, NULL, &opts, NULL); // NOTE! A fetch error is not fatal, we just report it @@ -776,7 +752,6 @@ static git_repository *create_local_repo(const char *localdir, const char *remot else if (rt == RT_HTTPS) opts.fetch_opts.callbacks.credentials = credential_https_cb; opts.repository_cb = repository_create_cb; - opts.fetch_opts.callbacks.certificate_check = certificate_check_cb; opts.checkout_branch = branch; if (is_subsurface_cloud && !canReachCloudServer()) |