4 #include "sha1-lookup.h"
7 int commit_patch_id(struct commit
*commit
, struct diff_options
*options
,
11 diff_tree_sha1(commit
->parents
->item
->object
.oid
.hash
,
12 commit
->object
.oid
.hash
, "", options
);
14 diff_root_tree_sha1(commit
->object
.oid
.hash
, "", options
);
15 diffcore_std(options
);
16 return diff_flush_patch_id(options
, sha1
);
19 static int patch_id_cmp(struct patch_id
*a
,
23 return hashcmp(a
->patch_id
, b
->patch_id
);
26 int init_patch_ids(struct patch_ids
*ids
)
28 memset(ids
, 0, sizeof(*ids
));
29 diff_setup(&ids
->diffopts
);
30 DIFF_OPT_SET(&ids
->diffopts
, RECURSIVE
);
31 diff_setup_done(&ids
->diffopts
);
32 hashmap_init(&ids
->patches
, (hashmap_cmp_fn
)patch_id_cmp
, 256);
36 int free_patch_ids(struct patch_ids
*ids
)
38 hashmap_free(&ids
->patches
, 1);
42 static int init_patch_id_entry(struct patch_id
*patch
,
43 struct commit
*commit
,
44 struct patch_ids
*ids
)
46 patch
->commit
= commit
;
47 if (commit_patch_id(commit
, &ids
->diffopts
, patch
->patch_id
))
50 hashmap_entry_init(patch
, sha1hash(patch
->patch_id
));
54 struct patch_id
*has_commit_patch_id(struct commit
*commit
,
55 struct patch_ids
*ids
)
57 struct patch_id patch
;
59 memset(&patch
, 0, sizeof(patch
));
60 if (init_patch_id_entry(&patch
, commit
, ids
))
63 return hashmap_get(&ids
->patches
, &patch
, NULL
);
66 struct patch_id
*add_commit_patch_id(struct commit
*commit
,
67 struct patch_ids
*ids
)
69 struct patch_id
*key
= xcalloc(1, sizeof(*key
));
71 if (init_patch_id_entry(key
, commit
, ids
)) {
76 hashmap_add(&ids
->patches
, key
);