diff options
Diffstat (limited to 'refs.h')
-rw-r--r-- | refs.h | 83 |
1 files changed, 75 insertions, 8 deletions
@@ -10,18 +10,41 @@ struct ref_lock { int force_write; }; +/* + * Bit values set in the flags argument passed to each_ref_fn(): + */ + +/* Reference is a symbolic reference. */ #define REF_ISSYMREF 0x01 + +/* Reference is a packed reference. */ #define REF_ISPACKED 0x02 + +/* + * Reference cannot be resolved to an object name: dangling symbolic + * reference (directly or indirectly), corrupt reference file, or + * symbolic reference refers to ill-formatted reference name. + */ #define REF_ISBROKEN 0x04 /* - * Calls the specified function for each ref file until it returns - * nonzero, and returns the value. Please note that it is not safe to - * modify references while an iteration is in progress, unless the - * same callback function invocation that modifies the reference also - * returns a nonzero value to immediately stop the iteration. + * The signature for the callback function for the for_each_*() + * functions below. The memory pointed to by the refname and sha1 + * arguments is only guaranteed to be valid for the duration of a + * single callback invocation. + */ +typedef int each_ref_fn(const char *refname, + const unsigned char *sha1, int flags, void *cb_data); + +/* + * The following functions invoke the specified callback function for + * each reference indicated. If the function ever returns a nonzero + * value, stop the iteration and return that value. Please note that + * it is not safe to modify references while an iteration is in + * progress, unless the same callback function invocation that + * modifies the reference also returns a nonzero value to immediately + * stop the iteration. */ -typedef int each_ref_fn(const char *refname, const unsigned char *sha1, int flags, void *cb_data); extern int head_ref(each_ref_fn, void *); extern int for_each_ref(each_ref_fn, void *); extern int for_each_ref_in(const char *, each_ref_fn, void *); @@ -54,13 +77,57 @@ extern int for_each_rawref(each_ref_fn, void *); extern void warn_dangling_symref(FILE *fp, const char *msg_fmt, const char *refname); /* - * Add a reference to the in-memory packed reference cache. To actually - * write the reference to the packed-refs file, call pack_refs(). + * Lock the packed-refs file for writing. Flags is passed to + * hold_lock_file_for_update(). Return 0 on success. + */ +extern int lock_packed_refs(int flags); + +/* + * Add a reference to the in-memory packed reference cache. This may + * only be called while the packed-refs file is locked (see + * lock_packed_refs()). To actually write the packed-refs file, call + * commit_packed_refs(). */ extern void add_packed_ref(const char *refname, const unsigned char *sha1); +/* + * Write the current version of the packed refs cache from memory to + * disk. The packed-refs file must already be locked for writing (see + * lock_packed_refs()). Return zero on success. + */ +extern int commit_packed_refs(void); + +/* + * Rollback the lockfile for the packed-refs file, and discard the + * in-memory packed reference cache. (The packed-refs file will be + * read anew if it is needed again after this function is called.) + */ +extern void rollback_packed_refs(void); + +/* + * 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 + */ +#define PACK_REFS_PRUNE 0x0001 +#define PACK_REFS_ALL 0x0002 + +/* + * Write a packed-refs file for the current repository. + * flags: Combination of the above PACK_REFS_* flags. + */ +int pack_refs(unsigned int flags); + extern int ref_exists(const char *); +/* + * If refname is a non-symbolic reference that refers to a tag object, + * and the tag can be (recursively) dereferenced to a non-tag object, + * store the SHA1 of the referred-to object to sha1 and return 0. If + * any of these conditions are not met, return a non-zero value. + * Symbolic references are considered unpeelable, even if they + * ultimately resolve to a peelable tag. + */ extern int peel_ref(const char *refname, unsigned char *sha1); /** Locks a "refs/" ref returning the lock on success and NULL on failure. **/ |