]> git.ipfire.org Git - thirdparty/git.git/blobdiff - refs.h
The seventh batch
[thirdparty/git.git] / refs.h
diff --git a/refs.h b/refs.h
index 298caf6c6184cc3a23acf78d1a0e3dc8c7d8614c..fb419ab2edcf186d5565ed12126f04bf9151b9d4 100644 (file)
--- a/refs.h
+++ b/refs.h
@@ -66,30 +66,20 @@ const char *ref_storage_format_to_name(unsigned int ref_storage_format);
 #define RESOLVE_REF_NO_RECURSE 0x02
 #define RESOLVE_REF_ALLOW_BAD_NAME 0x04
 
-struct pack_refs_opts {
-       unsigned int flags;
-       struct ref_exclusions *exclusions;
-       struct string_list *includes;
-};
-
 const char *refs_resolve_ref_unsafe(struct ref_store *refs,
                                    const char *refname,
                                    int resolve_flags,
                                    struct object_id *oid,
                                    int *flags);
 
-const char *resolve_ref_unsafe(const char *refname, int resolve_flags,
-                              struct object_id *oid, int *flags);
-
 char *refs_resolve_refdup(struct ref_store *refs,
                          const char *refname, int resolve_flags,
                          struct object_id *oid, int *flags);
-char *resolve_refdup(const char *refname, int resolve_flags,
-                    struct object_id *oid, int *flags);
 
-int read_ref_full(const char *refname, int resolve_flags,
-                 struct object_id *oid, int *flags);
-int read_ref(const char *refname, struct object_id *oid);
+int refs_read_ref_full(struct ref_store *refs, const char *refname,
+                      int resolve_flags, struct object_id *oid, int *flags);
+
+int refs_read_ref(struct ref_store *refs, const char *refname, struct object_id *oid);
 
 int refs_read_symbolic_ref(struct ref_store *ref_store, const char *refname,
                           struct strbuf *referent);
@@ -120,8 +110,6 @@ int refs_verify_refname_available(struct ref_store *refs,
 
 int refs_ref_exists(struct ref_store *refs, const char *refname);
 
-int ref_exists(const char *refname);
-
 int should_autocreate_reflog(const char *refname);
 
 int is_branch(const char *refname);
@@ -336,18 +324,6 @@ int refs_for_each_branch_ref(struct ref_store *refs,
 int refs_for_each_remote_ref(struct ref_store *refs,
                             each_ref_fn fn, void *cb_data);
 
-/* just iterates the head ref. */
-int head_ref(each_ref_fn fn, void *cb_data);
-
-/* iterates all refs. */
-int for_each_ref(each_ref_fn fn, void *cb_data);
-
-/**
- * iterates all refs which have a defined prefix and strips that prefix from
- * the passed variable refname.
- */
-int for_each_ref_in(const char *prefix, each_ref_fn fn, void *cb_data);
-
 /*
  * references matching any pattern in "exclude_patterns" are omitted from the
  * result set on a best-effort basis.
@@ -355,7 +331,6 @@ int for_each_ref_in(const char *prefix, each_ref_fn fn, void *cb_data);
 int refs_for_each_fullref_in(struct ref_store *refs, const char *prefix,
                             const char **exclude_patterns,
                             each_ref_fn fn, void *cb_data);
-int for_each_fullref_in(const char *prefix, each_ref_fn fn, void *cb_data);
 
 /**
  * iterate all refs in "patterns" by partitioning patterns into disjoint sets
@@ -375,28 +350,27 @@ int refs_for_each_fullref_in_prefixes(struct ref_store *refs,
 /**
  * iterate refs from the respective area.
  */
-int for_each_tag_ref(each_ref_fn fn, void *cb_data);
-int for_each_branch_ref(each_ref_fn fn, void *cb_data);
-int for_each_remote_ref(each_ref_fn fn, void *cb_data);
 int for_each_replace_ref(struct repository *r, each_repo_ref_fn fn, void *cb_data);
 
 /* iterates all refs that match the specified glob pattern. */
-int for_each_glob_ref(each_ref_fn fn, const char *pattern, void *cb_data);
+int refs_for_each_glob_ref(struct ref_store *refs, each_ref_fn fn,
+                          const char *pattern, void *cb_data);
+
+int refs_for_each_glob_ref_in(struct ref_store *refs, each_ref_fn fn,
+                             const char *pattern, const char *prefix, void *cb_data);
 
-int for_each_glob_ref_in(each_ref_fn fn, const char *pattern,
-                        const char *prefix, void *cb_data);
+int refs_head_ref_namespaced(struct ref_store *refs, each_ref_fn fn, void *cb_data);
 
-int head_ref_namespaced(each_ref_fn fn, void *cb_data);
 /*
  * references matching any pattern in "exclude_patterns" are omitted from the
  * result set on a best-effort basis.
  */
-int for_each_namespaced_ref(const char **exclude_patterns,
-                           each_ref_fn fn, void *cb_data);
+int refs_for_each_namespaced_ref(struct ref_store *refs,
+                                const char **exclude_patterns,
+                                each_ref_fn fn, void *cb_data);
 
 /* can be used to learn about broken ref and symref */
 int refs_for_each_rawref(struct ref_store *refs, each_ref_fn fn, void *cb_data);
-int for_each_rawref(each_ref_fn fn, void *cb_data);
 
 /*
  * Iterates over all refs including root refs, i.e. pseudorefs and HEAD.
@@ -428,10 +402,18 @@ void warn_dangling_symrefs(FILE *fp, const char *msg_fmt,
 /*
  * Flags for controlling behaviour of pack_refs()
  * PACK_REFS_PRUNE: Prune loose refs after packing
- * PACK_REFS_ALL:   Pack _all_ refs, not just tags and already packed refs
+ * PACK_REFS_AUTO: Pack refs on a best effort basis. The heuristics and end
+ *                 result are decided by the ref backend. Backends may ignore
+ *                 this flag and fall back to a normal repack.
  */
-#define PACK_REFS_PRUNE 0x0001
-#define PACK_REFS_ALL   0x0002
+#define PACK_REFS_PRUNE (1 << 0)
+#define PACK_REFS_AUTO  (1 << 1)
+
+struct pack_refs_opts {
+       unsigned int flags;
+       struct ref_exclusions *exclusions;
+       struct string_list *includes;
+};
 
 /*
  * Write a packed-refs file for the current repository.
@@ -444,7 +426,6 @@ int refs_pack_refs(struct ref_store *refs, struct pack_refs_opts *opts);
  */
 int refs_create_reflog(struct ref_store *refs, const char *refname,
                       struct strbuf *err);
-int safe_create_reflog(const char *refname, struct strbuf *err);
 
 /**
  * Reads log for the value of ref during at_time (in which case "cnt" should be
@@ -468,7 +449,6 @@ int read_ref_at(struct ref_store *refs,
 
 /** Check if a particular reflog exists */
 int refs_reflog_exists(struct ref_store *refs, const char *refname);
-int reflog_exists(const char *refname);
 
 /*
  * Delete the specified reference. If old_oid is non-NULL, then
@@ -482,8 +462,6 @@ int refs_delete_ref(struct ref_store *refs, const char *msg,
                    const char *refname,
                    const struct object_id *old_oid,
                    unsigned int flags);
-int delete_ref(const char *msg, const char *refname,
-              const struct object_id *old_oid, unsigned int flags);
 
 /*
  * Delete the specified references. If there are any problems, emit
@@ -493,12 +471,9 @@ int delete_ref(const char *msg, const char *refname,
  */
 int refs_delete_refs(struct ref_store *refs, const char *msg,
                     struct string_list *refnames, unsigned int flags);
-int delete_refs(const char *msg, struct string_list *refnames,
-               unsigned int flags);
 
 /** Delete a reflog */
 int refs_delete_reflog(struct ref_store *refs, const char *refname);
-int delete_reflog(const char *refname);
 
 /*
  * Callback to process a reflog entry found by the iteration functions (see
@@ -544,17 +519,7 @@ int refs_for_each_reflog_ent_reverse(struct ref_store *refs,
                                     void *cb_data);
 
 /*
- * Iterate over reflog entries in the log for `refname` in the main ref store.
- */
-
-/* oldest entry first */
-int for_each_reflog_ent(const char *refname, each_reflog_ent_fn fn, void *cb_data);
-
-/* youngest entry first */
-int for_each_reflog_ent_reverse(const char *refname, each_reflog_ent_fn fn, void *cb_data);
-
-/*
- * The signature for the callback function for the {refs_,}for_each_reflog()
+ * The signature for the callback function for the refs_for_each_reflog()
  * functions below. The memory pointed to by the refname argument is only
  * guaranteed to be valid for the duration of a single callback invocation.
  */
@@ -565,7 +530,6 @@ typedef int each_reflog_fn(const char *refname, void *cb_data);
  * and returns the value. Reflog file order is unspecified.
  */
 int refs_for_each_reflog(struct ref_store *refs, each_reflog_fn fn, void *cb_data);
-int for_each_reflog(each_reflog_fn fn, void *cb_data);
 
 #define REFNAME_ALLOW_ONELEVEL 1
 #define REFNAME_REFSPEC_PATTERN 2
@@ -590,23 +554,17 @@ const char *prettify_refname(const char *refname);
 
 char *refs_shorten_unambiguous_ref(struct ref_store *refs,
                                   const char *refname, int strict);
-char *shorten_unambiguous_ref(const char *refname, int strict);
 
 /** rename ref, return 0 on success **/
 int refs_rename_ref(struct ref_store *refs, const char *oldref,
                    const char *newref, const char *logmsg);
-int rename_ref(const char *oldref, const char *newref,
-                       const char *logmsg);
 
 /** copy ref, return 0 on success **/
 int refs_copy_existing_ref(struct ref_store *refs, const char *oldref,
                    const char *newref, const char *logmsg);
-int copy_existing_ref(const char *oldref, const char *newref,
-                       const char *logmsg);
 
-int refs_create_symref(struct ref_store *refs, const char *refname,
+int refs_update_symref(struct ref_store *refs, const char *refname,
                       const char *target, const char *logmsg);
-int create_symref(const char *refname, const char *target, const char *logmsg);
 
 enum action_on_err {
        UPDATE_REFS_MSG_ON_ERR,
@@ -620,7 +578,6 @@ enum action_on_err {
  */
 struct ref_transaction *ref_store_transaction_begin(struct ref_store *refs,
                                                    struct strbuf *err);
-struct ref_transaction *ref_transaction_begin(struct strbuf *err);
 
 /*
  * Reference transaction updates
@@ -646,6 +603,16 @@ struct ref_transaction *ref_transaction_begin(struct strbuf *err);
  *         before the update. A copy of this value is made in the
  *         transaction.
  *
+ *     new_target -- the target reference that the reference will be
+ *         updated to point to. If the reference is a regular reference,
+ *         it will be converted to a symbolic reference. Cannot be set
+ *         together with `new_oid`. A copy of this value is made in the
+ *         transaction.
+ *
+ *     old_target -- the reference that the reference must be pointing to.
+ *         Canont be set together with `old_oid`. A copy of this value is
+ *         made in the transaction.
+ *
  *     flags -- flags affecting the update, passed to
  *         update_ref_lock(). Possible flags: REF_NO_DEREF,
  *         REF_FORCE_CREATE_REFLOG. See those constants for more
@@ -711,7 +678,11 @@ struct ref_transaction *ref_transaction_begin(struct strbuf *err);
  * beforehand. The old value is checked after the lock is taken to
  * prevent races. If the old value doesn't agree with old_oid, the
  * whole transaction fails. If old_oid is NULL, then the previous
- * value is not checked.
+ * value is not checked. If `old_target` is not NULL, treat the reference
+ * as a symbolic ref and validate that its target before the update is
+ * `old_target`. If the `new_target` is not NULL, then the reference
+ * will be updated to a symbolic ref which targets `new_target`.
+ * Together, these allow us to update between regular refs and symrefs.
  *
  * See the above comment "Reference transaction updates" for more
  * information.
@@ -720,6 +691,8 @@ int ref_transaction_update(struct ref_transaction *transaction,
                           const char *refname,
                           const struct object_id *new_oid,
                           const struct object_id *old_oid,
+                          const char *new_target,
+                          const char *old_target,
                           unsigned int flags, const char *msg,
                           struct strbuf *err);
 
@@ -851,9 +824,6 @@ void ref_transaction_free(struct ref_transaction *transaction);
 int refs_update_ref(struct ref_store *refs, const char *msg, const char *refname,
                    const struct object_id *new_oid, const struct object_id *old_oid,
                    unsigned int flags, enum action_on_err onerr);
-int update_ref(const char *msg, const char *refname,
-              const struct object_id *new_oid, const struct object_id *old_oid,
-              unsigned int flags, enum action_on_err onerr);
 
 int parse_hide_refs_config(const char *var, const char *value, const char *,
                           struct strvec *);
@@ -911,7 +881,7 @@ enum expire_reflog_flags {
 
 /*
  * The following interface is used for reflog expiration. The caller
- * calls reflog_expire(), supplying it with three callback functions,
+ * calls refs_reflog_expire(), supplying it with three callback functions,
  * of the following types. The callback functions define the
  * expiration policy that is desired.
  *
@@ -948,12 +918,6 @@ int refs_reflog_expire(struct ref_store *refs,
                       reflog_expiry_should_prune_fn should_prune_fn,
                       reflog_expiry_cleanup_fn cleanup_fn,
                       void *policy_cb_data);
-int reflog_expire(const char *refname,
-                 unsigned int flags,
-                 reflog_expiry_prepare_fn prepare_fn,
-                 reflog_expiry_should_prune_fn should_prune_fn,
-                 reflog_expiry_cleanup_fn cleanup_fn,
-                 void *policy_cb_data);
 
 struct ref_store *get_main_ref_store(struct repository *r);
 
@@ -1052,4 +1016,211 @@ void update_ref_namespace(enum ref_namespace namespace, char *ref);
 int is_pseudoref(struct ref_store *refs, const char *refname);
 int is_headref(struct ref_store *refs, const char *refname);
 
+/*
+ * The following functions have been removed in Git v2.45 in favor of functions
+ * that receive a `ref_store` as parameter. The intent of this section is
+ * merely to help patch authors of in-flight series to have a reference what
+ * they should be migrating to. The section will be removed in Git v2.46.
+ */
+#if 0
+static char *resolve_refdup(const char *refname, int resolve_flags,
+                           struct object_id *oid, int *flags)
+{
+       return refs_resolve_refdup(get_main_ref_store(the_repository),
+                                  refname, resolve_flags,
+                                  oid, flags);
+}
+
+static int read_ref_full(const char *refname, int resolve_flags,
+                        struct object_id *oid, int *flags)
+{
+       return refs_read_ref_full(get_main_ref_store(the_repository), refname,
+                                 resolve_flags, oid, flags);
+}
+
+static int read_ref(const char *refname, struct object_id *oid)
+{
+       return refs_read_ref(get_main_ref_store(the_repository), refname, oid);
+}
+
+static int ref_exists(const char *refname)
+{
+       return refs_ref_exists(get_main_ref_store(the_repository), refname);
+}
+
+static int for_each_tag_ref(each_ref_fn fn, void *cb_data)
+{
+       return refs_for_each_tag_ref(get_main_ref_store(the_repository), fn, cb_data);
+}
+
+static int for_each_branch_ref(each_ref_fn fn, void *cb_data)
+{
+       return refs_for_each_branch_ref(get_main_ref_store(the_repository), fn, cb_data);
+}
+
+static int for_each_remote_ref(each_ref_fn fn, void *cb_data)
+{
+       return refs_for_each_remote_ref(get_main_ref_store(the_repository), fn, cb_data);
+}
+
+static int head_ref_namespaced(each_ref_fn fn, void *cb_data)
+{
+       return refs_head_ref_namespaced(get_main_ref_store(the_repository),
+                                       fn, cb_data);
+}
+
+static int for_each_glob_ref_in(each_ref_fn fn, const char *pattern,
+                               const char *prefix, void *cb_data)
+{
+       return refs_for_each_glob_ref_in(get_main_ref_store(the_repository),
+                                        fn, pattern, prefix, cb_data);
+}
+
+static int for_each_glob_ref(each_ref_fn fn, const char *pattern, void *cb_data)
+{
+       return refs_for_each_glob_ref(get_main_ref_store(the_repository),
+                                     fn, pattern, cb_data);
+}
+
+static int delete_ref(const char *msg, const char *refname,
+                     const struct object_id *old_oid, unsigned int flags)
+{
+       return refs_delete_ref(get_main_ref_store(the_repository), msg, refname,
+                              old_oid, flags);
+}
+
+static struct ref_transaction *ref_transaction_begin(struct strbuf *err)
+{
+       return ref_store_transaction_begin(get_main_ref_store(the_repository), err);
+}
+
+static int update_ref(const char *msg, const char *refname,
+                     const struct object_id *new_oid,
+                     const struct object_id *old_oid,
+                     unsigned int flags, enum action_on_err onerr)
+{
+       return refs_update_ref(get_main_ref_store(the_repository), msg, refname, new_oid,
+                              old_oid, flags, onerr);
+}
+
+static char *shorten_unambiguous_ref(const char *refname, int strict)
+{
+       return refs_shorten_unambiguous_ref(get_main_ref_store(the_repository),
+                                           refname, strict);
+}
+
+static int head_ref(each_ref_fn fn, void *cb_data)
+{
+       return refs_head_ref(get_main_ref_store(the_repository), fn, cb_data);
+}
+
+static int for_each_ref(each_ref_fn fn, void *cb_data)
+{
+       return refs_for_each_ref(get_main_ref_store(the_repository), fn, cb_data);
+}
+
+static int for_each_ref_in(const char *prefix, each_ref_fn fn, void *cb_data)
+{
+       return refs_for_each_ref_in(get_main_ref_store(the_repository), prefix, fn, cb_data);
+}
+
+static int for_each_fullref_in(const char *prefix,
+                              const char **exclude_patterns,
+                              each_ref_fn fn, void *cb_data)
+{
+       return refs_for_each_fullref_in(get_main_ref_store(the_repository),
+                                       prefix, exclude_patterns, fn, cb_data);
+}
+
+static int for_each_namespaced_ref(const char **exclude_patterns,
+                                  each_ref_fn fn, void *cb_data)
+{
+       return refs_for_each_namespaced_ref(get_main_ref_store(the_repository),
+                                           exclude_patterns, fn, cb_data);
+}
+
+static int for_each_rawref(each_ref_fn fn, void *cb_data)
+{
+       return refs_for_each_rawref(get_main_ref_store(the_repository), fn, cb_data);
+}
+
+static const char *resolve_ref_unsafe(const char *refname, int resolve_flags,
+                                     struct object_id *oid, int *flags)
+{
+       return refs_resolve_ref_unsafe(get_main_ref_store(the_repository), refname,
+                                      resolve_flags, oid, flags);
+}
+
+static int create_symref(const char *ref_target, const char *refs_heads_master,
+                        const char *logmsg)
+{
+       return refs_create_symref(get_main_ref_store(the_repository), ref_target,
+                                 refs_heads_master, logmsg);
+}
+
+static int for_each_reflog(each_reflog_fn fn, void *cb_data)
+{
+       return refs_for_each_reflog(get_main_ref_store(the_repository), fn, cb_data);
+}
+
+static int for_each_reflog_ent_reverse(const char *refname, each_reflog_ent_fn fn,
+                                      void *cb_data)
+{
+       return refs_for_each_reflog_ent_reverse(get_main_ref_store(the_repository),
+                                               refname, fn, cb_data);
+}
+
+static int for_each_reflog_ent(const char *refname, each_reflog_ent_fn fn,
+                              void *cb_data)
+{
+       return refs_for_each_reflog_ent(get_main_ref_store(the_repository), refname,
+                                       fn, cb_data);
+}
+
+static int reflog_exists(const char *refname)
+{
+       return refs_reflog_exists(get_main_ref_store(the_repository), refname);
+}
+
+static int safe_create_reflog(const char *refname, struct strbuf *err)
+{
+       return refs_create_reflog(get_main_ref_store(the_repository), refname,
+                                 err);
+}
+
+static int delete_reflog(const char *refname)
+{
+       return refs_delete_reflog(get_main_ref_store(the_repository), refname);
+}
+
+static int reflog_expire(const char *refname,
+                        unsigned int flags,
+                        reflog_expiry_prepare_fn prepare_fn,
+                        reflog_expiry_should_prune_fn should_prune_fn,
+                        reflog_expiry_cleanup_fn cleanup_fn,
+                        void *policy_cb_data)
+{
+       return refs_reflog_expire(get_main_ref_store(the_repository),
+                                 refname, flags,
+                                 prepare_fn, should_prune_fn,
+                                 cleanup_fn, policy_cb_data);
+}
+
+static int delete_refs(const char *msg, struct string_list *refnames,
+                      unsigned int flags)
+{
+       return refs_delete_refs(get_main_ref_store(the_repository), msg, refnames, flags);
+}
+
+static int rename_ref(const char *oldref, const char *newref, const char *logmsg)
+{
+       return refs_rename_ref(get_main_ref_store(the_repository), oldref, newref, logmsg);
+}
+
+static int copy_existing_ref(const char *oldref, const char *newref, const char *logmsg)
+{
+       return refs_copy_existing_ref(get_main_ref_store(the_repository), oldref, newref, logmsg);
+}
+#endif
+
 #endif /* REFS_H */