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 | |
Daniel Barkalow | e142a3c | 2008-04-27 13:39:24 -0400 | [diff] [blame] | 27 | /* |
| 28 | * Extra refs will be listed by for_each_ref() before any actual refs |
| 29 | * for the duration of this process or until clear_extra_refs() is |
| 30 | * called. Only extra refs added before for_each_ref() is called will |
| 31 | * be listed on a given call of for_each_ref(). |
| 32 | */ |
| 33 | extern void add_extra_ref(const char *refname, const unsigned char *sha1, int flags); |
| 34 | extern void clear_extra_refs(void); |
| 35 | |
Junio C Hamano | cf0adba | 2006-11-19 13:22:44 -0800 | [diff] [blame] | 36 | extern int peel_ref(const char *, unsigned char *); |
| 37 | |
Shawn Pearce | 4bd18c4 | 2006-05-17 05:55:02 -0400 | [diff] [blame] | 38 | /** 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] | 39 | 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] | 40 | |
Shawn Pearce | 4bd18c4 | 2006-05-17 05:55:02 -0400 | [diff] [blame] | 41 | /** Locks any ref (for 'HEAD' type refs). */ |
Sven Verdoolaege | 68db31c | 2007-05-09 12:33:20 +0200 | [diff] [blame] | 42 | #define REF_NODEREF 0x01 |
| 43 | 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] | 44 | |
Brandon Casey | 435fc85 | 2008-02-22 12:57:30 -0600 | [diff] [blame] | 45 | /** Close the file descriptor owned by a lock and return the status */ |
| 46 | extern int close_ref(struct ref_lock *lock); |
| 47 | |
| 48 | /** Close and commit the ref locked by the lock */ |
| 49 | extern int commit_ref(struct ref_lock *lock); |
| 50 | |
Shawn Pearce | 4bd18c4 | 2006-05-17 05:55:02 -0400 | [diff] [blame] | 51 | /** Release any lock taken but not written. **/ |
Junio C Hamano | e5f38ec | 2006-06-06 14:04:17 -0700 | [diff] [blame] | 52 | extern void unlock_ref(struct ref_lock *lock); |
Shawn Pearce | 4bd18c4 | 2006-05-17 05:55:02 -0400 | [diff] [blame] | 53 | |
| 54 | /** Writes sha1 into the ref specified by the lock. **/ |
| 55 | 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] | 56 | |
Shawn Pearce | d556fae | 2006-05-17 05:56:09 -0400 | [diff] [blame] | 57 | /** Reads log for the value of ref during at_time. **/ |
Junio C Hamano | 16d7cc9 | 2007-01-19 01:19:05 -0800 | [diff] [blame] | 58 | 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] | 59 | |
Junio C Hamano | 2ff8166 | 2006-12-18 01:18:16 -0800 | [diff] [blame] | 60 | /* iterate over reflog entries */ |
Johannes Schindelin | 883d60f | 2007-01-08 01:59:54 +0100 | [diff] [blame] | 61 | typedef int each_reflog_ent_fn(unsigned char *osha1, unsigned char *nsha1, const char *, unsigned long, int, const char *, void *); |
| 62 | 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] | 63 | |
Nicolas Pitre | eb8381c | 2007-02-03 13:25:43 -0500 | [diff] [blame] | 64 | /* |
| 65 | * Calls the specified function for each reflog file until it returns nonzero, |
| 66 | * and returns the value |
| 67 | */ |
| 68 | extern int for_each_reflog(each_ref_fn, void *); |
| 69 | |
Junio C Hamano | 5f7b202 | 2008-01-01 22:33:20 -0800 | [diff] [blame] | 70 | #define CHECK_REF_FORMAT_OK 0 |
| 71 | #define CHECK_REF_FORMAT_ERROR (-1) |
| 72 | #define CHECK_REF_FORMAT_ONELEVEL (-2) |
| 73 | #define CHECK_REF_FORMAT_WILDCARD (-3) |
Daniel Barkalow | 95fc751 | 2005-06-06 16:31:29 -0400 | [diff] [blame] | 74 | extern int check_ref_format(const char *target); |
| 75 | |
Lars Hjemli | c976d41 | 2006-11-28 15:47:40 +0100 | [diff] [blame] | 76 | /** rename ref, return 0 on success **/ |
Lars Hjemli | 678d0f4 | 2006-11-30 03:16:56 +0100 | [diff] [blame] | 77 | 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] | 78 | |
Linus Torvalds | 0ebde32 | 2007-04-09 21:14:26 -0700 | [diff] [blame] | 79 | /** resolve ref in nested "gitlink" repository */ |
| 80 | extern int resolve_gitlink_ref(const char *name, const char *refname, unsigned char *result); |
| 81 | |
Carlos Rica | 3d9f037 | 2007-09-05 03:38:24 +0200 | [diff] [blame] | 82 | /** lock a ref and then write its file */ |
| 83 | enum action_on_err { MSG_ON_ERR, DIE_ON_ERR, QUIET_ON_ERR }; |
| 84 | int update_ref(const char *action, const char *refname, |
| 85 | const unsigned char *sha1, const unsigned char *oldval, |
| 86 | int flags, enum action_on_err onerr); |
| 87 | |
Daniel Barkalow | 95fc751 | 2005-06-06 16:31:29 -0400 | [diff] [blame] | 88 | #endif /* REFS_H */ |