Convert update-ref to use ref_lock API.
[git/git.git] / refs.h
CommitLineData
95fc7512
DB
1#ifndef REFS_H
2#define REFS_H
3
4bd18c43
SP
4struct ref_lock {
5 char *ref_file;
6 char *lock_file;
7 unsigned char old_sha1[20];
8 int lock_fd;
9};
10
8a65ff76
LT
11/*
12 * Calls the specified function for each ref file until it returns nonzero,
13 * and returns the value
14 */
723c31fe 15extern int head_ref(int (*fn)(const char *path, const unsigned char *sha1));
944d8589 16extern int for_each_ref(int (*fn)(const char *path, const unsigned char *sha1));
a62be77f
SE
17extern int for_each_tag_ref(int (*fn)(const char *path, const unsigned char *sha1));
18extern int for_each_branch_ref(int (*fn)(const char *path, const unsigned char *sha1));
19extern int for_each_remote_ref(int (*fn)(const char *path, const unsigned char *sha1));
8a65ff76 20
95fc7512
DB
21/** Reads the refs file specified into sha1 **/
22extern int get_ref_sha1(const char *ref, unsigned char *sha1);
23
4bd18c43
SP
24/** Locks a "refs/" ref returning the lock on success and NULL on failure. **/
25extern struct ref_lock* lock_ref_sha1(const char *ref, const unsigned char *old_sha1, int mustexist);
26
27/** Locks any ref (for 'HEAD' type refs). */
28extern struct ref_lock* lock_any_ref_for_update(const char *ref, const unsigned char *old_sha1, int mustexist);
95fc7512 29
4bd18c43
SP
30/** Release any lock taken but not written. **/
31extern void unlock_ref (struct ref_lock *lock);
95fc7512 32
4bd18c43
SP
33/** Writes sha1 into the ref specified by the lock. **/
34extern int write_ref_sha1(struct ref_lock *lock, const unsigned char *sha1, const char *msg);
95fc7512
DB
35
36/** Returns 0 if target has the right format for a ref. **/
37extern int check_ref_format(const char *target);
38
39#endif /* REFS_H */