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 *); |
Christian Couder | 2a8177b | 2009-03-30 05:07:15 +0200 | [diff] [blame] | 23 | extern int for_each_ref_in(const char *, each_ref_fn, void *); |
Junio C Hamano | cb5d709 | 2006-09-20 21:47:42 -0700 | [diff] [blame] | 24 | extern int for_each_tag_ref(each_ref_fn, void *); |
| 25 | extern int for_each_branch_ref(each_ref_fn, void *); |
| 26 | extern int for_each_remote_ref(each_ref_fn, void *); |
Christian Couder | 2926870 | 2009-01-23 10:06:38 +0100 | [diff] [blame] | 27 | extern int for_each_replace_ref(each_ref_fn, void *); |
Ilari Liusvaara | d08bae7 | 2010-01-20 11:48:25 +0200 | [diff] [blame] | 28 | extern int for_each_glob_ref(each_ref_fn, const char *pattern, void *); |
Ilari Liusvaara | b09fe97 | 2010-01-20 11:48:26 +0200 | [diff] [blame] | 29 | extern int for_each_glob_ref_in(each_ref_fn, const char *pattern, const char* prefix, void *); |
Linus Torvalds | 8a65ff7 | 2005-07-02 20:23:36 -0700 | [diff] [blame] | 30 | |
Heiko Voigt | 9ef6aeb | 2010-07-07 15:39:12 +0200 | [diff] [blame] | 31 | extern int head_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data); |
| 32 | extern int for_each_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data); |
| 33 | extern int for_each_ref_in_submodule(const char *submodule, const char *prefix, |
| 34 | each_ref_fn fn, void *cb_data); |
| 35 | extern int for_each_tag_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data); |
| 36 | extern int for_each_branch_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data); |
| 37 | extern int for_each_remote_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data); |
| 38 | |
Thomas Rast | 894a9d3 | 2010-03-12 18:04:26 +0100 | [diff] [blame] | 39 | static inline const char *has_glob_specials(const char *pattern) |
| 40 | { |
| 41 | return strpbrk(pattern, "?*["); |
| 42 | } |
| 43 | |
Junio C Hamano | f8948e2 | 2009-02-08 23:27:10 -0800 | [diff] [blame] | 44 | /* can be used to learn about broken ref and symref */ |
| 45 | extern int for_each_rawref(each_ref_fn, void *); |
| 46 | |
Jay Soffian | 3cf6134 | 2009-11-10 00:03:32 -0500 | [diff] [blame] | 47 | extern void warn_dangling_symref(FILE *fp, const char *msg_fmt, const char *refname); |
Junio C Hamano | f8948e2 | 2009-02-08 23:27:10 -0800 | [diff] [blame] | 48 | |
Daniel Barkalow | e142a3c | 2008-04-27 13:39:24 -0400 | [diff] [blame] | 49 | /* |
| 50 | * Extra refs will be listed by for_each_ref() before any actual refs |
| 51 | * for the duration of this process or until clear_extra_refs() is |
| 52 | * called. Only extra refs added before for_each_ref() is called will |
| 53 | * be listed on a given call of for_each_ref(). |
| 54 | */ |
| 55 | extern void add_extra_ref(const char *refname, const unsigned char *sha1, int flags); |
| 56 | extern void clear_extra_refs(void); |
| 57 | |
Junio C Hamano | cf0adba | 2006-11-19 13:22:44 -0800 | [diff] [blame] | 58 | extern int peel_ref(const char *, unsigned char *); |
| 59 | |
Shawn Pearce | 4bd18c4 | 2006-05-17 05:55:02 -0400 | [diff] [blame] | 60 | /** 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] | 61 | 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] | 62 | |
Shawn Pearce | 4bd18c4 | 2006-05-17 05:55:02 -0400 | [diff] [blame] | 63 | /** Locks any ref (for 'HEAD' type refs). */ |
Sven Verdoolaege | 68db31c | 2007-05-09 12:33:20 +0200 | [diff] [blame] | 64 | #define REF_NODEREF 0x01 |
| 65 | 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] | 66 | |
Brandon Casey | 435fc85 | 2008-02-22 12:57:30 -0600 | [diff] [blame] | 67 | /** Close the file descriptor owned by a lock and return the status */ |
| 68 | extern int close_ref(struct ref_lock *lock); |
| 69 | |
| 70 | /** Close and commit the ref locked by the lock */ |
| 71 | extern int commit_ref(struct ref_lock *lock); |
| 72 | |
Shawn Pearce | 4bd18c4 | 2006-05-17 05:55:02 -0400 | [diff] [blame] | 73 | /** Release any lock taken but not written. **/ |
Junio C Hamano | e5f38ec | 2006-06-06 14:04:17 -0700 | [diff] [blame] | 74 | extern void unlock_ref(struct ref_lock *lock); |
Shawn Pearce | 4bd18c4 | 2006-05-17 05:55:02 -0400 | [diff] [blame] | 75 | |
| 76 | /** Writes sha1 into the ref specified by the lock. **/ |
| 77 | 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] | 78 | |
Erick Mattos | 859c301 | 2010-05-21 21:28:36 -0300 | [diff] [blame] | 79 | /** Setup reflog before using. **/ |
Thomas Rast | 157aaea | 2010-06-10 14:54:03 +0200 | [diff] [blame] | 80 | int log_ref_setup(const char *ref_name, char *logfile, int bufsize); |
Erick Mattos | 859c301 | 2010-05-21 21:28:36 -0300 | [diff] [blame] | 81 | |
Shawn Pearce | d556fae | 2006-05-17 05:56:09 -0400 | [diff] [blame] | 82 | /** Reads log for the value of ref during at_time. **/ |
Junio C Hamano | 16d7cc9 | 2007-01-19 01:19:05 -0800 | [diff] [blame] | 83 | 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] | 84 | |
Junio C Hamano | 2ff8166 | 2006-12-18 01:18:16 -0800 | [diff] [blame] | 85 | /* iterate over reflog entries */ |
Johannes Schindelin | 883d60f | 2007-01-08 01:59:54 +0100 | [diff] [blame] | 86 | typedef int each_reflog_ent_fn(unsigned char *osha1, unsigned char *nsha1, const char *, unsigned long, int, const char *, void *); |
| 87 | int for_each_reflog_ent(const char *ref, each_reflog_ent_fn fn, void *cb_data); |
Junio C Hamano | 101d15e | 2009-01-19 22:18:29 -0800 | [diff] [blame] | 88 | int for_each_recent_reflog_ent(const char *ref, each_reflog_ent_fn fn, long, void *cb_data); |
Junio C Hamano | 2ff8166 | 2006-12-18 01:18:16 -0800 | [diff] [blame] | 89 | |
Nicolas Pitre | eb8381c | 2007-02-03 13:25:43 -0500 | [diff] [blame] | 90 | /* |
| 91 | * Calls the specified function for each reflog file until it returns nonzero, |
| 92 | * and returns the value |
| 93 | */ |
| 94 | extern int for_each_reflog(each_ref_fn, void *); |
| 95 | |
Junio C Hamano | 5f7b202 | 2008-01-01 22:33:20 -0800 | [diff] [blame] | 96 | #define CHECK_REF_FORMAT_OK 0 |
| 97 | #define CHECK_REF_FORMAT_ERROR (-1) |
| 98 | #define CHECK_REF_FORMAT_ONELEVEL (-2) |
| 99 | #define CHECK_REF_FORMAT_WILDCARD (-3) |
Daniel Barkalow | 95fc751 | 2005-06-06 16:31:29 -0400 | [diff] [blame] | 100 | extern int check_ref_format(const char *target); |
| 101 | |
Felipe Contreras | 4577e48 | 2009-05-14 00:22:04 +0300 | [diff] [blame] | 102 | extern const char *prettify_refname(const char *refname); |
Bert Wesarg | 6e7b330 | 2009-04-13 12:25:46 +0200 | [diff] [blame] | 103 | extern char *shorten_unambiguous_ref(const char *ref, int strict); |
Daniel Barkalow | a9c37a7 | 2009-03-08 21:06:05 -0400 | [diff] [blame] | 104 | |
Lars Hjemli | c976d41 | 2006-11-28 15:47:40 +0100 | [diff] [blame] | 105 | /** rename ref, return 0 on success **/ |
Lars Hjemli | 678d0f4 | 2006-11-30 03:16:56 +0100 | [diff] [blame] | 106 | 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] | 107 | |
Linus Torvalds | 0ebde32 | 2007-04-09 21:14:26 -0700 | [diff] [blame] | 108 | /** resolve ref in nested "gitlink" repository */ |
| 109 | extern int resolve_gitlink_ref(const char *name, const char *refname, unsigned char *result); |
| 110 | |
Carlos Rica | 3d9f037 | 2007-09-05 03:38:24 +0200 | [diff] [blame] | 111 | /** lock a ref and then write its file */ |
| 112 | enum action_on_err { MSG_ON_ERR, DIE_ON_ERR, QUIET_ON_ERR }; |
| 113 | int update_ref(const char *action, const char *refname, |
| 114 | const unsigned char *sha1, const unsigned char *oldval, |
| 115 | int flags, enum action_on_err onerr); |
| 116 | |
Daniel Barkalow | 95fc751 | 2005-06-06 16:31:29 -0400 | [diff] [blame] | 117 | #endif /* REFS_H */ |