/* * call-seq: * commit.header_field(field_name) -> str * * Returns +commit+'s header field value. */ static VALUE rb_git_commit_header_field(VALUE self, VALUE rb_field) { git_buf header_field = { 0 }; git_commit *commit = NULL; const char *encoding_name; rb_encoding *encoding = rb_utf8_encoding(); VALUE rb_result; int error; Check_Type(rb_field, T_STRING); Data_Get_Struct(self, git_commit, commit); error = git_commit_header_field(&header_field, commit, StringValueCStr(rb_field)); if (error < 0) { git_buf_free(&header_field); if (error == GIT_ENOTFOUND) return Qnil; rugged_exception_check(error); } encoding_name = git_commit_message_encoding(commit); if (encoding_name != NULL) encoding = rb_enc_find(encoding_name); rb_result = rb_enc_str_new(header_field.ptr, header_field.size, encoding); git_buf_free(&header_field); return rb_result; }
int GitRev::ParserFromCommit(const git_commit* commit) { Clear(); int encode = CP_UTF8; const char* encodingstr = git_commit_message_encoding(commit); if (encodingstr) encode = CUnicodeUtils::GetCPCode(CUnicodeUtils::GetUnicode(encodingstr)); m_CommitHash = git_commit_id(commit)->id; const git_signature* author = git_commit_author(commit); m_AuthorDate = author->when.time; m_AuthorEmail = CUnicodeUtils::GetUnicode(author->email, encode); m_AuthorName = CUnicodeUtils::GetUnicode(author->name, encode); const git_signature* committer = git_commit_committer(commit); m_CommitterDate = committer->when.time; m_CommitterEmail = CUnicodeUtils::GetUnicode(committer->email, encode); m_CommitterName = CUnicodeUtils::GetUnicode(committer->name, encode); const char* msg = git_commit_message_raw(commit); const char* body = strchr(msg, '\n'); if (!body) m_Subject = CUnicodeUtils::GetUnicode(msg, encode); else { m_Subject = CUnicodeUtils::GetUnicode(CStringA(msg, (int)(body - msg)), encode); m_Body = CUnicodeUtils::GetUnicode(body + 1, encode); } return 0; }
void CGitPropertyPage::DisplayCommit(const git_commit* commit, UINT hashLabel, UINT subjectLabel, UINT authorLabel, UINT dateLabel) { if (commit == NULL) { SetDlgItemText(m_hwnd, hashLabel, _T("")); SetDlgItemText(m_hwnd, subjectLabel, _T("")); SetDlgItemText(m_hwnd, authorLabel, _T("")); SetDlgItemText(m_hwnd, dateLabel, _T("")); return; } int encode = CP_UTF8; const char * encodingString = git_commit_message_encoding(commit); if (encodingString != NULL) encode = CUnicodeUtils::GetCPCode(CUnicodeUtils::GetUnicode(encodingString)); const git_signature * author = git_commit_author(commit); CString authorName = CUnicodeUtils::GetUnicode(author->name, encode); CString message = CUnicodeUtils::GetUnicode(git_commit_message(commit), encode); int start = 0; message = message.Tokenize(L"\n", start); SetDlgItemText(m_hwnd, hashLabel, CGitHash((char*)(git_commit_id(commit)->id)).ToString()); SetDlgItemText(m_hwnd, subjectLabel, message); SetDlgItemText(m_hwnd, authorLabel, authorName); CString authorDate; Time64ToTimeString(author->when.time, authorDate.GetBufferSetLength(200), 200); SetDlgItemText(m_hwnd, dateLabel, authorDate); }
void test_rebase_merge__commit(void) { git_rebase *rebase; git_reference *branch_ref, *upstream_ref; git_annotated_commit *branch_head, *upstream_head; git_rebase_operation *rebase_operation; git_oid commit_id, tree_id, parent_id; git_signature *author; git_commit *commit; git_reflog *reflog; const git_reflog_entry *reflog_entry; cl_git_pass(git_reference_lookup(&branch_ref, repo, "refs/heads/beef")); cl_git_pass(git_reference_lookup(&upstream_ref, repo, "refs/heads/master")); cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref)); cl_git_pass(git_annotated_commit_from_ref(&upstream_head, repo, upstream_ref)); cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, NULL)); cl_git_pass(git_rebase_next(&rebase_operation, rebase)); cl_git_pass(git_rebase_commit(&commit_id, rebase, NULL, signature, NULL, NULL)); cl_git_pass(git_commit_lookup(&commit, repo, &commit_id)); git_oid_fromstr(&parent_id, "efad0b11c47cb2f0220cbd6f5b0f93bb99064b00"); cl_assert_equal_i(1, git_commit_parentcount(commit)); cl_assert_equal_oid(&parent_id, git_commit_parent_id(commit, 0)); git_oid_fromstr(&tree_id, "4461379789c777d2a6c1f2ee0e9d6c86731b9992"); cl_assert_equal_oid(&tree_id, git_commit_tree_id(commit)); cl_assert_equal_s(NULL, git_commit_message_encoding(commit)); cl_assert_equal_s("Modification 1 to beef\n", git_commit_message(commit)); cl_git_pass(git_signature_new(&author, "Edward Thomson", "*****@*****.**", 1405621769, 0-(4*60))); cl_assert(git_signature__equal(author, git_commit_author(commit))); cl_assert(git_signature__equal(signature, git_commit_committer(commit))); /* Make sure the reflogs are updated appropriately */ cl_git_pass(git_reflog_read(&reflog, repo, "HEAD")); cl_assert(reflog_entry = git_reflog_entry_byindex(reflog, 0)); cl_assert_equal_oid(&parent_id, git_reflog_entry_id_old(reflog_entry)); cl_assert_equal_oid(&commit_id, git_reflog_entry_id_new(reflog_entry)); cl_assert_equal_s("rebase: Modification 1 to beef", git_reflog_entry_message(reflog_entry)); git_reflog_free(reflog); git_signature_free(author); git_commit_free(commit); git_annotated_commit_free(branch_head); git_annotated_commit_free(upstream_head); git_reference_free(branch_ref); git_reference_free(upstream_ref); git_rebase_free(rebase); }
/* * call-seq: * commit.committer -> signature * * Return the signature for the committer of this +commit+. The signature * is returned as a +Hash+ containing +:name+, +:email+ of the author * and +:time+ of the change. * * The committer of a commit is the person who actually applied the changes * of the commit; in most cases it's the same as the author. * * In Ruby 1.9+, the returned string will be encoded with the encoding * specified in the +Encoding+ header of the commit, if available. * * commit.committer #=> {:email=>"*****@*****.**", :time=>Tue Jan 24 05:42:45 UTC 2012, :name=>"Vicent Mart\303\255"} */ static VALUE rb_git_commit_committer_GET(VALUE self) { git_commit *commit; Data_Get_Struct(self, git_commit, commit); return rugged_signature_new( git_commit_committer(commit), git_commit_message_encoding(commit)); }
PyObject * Commit_message__get__(Commit *commit) { const char *message, *encoding; message = git_commit_message(commit->commit); encoding = git_commit_message_encoding(commit->commit); return to_unicode(message, encoding, "strict"); }
PyObject * Commit_committer__get__(Commit *self) { const git_signature *signature; const char *encoding; signature = git_commit_committer(self->commit); encoding = git_commit_message_encoding(self->commit); return build_signature((Object*)self, signature, encoding); }
PyObject * Commit_message_encoding__get__(Commit *commit) { const char *encoding; encoding = git_commit_message_encoding(commit->commit); if (encoding == NULL) Py_RETURN_NONE; return to_encoding(encoding); }
CString CGitRefCompareList::GetCommitMessage(git_commit *commit) { int encode = CP_UTF8; const char *encodingString = git_commit_message_encoding(commit); if (encodingString != nullptr) encode = CUnicodeUtils::GetCPCode(CUnicodeUtils::GetUnicode(encodingString)); CString message = CUnicodeUtils::GetUnicode(git_commit_message(commit), encode); int start = 0; message = message.Tokenize(_T("\n"), start); return message; }
/* * call-seq: * commit.message -> msg * * Return the message of this commit. This includes the full body of the * message, with the short description, detailed descritpion, and any * optional footers or signatures after it. * * In Ruby 1.9+, the returned string will be encoded with the encoding * specified in the +Encoding+ header of the commit, if available. * * commit.message #=> "add a lot of RDoc docs\n\nthis includes docs for commit and blob" */ static VALUE rb_git_commit_message_GET(VALUE self) { git_commit *commit; rb_encoding *encoding = rb_utf8_encoding(); const char *encoding_name; const char *message; Data_Get_Struct(self, git_commit, commit); message = git_commit_message(commit); encoding_name = git_commit_message_encoding(commit); if (encoding_name != NULL) encoding = rb_enc_find(encoding_name); return rb_enc_str_new(message, strlen(message), encoding); }
int git_commit_amend( git_oid *id, const git_commit *commit_to_amend, const char *update_ref, const git_signature *author, const git_signature *committer, const char *message_encoding, const char *message, const git_tree *tree) { git_repository *repo; git_oid tree_id; git_reference *ref; int error; assert(id && commit_to_amend); repo = git_commit_owner(commit_to_amend); if (!author) author = git_commit_author(commit_to_amend); if (!committer) committer = git_commit_committer(commit_to_amend); if (!message_encoding) message_encoding = git_commit_message_encoding(commit_to_amend); if (!message) message = git_commit_message(commit_to_amend); if (!tree) { git_tree *old_tree; GITERR_CHECK_ERROR( git_commit_tree(&old_tree, commit_to_amend) ); git_oid_cpy(&tree_id, git_tree_id(old_tree)); git_tree_free(old_tree); } else { assert(git_tree_owner(tree) == repo); git_oid_cpy(&tree_id, git_tree_id(tree)); } if (update_ref) { if ((error = git_reference_lookup_resolved(&ref, repo, update_ref, 5)) < 0) return error; if (git_oid_cmp(git_commit_id(commit_to_amend), git_reference_target(ref))) { git_reference_free(ref); giterr_set(GITERR_REFERENCE, "commit to amend is not the tip of the given branch"); return -1; } } error = git_commit__create_internal( id, repo, NULL, author, committer, message_encoding, message, &tree_id, commit_parent_for_amend, (void *)commit_to_amend, false); if (!error && update_ref) { error = git_reference__update_for_commit( repo, ref, NULL, id, "commit"); git_reference_free(ref); } return error; }
static int rebase_commit__create( git_commit **out, git_rebase *rebase, git_index *index, git_commit *parent_commit, const git_signature *author, const git_signature *committer, const char *message_encoding, const char *message) { git_rebase_operation *operation; git_commit *current_commit = NULL, *commit = NULL; git_tree *parent_tree = NULL, *tree = NULL; git_oid tree_id, commit_id; int error; operation = git_array_get(rebase->operations, rebase->current); if (git_index_has_conflicts(index)) { giterr_set(GITERR_REBASE, "conflicts have not been resolved"); error = GIT_EUNMERGED; goto done; } if ((error = git_commit_lookup(¤t_commit, rebase->repo, &operation->id)) < 0 || (error = git_commit_tree(&parent_tree, parent_commit)) < 0 || (error = git_index_write_tree_to(&tree_id, index, rebase->repo)) < 0 || (error = git_tree_lookup(&tree, rebase->repo, &tree_id)) < 0) goto done; if (git_oid_equal(&tree_id, git_tree_id(parent_tree))) { giterr_set(GITERR_REBASE, "this patch has already been applied"); error = GIT_EAPPLIED; goto done; } if (!author) author = git_commit_author(current_commit); if (!message) { message_encoding = git_commit_message_encoding(current_commit); message = git_commit_message(current_commit); } if ((error = git_commit_create(&commit_id, rebase->repo, NULL, author, committer, message_encoding, message, tree, 1, (const git_commit **)&parent_commit)) < 0 || (error = git_commit_lookup(&commit, rebase->repo, &commit_id)) < 0) goto done; *out = commit; done: if (error < 0) git_commit_free(commit); git_commit_free(current_commit); git_tree_free(parent_tree); git_tree_free(tree); return error; }
static int rebase_commit_merge( git_oid *commit_id, git_rebase *rebase, const git_signature *author, const git_signature *committer, const char *message_encoding, const char *message) { git_index *index = NULL; git_reference *head = NULL; git_commit *current_commit = NULL, *head_commit = NULL, *commit = NULL; git_rebase_operation *operation; git_tree *head_tree = NULL, *tree = NULL; git_diff *diff = NULL; git_oid tree_id; git_buf reflog_msg = GIT_BUF_INIT; char old_idstr[GIT_OID_HEXSZ], new_idstr[GIT_OID_HEXSZ]; int error; operation = git_array_get(rebase->operations, rebase->current); assert(operation); if ((error = git_repository_index(&index, rebase->repo)) < 0) goto done; if (git_index_has_conflicts(index)) { giterr_set(GITERR_REBASE, "Conflicts have not been resolved"); error = GIT_EMERGECONFLICT; goto done; } if ((error = git_commit_lookup(¤t_commit, rebase->repo, &operation->id)) < 0 || (error = git_repository_head(&head, rebase->repo)) < 0 || (error = git_reference_peel((git_object **)&head_commit, head, GIT_OBJ_COMMIT)) < 0 || (error = git_commit_tree(&head_tree, head_commit)) < 0 || (error = git_diff_tree_to_index(&diff, rebase->repo, head_tree, index, NULL)) < 0) goto done; if (git_diff_num_deltas(diff) == 0) { giterr_set(GITERR_REBASE, "This patch has already been applied"); error = GIT_EAPPLIED; goto done; } if ((error = git_index_write_tree(&tree_id, index)) < 0 || (error = git_tree_lookup(&tree, rebase->repo, &tree_id)) < 0) goto done; if (!author) author = git_commit_author(current_commit); if (!message) { message_encoding = git_commit_message_encoding(current_commit); message = git_commit_message(current_commit); } if ((error = git_commit_create(commit_id, rebase->repo, NULL, author, committer, message_encoding, message, tree, 1, (const git_commit **)&head_commit)) < 0 || (error = git_commit_lookup(&commit, rebase->repo, commit_id)) < 0 || (error = git_reference__update_for_commit( rebase->repo, NULL, "HEAD", commit_id, "rebase")) < 0) goto done; git_oid_fmt(old_idstr, git_commit_id(current_commit)); git_oid_fmt(new_idstr, commit_id); error = rebase_setupfile(rebase, REWRITTEN_FILE, O_CREAT|O_WRONLY|O_APPEND, "%.*s %.*s\n", GIT_OID_HEXSZ, old_idstr, GIT_OID_HEXSZ, new_idstr); done: git_buf_free(&reflog_msg); git_commit_free(commit); git_diff_free(diff); git_tree_free(tree); git_tree_free(head_tree); git_commit_free(head_commit); git_commit_free(current_commit); git_reference_free(head); git_index_free(index); return error; }
std::string Commit::message_encoding() { return std::string(git_commit_message_encoding(commit.get())); }
int luagi_commit_encoding( lua_State *L ) { git_commit** commit = checkcommit( L ); lua_pushstring( L, git_commit_message_encoding( *commit )); return 1; }