Merge pull request #2737 from Subsurface-divelog/libgitCleanup

Libgit cleanup
This commit is contained in:
Dirk Hohndel 2020-04-10 17:19:51 -07:00 committed by GitHub
commit 61f9c4114e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 34 additions and 86 deletions

View file

@ -97,7 +97,7 @@ Other third party library dependencies
--------------------------------------
In order for our cloud storage to be fully functional you need
libgit2 0.23 or newer.
libgit2 0.26 or newer.
cmake build system

View file

@ -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

View file

@ -310,12 +310,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);

View file

@ -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];
@ -359,11 +360,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 +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;
@ -454,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);
}

View file

@ -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
}

View file

@ -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

View file

@ -20,12 +20,6 @@
#include <zip.h>
#include <sys/stat.h>
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

View file

@ -1021,25 +1021,18 @@ 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 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);
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)

View file

@ -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");

View file

@ -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)

View file

@ -120,7 +120,6 @@ mkdir -p install-root
-DLIBGIT2_INCLUDE_DIR=$RPM_BUILD_DIR/install-root/include \
-DLIBDIVECOMPUTER_LIBRARIES=$RPM_BUILD_DIR/install-root/lib/libdivecomputer.a \
-DLIBGIT2_LIBRARIES=$RPM_BUILD_DIR/install-root/lib/libgit2.a \
-DUSE_LIBGIT23_API=ON \
-DCMAKE_C_FLAGS:STRING="%optflags" \
-DCMAKE_CXX_FLAGS:STRING="%optflags" \
-DNO_PRINTING=OFF \

View file

@ -64,7 +64,6 @@ override_dh_auto_configure:
-DLIBGIT2_LIBRARIES=$(MY_INSTALL_ROOT)/lib/libgit2.a \
-DLIBDIVECOMPUTER_INCLUDE_DIR=$(MY_INSTALL_ROOT)/include \
-DLIBDIVECOMPUTER_LIBRARIES=$(MY_INSTALL_ROOT)/lib/libdivecomputer.a \
-DUSE_LIBGIT23_API=1 \
-DFORCE_LIBSSH=1 \
-DNO_PRINTING=OFF \
-DMAKE_TESTS=OFF \

View file

@ -245,8 +245,8 @@ fi
if [ "$PLATFORM" = Darwin ] ; then
SH_LIB_EXT=dylib
if [ ! "$BUILD_DEPS" == "1" ] ; then
pkg-config --exists libgit2 && LIBGIT=$(pkg-config --modversion libgit2 | cut -d. -f2)
if [[ "$LIBGIT" -gt "23" ]] ; then
pkg-config --exists libgit2 && LIBGIT=$(pkg-config --modversion libgit2) && LIBGITMAJ=$(echo $LIBGIT | cut -d. -f1) && LIBGIT=$(echo $LIBGIT | cut -d. -f2)
if [[ "$LIBGITMAJ" -gt "0" || "$LIBGIT" -gt "25" ]] ; then
LIBGIT2_FROM_PKGCONFIG="-DLIBGIT2_FROM_PKGCONFIG=ON"
fi
fi
@ -258,12 +258,20 @@ else
# first check pkgconfig (that will capture our own local build if
# this script has been run before)
if pkg-config --exists libgit2 ; then
LIBGIT=$(pkg-config --modversion libgit2 | cut -d. -f2)
LIBGIT2_FROM_PKGCONFIG="-DLIBGIT2_FROM_PKGCONFIG=ON"
LIBGIT=$(pkg-config --modversion libgit2)
LIBGITMAJ=$(echo $LIBGIT | cut -d. -f1)
LIBGIT=$(echo $LIBGIT | cut -d. -f2)
if [[ "$LIBGITMAJ" -gt "0" || "$LIBGIT" -gt "25" ]] ; then
LIBGIT2_FROM_PKGCONFIG="-DLIBGIT2_FROM_PKGCONFIG=ON"
fi
fi
if [[ "$LIBGIT" -lt "26" ]] ; then
if [[ "$LIBGITMAJ" -lt "1" && "$LIBGIT" -lt "26" ]] ; then
# maybe there's a system version that's new enough?
LIBGIT=$(ldconfig -p | grep libgit2\\.so\\. | awk -F. '{ print $NF }')
# Ugh that's uggly - read the ultimate filename, split at the last 'o' which gets us ".0.26.3" or ".1.0.0"
# since that starts with a dot, the field numbers in the cut need to be one higher
LIBGIT=$(realpath $(ldconfig -p | grep libgit2\\.so\\. | cut -d\ -f4) | awk -Fo '{ print $NF }')
LIBGITMAJ=$(echo $LIBGIT | cut -d. -f2)
LIBGIT=$(echo $LIBGIT | cut -d. -f3)
fi
fi
@ -312,7 +320,7 @@ if [[ $PLATFORM = Darwin && "$BUILD_DEPS" == "1" ]] ; then
fi
fi
if [[ "$LIBGIT" -lt "26" ]] ; then
if [[ "$LIBGITMAJ" -lt "1" && "$LIBGIT" -lt "26" ]] ; then
LIBGIT_ARGS=" -DLIBGIT2_INCLUDE_DIR=$INSTALL_ROOT/include -DLIBGIT2_LIBRARIES=$INSTALL_ROOT/lib/libgit2.$SH_LIB_EXT "
cd "$SRC"