]> git.ipfire.org Git - thirdparty/git.git/blobdiff - commit.c
shallow: use struct 'shallow_lock' for additional safety
[thirdparty/git.git] / commit.c
index 434ec030d6b2a0074c46c376c6322c92fd5c8a39..aa969b32a32456daf212967175ad63cc28c3b0a4 100644 (file)
--- a/commit.c
+++ b/commit.c
@@ -20,6 +20,7 @@
 #include "refs.h"
 #include "commit-reach.h"
 #include "run-command.h"
+#include "shallow.h"
 
 static struct commit_extra_header *read_commit_extra_header_lines(const char *buf, size_t len, const char **);
 
@@ -110,7 +111,7 @@ static const unsigned char *commit_graft_sha1_access(size_t index, void *table)
        return commit_graft_table[index]->oid.hash;
 }
 
-static int commit_graft_pos(struct repository *r, const unsigned char *sha1)
+int commit_graft_pos(struct repository *r, const unsigned char *sha1)
 {
        return sha1_pos(sha1, r->parsed_objects->grafts,
                        r->parsed_objects->grafts_nr,
@@ -245,19 +246,6 @@ int for_each_commit_graft(each_commit_graft_fn fn, void *cb_data)
        return ret;
 }
 
-int unregister_shallow(const struct object_id *oid)
-{
-       int pos = commit_graft_pos(the_repository, oid->hash);
-       if (pos < 0)
-               return -1;
-       if (pos + 1 < the_repository->parsed_objects->grafts_nr)
-               MOVE_ARRAY(the_repository->parsed_objects->grafts + pos,
-                          the_repository->parsed_objects->grafts + pos + 1,
-                          the_repository->parsed_objects->grafts_nr - pos - 1);
-       the_repository->parsed_objects->grafts_nr--;
-       return 0;
-}
-
 struct commit_buffer {
        void *buffer;
        unsigned long size;
@@ -993,7 +981,7 @@ static int do_sign_commit(struct strbuf *buf, const char *keyid)
                        strbuf_insert(buf, inspos, gpg_sig_header, gpg_sig_header_len);
                        inspos += gpg_sig_header_len;
                }
-               strbuf_insert(buf, inspos++, " ", 1);
+               strbuf_insertstr(buf, inspos++, " ");
                strbuf_insert(buf, inspos, bol, len);
                inspos += len;
                copypos += len;
@@ -1136,21 +1124,23 @@ int check_commit_signature(const struct commit *commit, struct signature_check *
        return ret;
 }
 
-void verify_merge_signature(struct commit *commit, int verbosity)
+void verify_merge_signature(struct commit *commit, int verbosity,
+                           int check_trust)
 {
        char hex[GIT_MAX_HEXSZ + 1];
        struct signature_check signature_check;
+       int ret;
        memset(&signature_check, 0, sizeof(signature_check));
 
-       check_commit_signature(commit, &signature_check);
+       ret = check_commit_signature(commit, &signature_check);
 
        find_unique_abbrev_r(hex, &commit->object.oid, DEFAULT_ABBREV);
        switch (signature_check.result) {
        case 'G':
+               if (ret || (check_trust && signature_check.trust_level < TRUST_MARGINAL))
+                       die(_("Commit %s has an untrusted GPG signature, "
+                             "allegedly by %s."), hex, signature_check.signer);
                break;
-       case 'U':
-               die(_("Commit %s has an untrusted GPG signature, "
-                     "allegedly by %s."), hex, signature_check.signer);
        case 'B':
                die(_("Commit %s has a bad GPG signature "
                      "allegedly by %s."), hex, signature_check.signer);