From a785d3f77c9922846f25d09fb04af9a3400ffbd1 Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg Date: Fri, 5 Dec 2014 00:08:14 +0100 Subject: refs.c: make ref_transaction_delete a wrapper for ref_transaction_update Signed-off-by: Ronnie Sahlberg Signed-off-by: Stefan Beller Reviewed-by: Michael Haggerty Reviewed-by: Jonathan Nieder Signed-off-by: Michael Haggerty Signed-off-by: Junio C Hamano --- refs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'refs.h') diff --git a/refs.h b/refs.h index 2bc3556874..7d675b7127 100644 --- a/refs.h +++ b/refs.h @@ -283,7 +283,7 @@ struct ref_transaction *ref_transaction_begin(struct strbuf *err); /* * Add a reference update to transaction. new_sha1 is the value that - * the reference should have after the update, or zeros if it should + * the reference should have after the update, or null_sha1 if it should * be deleted. If have_old is true, then old_sha1 holds the value * that the reference should have had before the update, or zeros if * it must not have existed beforehand. -- cgit v1.2.3 From fa5b1830b0605b39295631f6e167ddb133f2dbde Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Fri, 12 Dec 2014 09:56:59 +0100 Subject: reflog_expire(): new function in the reference API Move expire_reflog() into refs.c and rename it to reflog_expire(). Turn the three policy functions into function pointers that are passed into reflog_expire(). Add function prototypes and documentation to refs.h. [jc: squashed in $gmane/261582, drop "extern" in function definition] Signed-off-by: Michael Haggerty Reviewed-by: Stefan Beller Tweaked-by: Ramsay Jones Signed-off-by: Junio C Hamano --- refs.h | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'refs.h') diff --git a/refs.h b/refs.h index 7d675b7127..99e707b1b6 100644 --- a/refs.h +++ b/refs.h @@ -353,4 +353,50 @@ int update_ref(const char *action, const char *refname, extern int parse_hide_refs_config(const char *var, const char *value, const char *); extern int ref_is_hidden(const char *); +enum expire_reflog_flags { + EXPIRE_REFLOGS_DRY_RUN = 1 << 0, + EXPIRE_REFLOGS_UPDATE_REF = 1 << 1, + EXPIRE_REFLOGS_VERBOSE = 1 << 2, + EXPIRE_REFLOGS_REWRITE = 1 << 3 +}; + +/* + * The following interface is used for reflog expiration. The caller + * calls reflog_expire(), supplying it with three callback functions, + * of the following types. The callback functions define the + * expiration policy that is desired. + * + * reflog_expiry_prepare_fn -- Called once after the reference is + * locked. + * + * reflog_expiry_should_prune_fn -- Called once for each entry in the + * existing reflog. It should return true iff that entry should be + * pruned. + * + * reflog_expiry_cleanup_fn -- Called once before the reference is + * unlocked again. + */ +typedef void reflog_expiry_prepare_fn(const char *refname, + const unsigned char *sha1, + void *cb_data); +typedef int reflog_expiry_should_prune_fn(unsigned char *osha1, + unsigned char *nsha1, + const char *email, + unsigned long timestamp, int tz, + const char *message, void *cb_data); +typedef void reflog_expiry_cleanup_fn(void *cb_data); + +/* + * Expire reflog entries for the specified reference. sha1 is the old + * value of the reference. flags is a combination of the constants in + * enum expire_reflog_flags. The three function pointers are described + * above. On success, return zero. + */ +extern int reflog_expire(const char *refname, const unsigned char *sha1, + unsigned int flags, + reflog_expiry_prepare_fn prepare_fn, + reflog_expiry_should_prune_fn should_prune_fn, + reflog_expiry_cleanup_fn cleanup_fn, + void *policy_cb_data); + #endif /* REFS_H */ -- cgit v1.2.3 From 0b1e654801e52243b63b57e27b50acdfe7c8f853 Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg Date: Fri, 12 Dec 2014 09:57:00 +0100 Subject: refs.c: remove unlock_ref/close_ref/commit_ref from the refs api unlock|close|commit_ref can be made static since there are no more external callers. Signed-off-by: Ronnie Sahlberg Signed-off-by: Stefan Beller Signed-off-by: Michael Haggerty Signed-off-by: Junio C Hamano --- refs.h | 9 --------- 1 file changed, 9 deletions(-) (limited to 'refs.h') diff --git a/refs.h b/refs.h index 99e707b1b6..4bb58b9686 100644 --- a/refs.h +++ b/refs.h @@ -198,15 +198,6 @@ extern struct ref_lock *lock_any_ref_for_update(const char *refname, const unsigned char *old_sha1, int flags, int *type_p); -/** Close the file descriptor owned by a lock and return the status */ -extern int close_ref(struct ref_lock *lock); - -/** Close and commit the ref locked by the lock */ -extern int commit_ref(struct ref_lock *lock); - -/** Release any lock taken but not written. **/ -extern void unlock_ref(struct ref_lock *lock); - /* * Setup reflog before using. Set errno to something meaningful on failure. */ -- cgit v1.2.3 From 31e07f76a946831265e741333a3d9e0646c793ad Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Fri, 12 Dec 2014 09:57:01 +0100 Subject: lock_any_ref_for_update(): inline function Inline the function at its one remaining caller (which is within refs.c) and remove it. Signed-off-by: Michael Haggerty Signed-off-by: Junio C Hamano --- refs.h | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) (limited to 'refs.h') diff --git a/refs.h b/refs.h index 4bb58b9686..28e7834da4 100644 --- a/refs.h +++ b/refs.h @@ -181,8 +181,7 @@ extern int is_branch(const char *refname); extern int peel_ref(const char *refname, unsigned char *sha1); /* - * Flags controlling lock_any_ref_for_update(), ref_transaction_update(), - * ref_transaction_create(), etc. + * Flags controlling ref_transaction_update(), ref_transaction_create(), etc. * REF_NODEREF: act on the ref directly, instead of dereferencing * symbolic references. * REF_DELETING: tolerate broken refs @@ -191,12 +190,6 @@ extern int peel_ref(const char *refname, unsigned char *sha1); */ #define REF_NODEREF 0x01 #define REF_DELETING 0x02 -/* - * This function sets errno to something meaningful on failure. - */ -extern struct ref_lock *lock_any_ref_for_update(const char *refname, - const unsigned char *old_sha1, - int flags, int *type_p); /* * Setup reflog before using. Set errno to something meaningful on failure. -- cgit v1.2.3 From 3581d793351dba4e4a2f779a72f39d6ae84c1c2c Mon Sep 17 00:00:00 2001 From: Stefan Beller Date: Fri, 12 Dec 2014 09:57:02 +0100 Subject: refs.c: don't expose the internal struct ref_lock in the header file Now the struct ref_lock is used completely internally, so let's remove it from the header file. Signed-off-by: Stefan Beller Signed-off-by: Michael Haggerty Signed-off-by: Junio C Hamano --- refs.h | 9 --------- 1 file changed, 9 deletions(-) (limited to 'refs.h') diff --git a/refs.h b/refs.h index 28e7834da4..fc88ba6b30 100644 --- a/refs.h +++ b/refs.h @@ -1,15 +1,6 @@ #ifndef REFS_H #define REFS_H -struct ref_lock { - char *ref_name; - char *orig_ref_name; - struct lock_file *lk; - unsigned char old_sha1[20]; - int lock_fd; - int force_write; -}; - /* * A ref_transaction represents a collection of ref updates * that should succeed or fail together. -- cgit v1.2.3