Merge branch 'sd/branch-copy'
[gitweb.git] / refs / refs-internal.h
index 3d46131efbcc0a76cc3054a97a669bc5bdd036e7..8821e27ed9c033d36caceefc9cd1242682ae9398 100644 (file)
  */
 #define REF_DELETED_LOOSE 0x200
 
+/*
+ * Return the length of time to retry acquiring a loose reference lock
+ * before giving up, in milliseconds:
+ */
+long get_files_ref_lock_timeout_ms(void);
+
 /*
  * Return true iff refname is minimally safe. "Safe" here means that
  * deleting a loose reference by this name will not do any damage, for
  */
 int refname_is_safe(const char *refname);
 
+/*
+ * Helper function: return true if refname, which has the specified
+ * oid and flags, can be resolved to an object in the database. If the
+ * referred-to object does not exist, emit a warning and return false.
+ */
+int ref_resolves_to_object(const char *refname,
+                          const struct object_id *oid,
+                          unsigned int flags);
+
 enum peel_status {
        /* object was peeled successfully: */
        PEEL_PEELED = 0,
@@ -130,13 +145,13 @@ struct ref_update {
        /*
         * If (flags & REF_HAVE_NEW), set the reference to this value:
         */
-       unsigned char new_sha1[20];
+       struct object_id new_oid;
 
        /*
         * If (flags & REF_HAVE_OLD), check that the reference
         * previously had this value:
         */
-       unsigned char old_sha1[20];
+       struct object_id old_oid;
 
        /*
         * One or more of REF_HAVE_NEW, REF_HAVE_OLD, REF_NODEREF,
@@ -169,6 +184,14 @@ int refs_read_raw_ref(struct ref_store *ref_store,
                      const char *refname, unsigned char *sha1,
                      struct strbuf *referent, unsigned int *type);
 
+/*
+ * Write an error to `err` and return a nonzero value iff the same
+ * refname appears multiple times in `refnames`. `refnames` must be
+ * sorted on entry to this function.
+ */
+int ref_update_reject_duplicates(struct string_list *refnames,
+                                struct strbuf *err);
+
 /*
  * Add a ref_update with the specified properties to transaction, and
  * return a pointer to the new object. This function does not verify
@@ -185,17 +208,27 @@ struct ref_update *ref_transaction_add_update(
 
 /*
  * Transaction states.
- * OPEN:   The transaction is in a valid state and can accept new updates.
- *         An OPEN transaction can be committed.
- * CLOSED: A closed transaction is no longer active and no other operations
- *         than free can be used on it in this state.
- *         A transaction can either become closed by successfully committing
- *         an active transaction or if there is a failure while building
- *         the transaction thus rendering it failed/inactive.
+ *
+ * OPEN:   The transaction is initialized and new updates can still be
+ *         added to it. An OPEN transaction can be prepared,
+ *         committed, freed, or aborted (freeing and aborting an open
+ *         transaction are equivalent).
+ *
+ * PREPARED: ref_transaction_prepare(), which locks all of the
+ *         references involved in the update and checks that the
+ *         update has no errors, has been called successfully for the
+ *         transaction. A PREPARED transaction can be committed or
+ *         aborted.
+ *
+ * CLOSED: The transaction is no longer active. A transaction becomes
+ *         CLOSED if there is a failure while building the transaction
+ *         or if a transaction is committed or aborted. A CLOSED
+ *         transaction can only be freed.
  */
 enum ref_transaction_state {
-       REF_TRANSACTION_OPEN   = 0,
-       REF_TRANSACTION_CLOSED = 1
+       REF_TRANSACTION_OPEN     = 0,
+       REF_TRANSACTION_PREPARED = 1,
+       REF_TRANSACTION_CLOSED   = 2
 };
 
 /*
@@ -209,6 +242,7 @@ struct ref_transaction {
        size_t alloc;
        size_t nr;
        enum ref_transaction_state state;
+       void *backend_data;
 };
 
 /*
@@ -482,6 +516,10 @@ struct ref_store;
 #define REF_STORE_WRITE                (1 << 1) /* can perform update operations */
 #define REF_STORE_ODB          (1 << 2) /* has access to object database */
 #define REF_STORE_MAIN         (1 << 3)
+#define REF_STORE_ALL_CAPS     (REF_STORE_READ | \
+                                REF_STORE_WRITE | \
+                                REF_STORE_ODB | \
+                                REF_STORE_MAIN)
 
 /*
  * Initialize the ref_store for the specified gitdir. These functions
@@ -493,6 +531,18 @@ typedef struct ref_store *ref_store_init_fn(const char *gitdir,
 
 typedef int ref_init_db_fn(struct ref_store *refs, struct strbuf *err);
 
+typedef int ref_transaction_prepare_fn(struct ref_store *refs,
+                                      struct ref_transaction *transaction,
+                                      struct strbuf *err);
+
+typedef int ref_transaction_finish_fn(struct ref_store *refs,
+                                     struct ref_transaction *transaction,
+                                     struct strbuf *err);
+
+typedef int ref_transaction_abort_fn(struct ref_store *refs,
+                                    struct ref_transaction *transaction,
+                                    struct strbuf *err);
+
 typedef int ref_transaction_commit_fn(struct ref_store *refs,
                                      struct ref_transaction *transaction,
                                      struct strbuf *err);
@@ -504,16 +554,20 @@ typedef int create_symref_fn(struct ref_store *ref_store,
                             const char *ref_target,
                             const char *refs_heads_master,
                             const char *logmsg);
-typedef int delete_refs_fn(struct ref_store *ref_store,
+typedef int delete_refs_fn(struct ref_store *ref_store, const char *msg,
                           struct string_list *refnames, unsigned int flags);
 typedef int rename_ref_fn(struct ref_store *ref_store,
                          const char *oldref, const char *newref,
                          const char *logmsg);
+typedef int copy_ref_fn(struct ref_store *ref_store,
+                         const char *oldref, const char *newref,
+                         const char *logmsg);
 
 /*
- * Iterate over the references in the specified ref_store that are
- * within find_containing_dir(prefix). If prefix is NULL or the empty
- * string, iterate over all references in the submodule.
+ * Iterate over the references in `ref_store` whose names start with
+ * `prefix`. `prefix` is matched as a literal string, without regard
+ * for path separators. If prefix is NULL or the empty string, iterate
+ * over all references in `ref_store`.
  */
 typedef struct ref_iterator *ref_iterator_begin_fn(
                struct ref_store *ref_store,
@@ -595,7 +649,10 @@ struct ref_storage_be {
        const char *name;
        ref_store_init_fn *init;
        ref_init_db_fn *init_db;
-       ref_transaction_commit_fn *transaction_commit;
+
+       ref_transaction_prepare_fn *transaction_prepare;
+       ref_transaction_finish_fn *transaction_finish;
+       ref_transaction_abort_fn *transaction_abort;
        ref_transaction_commit_fn *initial_transaction_commit;
 
        pack_refs_fn *pack_refs;
@@ -603,6 +660,7 @@ struct ref_storage_be {
        create_symref_fn *create_symref;
        delete_refs_fn *delete_refs;
        rename_ref_fn *rename_ref;
+       copy_ref_fn *copy_ref;
 
        ref_iterator_begin_fn *iterator_begin;
        read_raw_ref_fn *read_raw_ref;
@@ -617,6 +675,7 @@ struct ref_storage_be {
 };
 
 extern struct ref_storage_be refs_be_files;
+extern struct ref_storage_be refs_be_packed;
 
 /*
  * A representation of the reference store for the main repository or