Daniel Barkalow | 95fc751 | 2005-06-06 16:31:29 -0400 | [diff] [blame] | 1 | #ifndef REFS_H |
| 2 | #define REFS_H |
| 3 | |
Shawn Pearce | 4bd18c4 | 2006-05-17 05:55:02 -0400 | [diff] [blame] | 4 | struct ref_lock { |
Linus Torvalds | 434cd0c | 2006-09-14 10:14:47 -0700 | [diff] [blame] | 5 | char *ref_name; |
Nicolas Pitre | 1655707 | 2007-01-26 17:26:06 -0500 | [diff] [blame] | 6 | char *orig_ref_name; |
Junio C Hamano | c33d517 | 2006-06-06 13:54:14 -0700 | [diff] [blame] | 7 | struct lock_file *lk; |
Shawn Pearce | 4bd18c4 | 2006-05-17 05:55:02 -0400 | [diff] [blame] | 8 | unsigned char old_sha1[20]; |
| 9 | int lock_fd; |
Shawn Pearce | 732232a | 2006-05-19 03:29:05 -0400 | [diff] [blame] | 10 | int force_write; |
Shawn Pearce | 4bd18c4 | 2006-05-17 05:55:02 -0400 | [diff] [blame] | 11 | }; |
| 12 | |
Junio C Hamano | f4204ab | 2006-11-21 23:36:35 -0800 | [diff] [blame] | 13 | #define REF_ISSYMREF 01 |
| 14 | #define REF_ISPACKED 02 |
| 15 | |
Linus Torvalds | 8a65ff7 | 2005-07-02 20:23:36 -0700 | [diff] [blame] | 16 | /* |
| 17 | * Calls the specified function for each ref file until it returns nonzero, |
| 18 | * and returns the value |
| 19 | */ |
Junio C Hamano | 8da1977 | 2006-09-20 22:02:01 -0700 | [diff] [blame] | 20 | typedef int each_ref_fn(const char *refname, const unsigned char *sha1, int flags, void *cb_data); |
Junio C Hamano | cb5d709 | 2006-09-20 21:47:42 -0700 | [diff] [blame] | 21 | extern int head_ref(each_ref_fn, void *); |
| 22 | extern int for_each_ref(each_ref_fn, void *); |
| 23 | extern int for_each_tag_ref(each_ref_fn, void *); |
| 24 | extern int for_each_branch_ref(each_ref_fn, void *); |
| 25 | extern int for_each_remote_ref(each_ref_fn, void *); |
Linus Torvalds | 8a65ff7 | 2005-07-02 20:23:36 -0700 | [diff] [blame] | 26 | |
Junio C Hamano | cf0adba | 2006-11-19 13:22:44 -0800 | [diff] [blame] | 27 | extern int peel_ref(const char *, unsigned char *); |
| 28 | |
Daniel Barkalow | 95fc751 | 2005-06-06 16:31:29 -0400 | [diff] [blame] | 29 | /** Reads the refs file specified into sha1 **/ |
| 30 | extern int get_ref_sha1(const char *ref, unsigned char *sha1); |
| 31 | |
Shawn Pearce | 4bd18c4 | 2006-05-17 05:55:02 -0400 | [diff] [blame] | 32 | /** Locks a "refs/" ref returning the lock on success and NULL on failure. **/ |
Junio C Hamano | 4431fcc | 2006-09-27 01:09:18 -0700 | [diff] [blame] | 33 | extern struct ref_lock *lock_ref_sha1(const char *ref, const unsigned char *old_sha1); |
Daniel Barkalow | 95fc751 | 2005-06-06 16:31:29 -0400 | [diff] [blame] | 34 | |
Shawn Pearce | 4bd18c4 | 2006-05-17 05:55:02 -0400 | [diff] [blame] | 35 | /** Locks any ref (for 'HEAD' type refs). */ |
Sven Verdoolaege | 68db31c | 2007-05-09 12:33:20 +0200 | [diff] [blame] | 36 | #define REF_NODEREF 0x01 |
| 37 | extern struct ref_lock *lock_any_ref_for_update(const char *ref, const unsigned char *old_sha1, int flags); |
Daniel Barkalow | 95fc751 | 2005-06-06 16:31:29 -0400 | [diff] [blame] | 38 | |
Shawn Pearce | 4bd18c4 | 2006-05-17 05:55:02 -0400 | [diff] [blame] | 39 | /** Release any lock taken but not written. **/ |
Junio C Hamano | e5f38ec | 2006-06-06 14:04:17 -0700 | [diff] [blame] | 40 | extern void unlock_ref(struct ref_lock *lock); |
Shawn Pearce | 4bd18c4 | 2006-05-17 05:55:02 -0400 | [diff] [blame] | 41 | |
| 42 | /** Writes sha1 into the ref specified by the lock. **/ |
| 43 | extern int write_ref_sha1(struct ref_lock *lock, const unsigned char *sha1, const char *msg); |
Daniel Barkalow | 95fc751 | 2005-06-06 16:31:29 -0400 | [diff] [blame] | 44 | |
Shawn Pearce | d556fae | 2006-05-17 05:56:09 -0400 | [diff] [blame] | 45 | /** Reads log for the value of ref during at_time. **/ |
Junio C Hamano | 16d7cc9 | 2007-01-19 01:19:05 -0800 | [diff] [blame] | 46 | extern int read_ref_at(const char *ref, unsigned long at_time, int cnt, unsigned char *sha1, char **msg, unsigned long *cutoff_time, int *cutoff_tz, int *cutoff_cnt); |
Shawn Pearce | d556fae | 2006-05-17 05:56:09 -0400 | [diff] [blame] | 47 | |
Junio C Hamano | 2ff8166 | 2006-12-18 01:18:16 -0800 | [diff] [blame] | 48 | /* iterate over reflog entries */ |
Johannes Schindelin | 883d60f | 2007-01-08 01:59:54 +0100 | [diff] [blame] | 49 | typedef int each_reflog_ent_fn(unsigned char *osha1, unsigned char *nsha1, const char *, unsigned long, int, const char *, void *); |
| 50 | int for_each_reflog_ent(const char *ref, each_reflog_ent_fn fn, void *cb_data); |
Junio C Hamano | 2ff8166 | 2006-12-18 01:18:16 -0800 | [diff] [blame] | 51 | |
Nicolas Pitre | eb8381c | 2007-02-03 13:25:43 -0500 | [diff] [blame] | 52 | /* |
| 53 | * Calls the specified function for each reflog file until it returns nonzero, |
| 54 | * and returns the value |
| 55 | */ |
| 56 | extern int for_each_reflog(each_ref_fn, void *); |
| 57 | |
Daniel Barkalow | 95fc751 | 2005-06-06 16:31:29 -0400 | [diff] [blame] | 58 | /** Returns 0 if target has the right format for a ref. **/ |
| 59 | extern int check_ref_format(const char *target); |
| 60 | |
Lars Hjemli | c976d41 | 2006-11-28 15:47:40 +0100 | [diff] [blame] | 61 | /** rename ref, return 0 on success **/ |
Lars Hjemli | 678d0f4 | 2006-11-30 03:16:56 +0100 | [diff] [blame] | 62 | extern int rename_ref(const char *oldref, const char *newref, const char *logmsg); |
Lars Hjemli | c976d41 | 2006-11-28 15:47:40 +0100 | [diff] [blame] | 63 | |
Linus Torvalds | 0ebde32 | 2007-04-09 21:14:26 -0700 | [diff] [blame] | 64 | /** resolve ref in nested "gitlink" repository */ |
| 65 | extern int resolve_gitlink_ref(const char *name, const char *refname, unsigned char *result); |
| 66 | |
Carlos Rica | 3d9f037 | 2007-09-05 03:38:24 +0200 | [diff] [blame] | 67 | /** lock a ref and then write its file */ |
| 68 | enum action_on_err { MSG_ON_ERR, DIE_ON_ERR, QUIET_ON_ERR }; |
| 69 | int update_ref(const char *action, const char *refname, |
| 70 | const unsigned char *sha1, const unsigned char *oldval, |
| 71 | int flags, enum action_on_err onerr); |
| 72 | |
Daniel Barkalow | 95fc751 | 2005-06-06 16:31:29 -0400 | [diff] [blame] | 73 | #endif /* REFS_H */ |