gpg-interface: provide access to the payload
[gitweb.git] / refs.c
diff --git a/refs.c b/refs.c
index 6fe4bfe8d90c2d260a852172448303432885e764..68982637ed89a2d679d5e2a9a86e76e6fb56a7b4 100644 (file)
--- a/refs.c
+++ b/refs.c
@@ -1999,7 +1999,6 @@ int dwim_log(const char *str, int len, unsigned char *sha1, char **log)
 
        *log = NULL;
        for (p = ref_rev_parse_rules; *p; p++) {
-               struct stat st;
                unsigned char hash[20];
                char path[PATH_MAX];
                const char *ref, *it;
@@ -2008,12 +2007,9 @@ int dwim_log(const char *str, int len, unsigned char *sha1, char **log)
                ref = resolve_ref_unsafe(path, hash, 1, NULL);
                if (!ref)
                        continue;
-               if (!stat(git_path("logs/%s", path), &st) &&
-                   S_ISREG(st.st_mode))
+               if (reflog_exists(path))
                        it = path;
-               else if (strcmp(ref, path) &&
-                        !stat(git_path("logs/%s", ref), &st) &&
-                        S_ISREG(st.st_mode))
+               else if (strcmp(ref, path) && reflog_exists(ref))
                        it = ref;
                else
                        continue;
@@ -3046,6 +3042,19 @@ int read_ref_at(const char *refname, unsigned long at_time, int cnt,
        return 1;
 }
 
+int reflog_exists(const char *refname)
+{
+       struct stat st;
+
+       return !lstat(git_path("logs/%s", refname), &st) &&
+               S_ISREG(st.st_mode);
+}
+
+int delete_reflog(const char *refname)
+{
+       return remove_path(git_path("logs/%s", refname));
+}
+
 static int show_one_reflog_ent(struct strbuf *sb, each_reflog_ent_fn fn, void *cb_data)
 {
        unsigned char osha1[20], nsha1[20];
@@ -3279,6 +3288,7 @@ struct ref_update {
        int flags; /* REF_NODEREF? */
        int have_old; /* 1 if old_sha1 is valid, 0 otherwise */
        struct ref_lock *lock;
+       int type;
        const char refname[FLEX_ARRAY];
 };
 
@@ -3412,21 +3422,17 @@ int ref_transaction_commit(struct ref_transaction *transaction,
                           const char *msg, enum action_on_err onerr)
 {
        int ret = 0, delnum = 0, i;
-       struct ref_update **updates;
-       int *types;
        const char **delnames;
        int n = transaction->nr;
+       struct ref_update **updates = transaction->updates;
 
        if (!n)
                return 0;
 
        /* Allocate work space */
-       updates = xmalloc(sizeof(*updates) * n);
-       types = xmalloc(sizeof(*types) * n);
        delnames = xmalloc(sizeof(*delnames) * n);
 
        /* Copy, sort, and reject duplicate refs */
-       memcpy(updates, transaction->updates, sizeof(*updates) * n);
        qsort(updates, n, sizeof(*updates), ref_update_compare);
        ret = ref_update_reject_duplicates(updates, n, onerr);
        if (ret)
@@ -3440,7 +3446,7 @@ int ref_transaction_commit(struct ref_transaction *transaction,
                                               (update->have_old ?
                                                update->old_sha1 : NULL),
                                               update->flags,
-                                              &types[i], onerr);
+                                              &update->type, onerr);
                if (!update->lock) {
                        ret = 1;
                        goto cleanup;
@@ -3468,7 +3474,7 @@ int ref_transaction_commit(struct ref_transaction *transaction,
 
                if (update->lock) {
                        delnames[delnum++] = update->lock->ref_name;
-                       ret |= delete_ref_loose(update->lock, types[i]);
+                       ret |= delete_ref_loose(update->lock, update->type);
                }
        }
 
@@ -3481,8 +3487,6 @@ int ref_transaction_commit(struct ref_transaction *transaction,
        for (i = 0; i < n; i++)
                if (updates[i]->lock)
                        unlock_ref(updates[i]->lock);
-       free(updates);
-       free(types);
        free(delnames);
        ref_transaction_free(transaction);
        return ret;