mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-29 10:17:16 +08:00
Android JNI GitAdd: Use the c-lib's gitAdd instead
It finally works!
This commit is contained in:
@ -1,7 +1,10 @@
|
|||||||
cmake_minimum_required(VERSION 3.4.1)
|
cmake_minimum_required(VERSION 3.4.1)
|
||||||
|
|
||||||
set(lib_src_DIR ${CMAKE_SOURCE_DIR}/../../../libs/${ANDROID_ABI})
|
set(lib_src_DIR ${CMAKE_SOURCE_DIR}/../../../libs/${ANDROID_ABI})
|
||||||
include_directories(${lib_src_DIR}/include)
|
include_directories(
|
||||||
|
${lib_src_DIR}/include
|
||||||
|
${CMAKE_SOURCE_DIR}/../../../../../gj_common/
|
||||||
|
)
|
||||||
|
|
||||||
add_library(openssl-lib
|
add_library(openssl-lib
|
||||||
STATIC
|
STATIC
|
||||||
@ -45,9 +48,10 @@ set_target_properties(git2-lib
|
|||||||
|
|
||||||
add_library(native-lib
|
add_library(native-lib
|
||||||
SHARED
|
SHARED
|
||||||
|
${CMAKE_SOURCE_DIR}/../../../../../gj_common/gitjournal.c
|
||||||
keygen.c
|
keygen.c
|
||||||
git.c
|
git.c
|
||||||
)
|
)
|
||||||
|
|
||||||
# The order of these libraries is super dooper important
|
# The order of these libraries is super dooper important
|
||||||
# Otherwise you'll get linker errors
|
# Otherwise you'll get linker errors
|
||||||
|
@ -6,68 +6,39 @@
|
|||||||
#include <android/log.h>
|
#include <android/log.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
#include <git2.h>
|
#include "gitjournal.h"
|
||||||
|
|
||||||
int match_cb(const char *path, const char *spec, void *payload)
|
void gj_log(const char *message) {
|
||||||
{
|
__android_log_print(ANDROID_LOG_ERROR, "GitJournalLib", "%s", message);
|
||||||
__android_log_print(ANDROID_LOG_ERROR, "GitAdd", "Match: %s\n", path);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int handle_error(int err) {
|
||||||
|
if (err != 0) {
|
||||||
|
const gj_error *e = gj_error_info(err);
|
||||||
|
if (e) {
|
||||||
|
__android_log_print("Error %d/%d: %s\n", err, e->code, e->message);
|
||||||
|
gj_error_free(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
JNIEXPORT jstring JNICALL
|
JNIEXPORT jstring JNICALL
|
||||||
Java_io_gitjournal_gitjournal_Git_add(
|
Java_io_gitjournal_gitjournal_Git_add(
|
||||||
JNIEnv *env,
|
JNIEnv *env,
|
||||||
jobject this_obj,
|
jobject this_obj,
|
||||||
jstring jni_git_base_path,
|
jstring jni_git_base_path,
|
||||||
jstring jni_add_pattern)
|
jstring jni_add_pattern) {
|
||||||
{
|
|
||||||
const char *git_base_path = (*env)->GetStringUTFChars(env, jni_git_base_path, 0);
|
const char *git_base_path = (*env)->GetStringUTFChars(env, jni_git_base_path, 0);
|
||||||
const char *add_pattern = (*env)->GetStringUTFChars(env, jni_add_pattern, 0);
|
const char *add_pattern = (*env)->GetStringUTFChars(env, jni_add_pattern, 0);
|
||||||
|
|
||||||
int error;
|
// FIXME: This should be done somewhere else!
|
||||||
|
gj_init();
|
||||||
|
|
||||||
// FIXME: Do this somewhere else
|
int err = gj_git_add(git_base_path, add_pattern);
|
||||||
git_libgit2_init();
|
if (err < 0) {
|
||||||
|
handle_error(err);
|
||||||
git_repository *repo = NULL;
|
|
||||||
error = git_repository_open(&repo, git_base_path);
|
|
||||||
if (error < 0) {
|
|
||||||
const git_error *e = giterr_last();
|
|
||||||
__android_log_print(ANDROID_LOG_ERROR, "GitAdd", "Error %d/%d: %s\n", error, e->klass, e->message);
|
|
||||||
return (*env)->NewStringUTF(env, "Error");
|
|
||||||
}
|
|
||||||
|
|
||||||
git_index *idx = NULL;
|
|
||||||
error = git_repository_index(&idx, repo);
|
|
||||||
if (error < 0) {
|
|
||||||
const git_error *e = giterr_last();
|
|
||||||
__android_log_print(ANDROID_LOG_ERROR, "GitAdd", "Error %d/%d: %s\n", error, e->klass, e->message);
|
|
||||||
return (*env)->NewStringUTF(env, "Error");
|
|
||||||
}
|
|
||||||
|
|
||||||
const char *paths[] = {add_pattern};
|
|
||||||
git_strarray pathspec = {paths, 1};
|
|
||||||
|
|
||||||
__android_log_print(ANDROID_LOG_ERROR, "GitAdd", "Add Pattern: %s", add_pattern);
|
|
||||||
|
|
||||||
error = git_index_add_all(idx, &pathspec, GIT_INDEX_ADD_DEFAULT, match_cb, NULL);
|
|
||||||
if (error < 0) {
|
|
||||||
const git_error *e = giterr_last();
|
|
||||||
__android_log_print(ANDROID_LOG_ERROR, "GitAdd", "Error %d/%d: %s\n", error, e->klass, e->message);
|
|
||||||
return (*env)->NewStringUTF(env, "Error");
|
|
||||||
}
|
|
||||||
|
|
||||||
error = git_index_write(idx);
|
|
||||||
if (error < 0) {
|
|
||||||
const git_error *e = giterr_last();
|
|
||||||
__android_log_print(ANDROID_LOG_ERROR, "GitAdd", "Error %d/%d: %s\n", error, e->klass, e->message);
|
|
||||||
return (*env)->NewStringUTF(env, "Error");
|
|
||||||
}
|
|
||||||
|
|
||||||
git_index_free(idx);
|
|
||||||
if (error < 0) {
|
|
||||||
const git_error *e = giterr_last();
|
|
||||||
__android_log_print(ANDROID_LOG_ERROR, "GitAdd", "Error %d/%d: %s\n", error, e->klass, e->message);
|
|
||||||
return (*env)->NewStringUTF(env, "Error");
|
return (*env)->NewStringUTF(env, "Error");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user