From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Turner Subject: [PATCH v5 07/27] refs: add methods for reflog Date: Thu, 18 Feb 2016 00:17:30 -0500 Message-ID: <1455772670-21142-8-git-send-email-dturner@twopensource.com> References: <1455772670-21142-1-git-send-email-dturner@twopensource.com> Cc: David Turner , Ronnie Sahlberg To: git@vger.kernel.org, mhagger@alum.mit.edu X-From: git-owner@vger.kernel.org Thu Feb 18 06:20:17 2016 Return-path: Envelope-to: gcvg-git-2@plane.gmane.org Received: from vger.kernel.org ([209.132.180.67]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1aWH0i-0002S2-8g for gcvg-git-2@plane.gmane.org; Thu, 18 Feb 2016 06:20:16 +0100 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1424840AbcBRFUL (ORCPT ); Thu, 18 Feb 2016 00:20:11 -0500 Received: from mail-qg0-f47.google.com ([209.85.192.47]:35098 "EHLO mail-qg0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1424757AbcBRFSf (ORCPT ); Thu, 18 Feb 2016 00:18:35 -0500 Received: by mail-qg0-f47.google.com with SMTP id y89so29369093qge.2 for ; Wed, 17 Feb 2016 21:18:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=twopensource-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=xCMopdDaaVoaMxu9IZMT5+mQTPJjfpUNL1y5SFh899g=; b=n/fURkOFRsR8CYPOBf3awf5ZackJmAZ5wFRTf9HIHHuvvWAWRSkSbWnGKJq/kYFRVz y6p1j1ZYaytf5amowc2uL1b3VJh4BamfC3G15Q1D071Ijkv18vGic65Vd1BpW15QYo5E 2r/kh7kuQPIlLKSx7rOScV9smSUqxfhwnVFKh660cZAUbr1bufKA5B7Mr8XD+PcubZ2n pXOxLQduvTQS4YOFudDQjjrR/7YFzuptpvGCtpxW0q72PSu8uTfcdb3NT9NKzW//Psk0 f9nZOfIJIyjMM9ISa33jp8zfw0xxq+Z9Epa2Vjm/Q4tC4PhRWhpzdF+d8ZGX61tYYCZT RgeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=xCMopdDaaVoaMxu9IZMT5+mQTPJjfpUNL1y5SFh899g=; b=GwHKdWtzShaeA3pw82KGyirvApX3scar9W/mOpemlgyAjaQWXYVFf5aT/zvYRG0e1J u1Kxiz3wExq/9jHs2Y+0s8W40cQSbWCMOVU38mF+cOOXmjHBwY7lr4Qdc8hFifHbXmnF 1Dr4Ku6xagVz17DlqmCYUTEXA3T7Y4FysXhxZ2F3R7VAAsEmLzZqKV8rPNYlEGGwMtuo PdwZtb4ykBp+pKTgCOeXAB/aK5UgCyI1vM97qS1buB5ZFCW4oat6mjxyjPllF07zLSKe AUBIhz7ERK2YT9056gdLXAIeC/ki2BJxfkdfjTz4v+8U00B28Jp119YlhpFyZewYnsbj AoqQ== X-Gm-Message-State: AG10YOTMMQq4KTw7srIGvIqzgZUmzph8qgdTuFyoq49Ug9S0Lro1BNpBfs9VHQXP9R0whg== X-Received: by 10.140.43.37 with SMTP id d34mr6554048qga.51.1455772715201; Wed, 17 Feb 2016 21:18:35 -0800 (PST) Received: from ubuntu.twitter.corp? ([8.25.196.26]) by smtp.gmail.com with ESMTPSA id q22sm1965322qkl.19.2016.02.17.21.18.33 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 17 Feb 2016 21:18:34 -0800 (PST) X-Mailer: git-send-email 2.4.2.767.g62658d5-twtrsrc In-Reply-To: <1455772670-21142-1-git-send-email-dturner@twopensource.com> Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Archived-At: In the file-based backend, the reflog piggybacks on the ref lock. Since other backends won't have the same sort of ref lock, ref backends must also handle reflogs. Signed-off-by: Ronnie Sahlberg Signed-off-by: David Turner --- refs.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ refs/files-backend.c | 36 ++++++++++++++++++++++++------------ refs/refs-internal.h | 27 +++++++++++++++++++++++++++ 3 files changed, 97 insertions(+), 12 deletions(-) diff --git a/refs.c b/refs.c index 253e566..4733935 100644 --- a/refs.c +++ b/refs.c @@ -1241,3 +1241,49 @@ int do_for_each_ref(const char *submodule, const char *base, return the_refs_backend->do_for_each_ref(submodule, base, fn, trim, flags, cb_data); } + +int for_each_reflog_ent_reverse(const char *refname, each_reflog_ent_fn fn, + void *cb_data) +{ + return the_refs_backend->for_each_reflog_ent_reverse(refname, fn, + cb_data); +} + +int for_each_reflog_ent(const char *refname, each_reflog_ent_fn fn, + void *cb_data) +{ + return the_refs_backend->for_each_reflog_ent(refname, fn, cb_data); +} + +int for_each_reflog(each_ref_fn fn, void *cb_data) +{ + return the_refs_backend->for_each_reflog(fn, cb_data); +} + +int reflog_exists(const char *refname) +{ + return the_refs_backend->reflog_exists(refname); +} + +int safe_create_reflog(const char *refname, int force_create, + struct strbuf *err) +{ + return the_refs_backend->create_reflog(refname, force_create, err); +} + +int delete_reflog(const char *refname) +{ + return the_refs_backend->delete_reflog(refname); +} + +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) +{ + return the_refs_backend->reflog_expire(refname, sha1, flags, + prepare_fn, should_prune_fn, + cleanup_fn, policy_cb_data); +} diff --git a/refs/files-backend.c b/refs/files-backend.c index e94960a..149f6a2 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -2589,7 +2589,8 @@ static int log_ref_setup(const char *refname, struct strbuf *logfile, struct str } -int safe_create_reflog(const char *refname, int force_create, struct strbuf *err) +static int files_create_reflog(const char *refname, int force_create, + struct strbuf *err) { int ret; struct strbuf sb = STRBUF_INIT; @@ -2845,7 +2846,7 @@ static int files_create_symref(const char *refname, return ret; } -int reflog_exists(const char *refname) +static int files_reflog_exists(const char *refname) { struct stat st; @@ -2853,7 +2854,7 @@ int reflog_exists(const char *refname) S_ISREG(st.st_mode); } -int delete_reflog(const char *refname) +static int files_delete_reflog(const char *refname) { return remove_path(git_path("logs/%s", refname)); } @@ -2897,7 +2898,9 @@ static char *find_beginning_of_line(char *bob, char *scan) return scan; } -int for_each_reflog_ent_reverse(const char *refname, each_reflog_ent_fn fn, void *cb_data) +static int files_for_each_reflog_ent_reverse(const char *refname, + each_reflog_ent_fn fn, + void *cb_data) { struct strbuf sb = STRBUF_INIT; FILE *logfp; @@ -2999,7 +3002,8 @@ int for_each_reflog_ent_reverse(const char *refname, each_reflog_ent_fn fn, void return ret; } -int for_each_reflog_ent(const char *refname, each_reflog_ent_fn fn, void *cb_data) +static int files_for_each_reflog_ent(const char *refname, + each_reflog_ent_fn fn, void *cb_data) { FILE *logfp; struct strbuf sb = STRBUF_INIT; @@ -3061,7 +3065,7 @@ static int do_for_each_reflog(struct strbuf *name, each_ref_fn fn, void *cb_data return retval; } -int for_each_reflog(each_ref_fn fn, void *cb_data) +static int files_for_each_reflog(each_ref_fn fn, void *cb_data) { int retval; struct strbuf name; @@ -3371,12 +3375,12 @@ static int expire_reflog_ent(unsigned char *osha1, unsigned char *nsha1, return 0; } -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) +static int files_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) { static struct lock_file reflog_lock; struct expire_reflog_cb cb; @@ -3481,6 +3485,14 @@ struct ref_storage_be refs_be_files = { "files", files_transaction_commit, + files_for_each_reflog_ent, + files_for_each_reflog_ent_reverse, + files_for_each_reflog, + files_reflog_exists, + files_create_reflog, + files_delete_reflog, + files_reflog_expire, + files_pack_refs, files_peel_ref, files_create_symref, diff --git a/refs/refs-internal.h b/refs/refs-internal.h index 87b9d80..8b5bbdf 100644 --- a/refs/refs-internal.h +++ b/refs/refs-internal.h @@ -217,6 +217,25 @@ int do_for_each_ref(const char *submodule, const char *base, typedef int ref_transaction_commit_fn(struct ref_transaction *transaction, struct strbuf *err); +/* reflog functions */ +typedef int for_each_reflog_ent_fn(const char *refname, + each_reflog_ent_fn fn, + void *cb_data); +typedef int for_each_reflog_ent_reverse_fn(const char *refname, + each_reflog_ent_fn fn, + void *cb_data); +typedef int for_each_reflog_fn(each_ref_fn fn, void *cb_data); +typedef int reflog_exists_fn(const char *refname); +typedef int create_reflog_fn(const char *refname, int force_create, + struct strbuf *err); +typedef int delete_reflog_fn(const char *refname); +typedef int reflog_expire_fn(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); + /* misc methods */ typedef int pack_refs_fn(unsigned int flags); typedef int peel_ref_fn(const char *refname, unsigned char *sha1); @@ -240,6 +259,14 @@ struct ref_storage_be { const char *name; ref_transaction_commit_fn *transaction_commit; + for_each_reflog_ent_fn *for_each_reflog_ent; + for_each_reflog_ent_reverse_fn *for_each_reflog_ent_reverse; + for_each_reflog_fn *for_each_reflog; + reflog_exists_fn *reflog_exists; + create_reflog_fn *create_reflog; + delete_reflog_fn *delete_reflog; + reflog_expire_fn *reflog_expire; + pack_refs_fn *pack_refs; peel_ref_fn *peel_ref; create_symref_fn *create_symref; -- 2.4.2.767.g62658d5-twtrsrc