gj_commit: Allow the commit time to be specified

For now this has not been hooked up to android or ios.
This commit is contained in:
Vishesh Handa
2019-10-02 16:13:24 +02:00
parent dc746ac7c0
commit 9c1b24c5b4
5 changed files with 21 additions and 11 deletions

View File

@ -115,7 +115,7 @@ Java_io_gitjournal_gitjournal_Git_commit(
const char *author_email = (*env)->GetStringUTFChars(env, jni_author_email, 0);
const char *message = (*env)->GetStringUTFChars(env, jni_message, 0);
int err = gj_git_commit(git_base_path, author_name, author_email, message);
int err = gj_git_commit(git_base_path, author_name, author_email, message, 0, 0);
return handle_error(env, err);
}

View File

@ -161,9 +161,8 @@ cleanup:
return err;
}
// FIXME: Add a datetime str
int gj_git_commit(const char *git_base_path, const char *author_name,
const char *author_email, const char *message)
const char *author_email, const char *message, long long commit_time, int commit_time_offset)
{
int err = 0;
git_signature *sig = NULL;
@ -193,9 +192,18 @@ int gj_git_commit(const char *git_base_path, const char *author_name,
}
*/
err = git_signature_now(&sig, author_name, author_email);
if (err < 0)
goto cleanup;
if (commit_time == 0)
{
err = git_signature_now(&sig, author_name, author_email);
if (err < 0)
goto cleanup;
}
else
{
err = git_signature_new(&sig, author_name, author_email, commit_time, commit_time_offset);
if (err < 0)
goto cleanup;
}
err = git_index_write_tree(&tree_id, index);
if (err < 0)

View File

@ -12,8 +12,9 @@ int gj_git_clone(const char *clone_url, const char *git_base_path);
int gj_git_pull(const char *git_base_path, const char *author_name, const char *author_email);
int gj_git_push(const char *git_base_path);
// commit_time_offset is in minutes
int gj_git_commit(const char *git_base_path, const char *author_name,
const char *author_email, const char *message);
const char *author_email, const char *message, long long commit_time, int commit_time_offset);
int gj_git_reset_hard(const char *git_base_path, const char *ref);
int gj_git_add(const char *git_base_path, const char *pattern);
int gj_git_rm(const char *git_base_path, const char *pattern);

View File

@ -25,8 +25,8 @@ int main(int argc, char *argv[])
{
gj_init();
char *publickey = "/Users/vishesh/.ssh/id_rsa.pub";
char *privatekey = "/Users/vishesh/.ssh/id_rsa";
char *publickey = "./.ssh/id_rsa.pub";
char *privatekey = "./.ssh/id_rsa";
char *passphrase = "";
gj_set_ssh_keys_paths(publickey, privatekey, passphrase);
@ -34,7 +34,8 @@ int main(int argc, char *argv[])
int err;
char *git_base_path = "/tmp/test";
//char *clone_url = "https://github.com/GitJournal/journal_test.git";
char *clone_url = "git@github.com:GitJournal/journal_test.git";
//char *clone_url = "git@github.com:GitJournal/journal_test.git";
char *clone_url = "git@github.com:vhanda/test_gj.git";
//char *clone_url = "root@pi.local:git/test";
char *add_pattern = ".";
char *author_name = "TestMan";

View File

@ -146,7 +146,7 @@ static FlutterMethodChannel* gitChannel = 0;
NSString* dirPath = [NSString pathWithComponents:components];
int err = gj_git_commit([dirPath UTF8String], [authorName UTF8String],
[authorEmail UTF8String], [message UTF8String]);
[authorEmail UTF8String], [message UTF8String], 0, 0);
if (!handleError(result, err)) {
result(@YES);
return;