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

Function diff_get_patch_id

diff.c:6895–6991  ·  view source on GitHub ↗

returns 0 upon success, and writes result into oid */

Source from the content-addressed store, hash-verified

6893
6894/* returns 0 upon success, and writes result into oid */
6895static int diff_get_patch_id(struct diff_options *options, struct object_id *oid, int diff_header_only)
6896{
6897 struct diff_queue_struct *q = &diff_queued_diff;
6898 int i;
6899 struct git_hash_ctx ctx;
6900 struct patch_id_t data;
6901
6902 the_hash_algo->init_fn(&ctx);
6903 memset(&data, 0, sizeof(struct patch_id_t));
6904 data.ctx = &ctx;
6905 oidclr(oid, the_repository->hash_algo);
6906
6907 for (i = 0; i < q->nr; i++) {
6908 xpparam_t xpp;
6909 xdemitconf_t xecfg;
6910 mmfile_t mf1, mf2;
6911 struct diff_filepair *p = q->queue[i];
6912 int len1, len2;
6913
6914 memset(&xpp, 0, sizeof(xpp));
6915 memset(&xecfg, 0, sizeof(xecfg));
6916 if (p->status == 0)
6917 return error("internal diff status error");
6918 if (p->status == DIFF_STATUS_UNKNOWN)
6919 continue;
6920 if (diff_unmodified_pair(p))
6921 continue;
6922 if ((DIFF_FILE_VALID(p->one) && S_ISDIR(p->one->mode)) ||
6923 (DIFF_FILE_VALID(p->two) && S_ISDIR(p->two->mode)))
6924 continue;
6925 if (DIFF_PAIR_UNMERGED(p))
6926 continue;
6927
6928 diff_fill_oid_info(p->one, options->repo->index);
6929 diff_fill_oid_info(p->two, options->repo->index);
6930
6931 len1 = remove_space(p->one->path, strlen(p->one->path));
6932 len2 = remove_space(p->two->path, strlen(p->two->path));
6933 patch_id_add_string(&ctx, "diff--git");
6934 patch_id_add_string(&ctx, "a/");
6935 git_hash_update(&ctx, p->one->path, len1);
6936 patch_id_add_string(&ctx, "b/");
6937 git_hash_update(&ctx, p->two->path, len2);
6938
6939 if (p->one->mode == 0) {
6940 patch_id_add_string(&ctx, "newfilemode");
6941 patch_id_add_mode(&ctx, p->two->mode);
6942 } else if (p->two->mode == 0) {
6943 patch_id_add_string(&ctx, "deletedfilemode");
6944 patch_id_add_mode(&ctx, p->one->mode);
6945 } else if (p->one->mode != p->two->mode) {
6946 patch_id_add_string(&ctx, "oldmode");
6947 patch_id_add_mode(&ctx, p->one->mode);
6948 patch_id_add_string(&ctx, "newmode");
6949 patch_id_add_mode(&ctx, p->two->mode);
6950 }
6951
6952 if (diff_header_only) {

Callers 1

diff_flush_patch_idFunction · 0.85

Calls 13

oidclrFunction · 0.85
errorFunction · 0.85
diff_unmodified_pairFunction · 0.85
diff_fill_oid_infoFunction · 0.85
patch_id_add_stringFunction · 0.85
git_hash_updateFunction · 0.85
patch_id_add_modeFunction · 0.85
diff_filespec_is_binaryFunction · 0.85
oid_to_hexFunction · 0.85
fill_mmfileFunction · 0.85
xdi_diff_outfFunction · 0.85
flush_one_hunkFunction · 0.85

Tested by

no test coverage detected