blame: fix alignment with --abbrev=40
[gitweb.git] / patch-ids.c
index 77e46638a460bebb0efb5d95af6eeb210e276903..ce285c2e0c552ecf725c87052846d755507bd9db 100644 (file)
@@ -4,9 +4,18 @@
 #include "sha1-lookup.h"
 #include "patch-ids.h"
 
+static int patch_id_defined(struct commit *commit)
+{
+       /* must be 0 or 1 parents */
+       return !commit->parents || !commit->parents->next;
+}
+
 int commit_patch_id(struct commit *commit, struct diff_options *options,
                    unsigned char *sha1, int diff_header_only)
 {
+       if (!patch_id_defined(commit))
+               return -1;
+
        if (commit->parents)
                diff_tree_sha1(commit->parents->item->object.oid.hash,
                               commit->object.oid.hash, "", options);
@@ -77,6 +86,9 @@ struct patch_id *has_commit_patch_id(struct commit *commit,
 {
        struct patch_id patch;
 
+       if (!patch_id_defined(commit))
+               return NULL;
+
        memset(&patch, 0, sizeof(patch));
        if (init_patch_id_entry(&patch, commit, ids))
                return NULL;
@@ -89,6 +101,9 @@ struct patch_id *add_commit_patch_id(struct commit *commit,
 {
        struct patch_id *key = xcalloc(1, sizeof(*key));
 
+       if (!patch_id_defined(commit))
+               return NULL;
+
        if (init_patch_id_entry(key, commit, ids)) {
                free(key);
                return NULL;