MCPcopy Index your code
hub / github.com/git/git / notes_merge_commit

Function notes_merge_commit

notes-merge.c:682–752  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

680}
681
682int notes_merge_commit(struct notes_merge_options *o,
683 struct notes_tree *partial_tree,
684 struct commit *partial_commit,
685 struct object_id *result_oid)
686{
687 /*
688 * Iterate through files in .git/NOTES_MERGE_WORKTREE and add all
689 * found notes to 'partial_tree'. Write the updated notes tree to
690 * the DB, and commit the resulting tree object while reusing the
691 * commit message and parents from 'partial_commit'.
692 * Finally store the new commit object OID into 'result_oid'.
693 */
694 DIR *dir;
695 struct dirent *e;
696 struct strbuf path = STRBUF_INIT;
697 const char *buffer = repo_get_commit_buffer(the_repository,
698 partial_commit, NULL);
699 const char *msg = strstr(buffer, "\n\n");
700 int baselen;
701
702 repo_git_path_replace(the_repository, &path, NOTES_MERGE_WORKTREE);
703 if (o->verbosity >= 3)
704 printf("Committing notes in notes merge worktree at %s\n",
705 path.buf);
706
707 if (!msg || msg[2] == '\0')
708 die("partial notes commit has empty message");
709 msg += 2;
710
711 dir = opendir(path.buf);
712 if (!dir)
713 die_errno("could not open %s", path.buf);
714
715 strbuf_addch(&path, '/');
716 baselen = path.len;
717 while ((e = readdir_skip_dot_and_dotdot(dir)) != NULL) {
718 struct stat st;
719 struct object_id obj_oid, blob_oid;
720
721 if (get_oid_hex(e->d_name, &obj_oid)) {
722 if (o->verbosity >= 3)
723 printf("Skipping non-SHA1 entry '%s%s'\n",
724 path.buf, e->d_name);
725 continue;
726 }
727
728 strbuf_addstr(&path, e->d_name);
729 /* write file as blob, and add to partial_tree */
730 if (stat(path.buf, &st))
731 die_errno("Failed to stat '%s'", path.buf);
732 if (index_path(o->repo->index, &blob_oid, path.buf, &st, INDEX_WRITE_OBJECT))
733 die("Failed to write blob object from '%s'", path.buf);
734 if (add_note(partial_tree, &obj_oid, &blob_oid, NULL))
735 die("Failed to add resolved note '%s' to notes tree",
736 path.buf);
737 if (o->verbosity >= 4)
738 printf("Added resolved note for object %s: %s\n",
739 oid_to_hex(&obj_oid), oid_to_hex(&blob_oid));

Callers 1

merge_commitFunction · 0.85

Calls 15

repo_get_commit_bufferFunction · 0.85
repo_git_path_replaceFunction · 0.85
opendirFunction · 0.85
die_errnoFunction · 0.85
strbuf_addchFunction · 0.85
get_oid_hexFunction · 0.85
strbuf_addstrFunction · 0.85
index_pathFunction · 0.85
add_noteFunction · 0.85
oid_to_hexFunction · 0.85
strbuf_setlenFunction · 0.85

Tested by

no test coverage detected