MCPcopy Create free account
hub / github.com/git/git / combine_notes_concatenate

Function combine_notes_concatenate

notes.c:810–856  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

808}
809
810int combine_notes_concatenate(struct object_id *cur_oid,
811 const struct object_id *new_oid)
812{
813 char *cur_msg = NULL, *new_msg = NULL, *buf;
814 unsigned long buf_len;
815 size_t cur_len, new_len;
816 enum object_type cur_type, new_type;
817 int ret;
818
819 /* read in both note blob objects */
820 if (!is_null_oid(new_oid))
821 new_msg = odb_read_object(the_repository->objects, new_oid,
822 &new_type, &new_len);
823 if (!new_msg || !new_len || new_type != OBJ_BLOB) {
824 free(new_msg);
825 return 0;
826 }
827 if (!is_null_oid(cur_oid))
828 cur_msg = odb_read_object(the_repository->objects, cur_oid,
829 &cur_type, &cur_len);
830 if (!cur_msg || !cur_len || cur_type != OBJ_BLOB) {
831 free(cur_msg);
832 free(new_msg);
833 oidcpy(cur_oid, new_oid);
834 return 0;
835 }
836
837 /* we will separate the notes by two newlines anyway */
838 if (cur_msg[cur_len - 1] == '\n')
839 cur_len--;
840
841 /* concatenate cur_msg and new_msg into buf */
842 buf_len = cur_len + 2 + new_len;
843 buf = (char *) xmalloc(buf_len);
844 memcpy(buf, cur_msg, cur_len);
845 buf[cur_len] = '\n';
846 buf[cur_len + 1] = '\n';
847 memcpy(buf + cur_len + 2, new_msg, new_len);
848 free(cur_msg);
849 free(new_msg);
850
851 /* create a new blob object from buf */
852 ret = odb_write_object(the_repository->objects, buf,
853 buf_len, OBJ_BLOB, cur_oid);
854 free(buf);
855 return ret;
856}
857
858int combine_notes_overwrite(struct object_id *cur_oid,
859 const struct object_id *new_oid)

Callers

nothing calls this directly

Calls 5

is_null_oidFunction · 0.85
odb_read_objectFunction · 0.85
oidcpyFunction · 0.85
odb_write_objectFunction · 0.85
xmallocFunction · 0.70

Tested by

no test coverage detected