From: David Turner <dturner@twopensource.com>
To: git@vger.kernel.org, mhagger@alum.mit.edu
Cc: Ronnie Sahlberg <sahlberg@google.com>,
David Turner <dturner@twopensource.com>
Subject: [PATCH v3 07/44] refs.c: move read_ref_at to the common refs file
Date: Mon, 12 Oct 2015 17:51:27 -0400 [thread overview]
Message-ID: <1444686725-27660-8-git-send-email-dturner@twopensource.com> (raw)
In-Reply-To: <1444686725-27660-1-git-send-email-dturner@twopensource.com>
From: Ronnie Sahlberg <sahlberg@google.com>
Move read_ref_at() to the refs.c file since this function does not
contain any backend specific code.
Signed-off-by: Ronnie Sahlberg <sahlberg@google.com>
Signed-off-by: David Turner <dturner@twopensource.com>
---
refs-be-files.c | 118 --------------------------------------------------------
refs.c | 118 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 118 insertions(+), 118 deletions(-)
diff --git a/refs-be-files.c b/refs-be-files.c
index 099df75..4e7e05e 100644
--- a/refs-be-files.c
+++ b/refs-be-files.c
@@ -3424,124 +3424,6 @@ int create_symref(const char *ref_target, const char *refs_heads_master,
return 0;
}
-struct read_ref_at_cb {
- const char *refname;
- unsigned long at_time;
- int cnt;
- int reccnt;
- unsigned char *sha1;
- int found_it;
-
- unsigned char osha1[20];
- unsigned char nsha1[20];
- int tz;
- unsigned long date;
- char **msg;
- unsigned long *cutoff_time;
- int *cutoff_tz;
- int *cutoff_cnt;
-};
-
-static int read_ref_at_ent(unsigned char *osha1, unsigned char *nsha1,
- const char *email, unsigned long timestamp, int tz,
- const char *message, void *cb_data)
-{
- struct read_ref_at_cb *cb = cb_data;
-
- cb->reccnt++;
- cb->tz = tz;
- cb->date = timestamp;
-
- if (timestamp <= cb->at_time || cb->cnt == 0) {
- if (cb->msg)
- *cb->msg = xstrdup(message);
- if (cb->cutoff_time)
- *cb->cutoff_time = timestamp;
- if (cb->cutoff_tz)
- *cb->cutoff_tz = tz;
- if (cb->cutoff_cnt)
- *cb->cutoff_cnt = cb->reccnt - 1;
- /*
- * we have not yet updated cb->[n|o]sha1 so they still
- * hold the values for the previous record.
- */
- if (!is_null_sha1(cb->osha1)) {
- hashcpy(cb->sha1, nsha1);
- if (hashcmp(cb->osha1, nsha1))
- warning("Log for ref %s has gap after %s.",
- cb->refname, show_date(cb->date, cb->tz, DATE_MODE(RFC2822)));
- }
- else if (cb->date == cb->at_time)
- hashcpy(cb->sha1, nsha1);
- else if (hashcmp(nsha1, cb->sha1))
- warning("Log for ref %s unexpectedly ended on %s.",
- cb->refname, show_date(cb->date, cb->tz,
- DATE_MODE(RFC2822)));
- hashcpy(cb->osha1, osha1);
- hashcpy(cb->nsha1, nsha1);
- cb->found_it = 1;
- return 1;
- }
- hashcpy(cb->osha1, osha1);
- hashcpy(cb->nsha1, nsha1);
- if (cb->cnt > 0)
- cb->cnt--;
- return 0;
-}
-
-static int read_ref_at_ent_oldest(unsigned char *osha1, unsigned char *nsha1,
- const char *email, unsigned long timestamp,
- int tz, const char *message, void *cb_data)
-{
- struct read_ref_at_cb *cb = cb_data;
-
- if (cb->msg)
- *cb->msg = xstrdup(message);
- if (cb->cutoff_time)
- *cb->cutoff_time = timestamp;
- if (cb->cutoff_tz)
- *cb->cutoff_tz = tz;
- if (cb->cutoff_cnt)
- *cb->cutoff_cnt = cb->reccnt;
- hashcpy(cb->sha1, osha1);
- if (is_null_sha1(cb->sha1))
- hashcpy(cb->sha1, nsha1);
- /* We just want the first entry */
- return 1;
-}
-
-int read_ref_at(const char *refname, unsigned int flags, unsigned long at_time, int cnt,
- unsigned char *sha1, char **msg,
- unsigned long *cutoff_time, int *cutoff_tz, int *cutoff_cnt)
-{
- struct read_ref_at_cb cb;
-
- memset(&cb, 0, sizeof(cb));
- cb.refname = refname;
- cb.at_time = at_time;
- cb.cnt = cnt;
- cb.msg = msg;
- cb.cutoff_time = cutoff_time;
- cb.cutoff_tz = cutoff_tz;
- cb.cutoff_cnt = cutoff_cnt;
- cb.sha1 = sha1;
-
- for_each_reflog_ent_reverse(refname, read_ref_at_ent, &cb);
-
- if (!cb.reccnt) {
- if (flags & GET_SHA1_QUIETLY)
- exit(128);
- else
- die("Log for %s is empty.", refname);
- }
- if (cb.found_it)
- return 0;
-
- for_each_reflog_ent(refname, read_ref_at_ent_oldest, &cb);
-
- return 1;
-}
-
int reflog_exists(const char *refname)
{
struct stat st;
diff --git a/refs.c b/refs.c
index 205a899..5a8ef0c 100644
--- a/refs.c
+++ b/refs.c
@@ -210,3 +210,121 @@ out:
strbuf_release(&err);
return result;
}
+
+struct read_ref_at_cb {
+ const char *refname;
+ unsigned long at_time;
+ int cnt;
+ int reccnt;
+ unsigned char *sha1;
+ int found_it;
+
+ unsigned char osha1[20];
+ unsigned char nsha1[20];
+ int tz;
+ unsigned long date;
+ char **msg;
+ unsigned long *cutoff_time;
+ int *cutoff_tz;
+ int *cutoff_cnt;
+};
+
+static int read_ref_at_ent(unsigned char *osha1, unsigned char *nsha1,
+ const char *email, unsigned long timestamp, int tz,
+ const char *message, void *cb_data)
+{
+ struct read_ref_at_cb *cb = cb_data;
+
+ cb->reccnt++;
+ cb->tz = tz;
+ cb->date = timestamp;
+
+ if (timestamp <= cb->at_time || cb->cnt == 0) {
+ if (cb->msg)
+ *cb->msg = xstrdup(message);
+ if (cb->cutoff_time)
+ *cb->cutoff_time = timestamp;
+ if (cb->cutoff_tz)
+ *cb->cutoff_tz = tz;
+ if (cb->cutoff_cnt)
+ *cb->cutoff_cnt = cb->reccnt - 1;
+ /*
+ * we have not yet updated cb->[n|o]sha1 so they still
+ * hold the values for the previous record.
+ */
+ if (!is_null_sha1(cb->osha1)) {
+ hashcpy(cb->sha1, nsha1);
+ if (hashcmp(cb->osha1, nsha1))
+ warning("Log for ref %s has gap after %s.",
+ cb->refname, show_date(cb->date, cb->tz, DATE_MODE(RFC2822)));
+ }
+ else if (cb->date == cb->at_time)
+ hashcpy(cb->sha1, nsha1);
+ else if (hashcmp(nsha1, cb->sha1))
+ warning("Log for ref %s unexpectedly ended on %s.",
+ cb->refname, show_date(cb->date, cb->tz,
+ DATE_MODE(RFC2822)));
+ hashcpy(cb->osha1, osha1);
+ hashcpy(cb->nsha1, nsha1);
+ cb->found_it = 1;
+ return 1;
+ }
+ hashcpy(cb->osha1, osha1);
+ hashcpy(cb->nsha1, nsha1);
+ if (cb->cnt > 0)
+ cb->cnt--;
+ return 0;
+}
+
+static int read_ref_at_ent_oldest(unsigned char *osha1, unsigned char *nsha1,
+ const char *email, unsigned long timestamp,
+ int tz, const char *message, void *cb_data)
+{
+ struct read_ref_at_cb *cb = cb_data;
+
+ if (cb->msg)
+ *cb->msg = xstrdup(message);
+ if (cb->cutoff_time)
+ *cb->cutoff_time = timestamp;
+ if (cb->cutoff_tz)
+ *cb->cutoff_tz = tz;
+ if (cb->cutoff_cnt)
+ *cb->cutoff_cnt = cb->reccnt;
+ hashcpy(cb->sha1, osha1);
+ if (is_null_sha1(cb->sha1))
+ hashcpy(cb->sha1, nsha1);
+ /* We just want the first entry */
+ return 1;
+}
+
+int read_ref_at(const char *refname, unsigned int flags, unsigned long at_time, int cnt,
+ unsigned char *sha1, char **msg,
+ unsigned long *cutoff_time, int *cutoff_tz, int *cutoff_cnt)
+{
+ struct read_ref_at_cb cb;
+
+ memset(&cb, 0, sizeof(cb));
+ cb.refname = refname;
+ cb.at_time = at_time;
+ cb.cnt = cnt;
+ cb.msg = msg;
+ cb.cutoff_time = cutoff_time;
+ cb.cutoff_tz = cutoff_tz;
+ cb.cutoff_cnt = cutoff_cnt;
+ cb.sha1 = sha1;
+
+ for_each_reflog_ent_reverse(refname, read_ref_at_ent, &cb);
+
+ if (!cb.reccnt) {
+ if (flags & GET_SHA1_QUIETLY)
+ exit(128);
+ else
+ die("Log for %s is empty.", refname);
+ }
+ if (cb.found_it)
+ return 0;
+
+ for_each_reflog_ent(refname, read_ref_at_ent_oldest, &cb);
+
+ return 1;
+}
--
2.4.2.644.g97b850b-twtrsrc
next prev parent reply other threads:[~2015-10-12 21:54 UTC|newest]
Thread overview: 71+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-12 21:51 [PATCH v3 00/44] alternate refs backends David Turner
2015-10-12 21:51 ` [PATCH v3 01/44] refs.c: create a public version of verify_refname_available David Turner
2015-10-13 2:28 ` Michael Haggerty
2015-10-12 21:51 ` [PATCH v3 02/44] refs: make repack_without_refs and is_branch public David Turner
2015-10-13 2:39 ` Michael Haggerty
2015-10-13 7:23 ` Michael Haggerty
2015-10-13 21:18 ` David Turner
2015-10-12 21:51 ` [PATCH v3 03/44] refs-be-files.c: rename refs to refs-be-files David Turner
2015-10-12 21:51 ` [PATCH v3 04/44] refs.c: add a new refs.c file to hold all common refs code David Turner
2015-10-12 21:51 ` [PATCH v3 05/44] refs.c: move update_ref to refs.c David Turner
2015-10-13 3:41 ` Michael Haggerty
2015-10-13 20:40 ` David Turner
2015-10-14 1:01 ` David Turner
2015-10-12 21:51 ` [PATCH v3 06/44] refs.c: move delete_ref and delete_refs to the common code David Turner
2015-10-13 3:51 ` Michael Haggerty
2015-10-12 21:51 ` David Turner [this message]
2015-10-12 21:51 ` [PATCH v3 08/44] refs.c: move the hidden refs functions " David Turner
2015-10-12 21:51 ` [PATCH v3 09/44] refs.c: move dwim and friend functions to the common refs code David Turner
2015-10-12 21:51 ` [PATCH v3 10/44] refs.c: move warn_if_dangling_symref* to the common code David Turner
2015-10-12 21:51 ` [PATCH v3 11/44] refs.c: move read_ref, read_ref_full and ref_exists " David Turner
2015-10-12 21:51 ` [PATCH v3 12/44] refs.c: move resolve_refdup to common David Turner
2015-10-12 21:51 ` [PATCH v3 13/44] refs.c: move check_refname_format to the common code David Turner
2015-10-12 21:51 ` [PATCH v3 14/44] refs.c: move is_branch " David Turner
2015-10-12 21:51 ` [PATCH v3 15/44] refs.c: move prettify_refname " David Turner
2015-10-12 21:51 ` [PATCH v3 16/44] refs.c: move ref iterators " David Turner
2015-10-13 4:12 ` Michael Haggerty
2015-10-12 21:51 ` [PATCH v3 17/44] refs.c: move head_ref_namespaced " David Turner
2015-10-12 21:51 ` [PATCH v3 18/44] refs: move transaction functions into " David Turner
2015-10-13 6:15 ` Michael Haggerty
2015-10-13 11:29 ` Michael Haggerty
2015-10-13 22:21 ` David Turner
2015-10-13 23:05 ` David Turner
2015-10-12 21:51 ` [PATCH v3 19/44] refs: add a backend method structure with transaction functions David Turner
2015-10-12 21:51 ` [PATCH v3 19/44] refs-be-files.c: " David Turner
2015-10-12 22:25 ` David Turner
2015-10-13 7:56 ` Michael Haggerty
2015-10-13 18:28 ` David Turner
2015-10-13 21:12 ` Michael Haggerty
2015-10-12 21:51 ` [PATCH v3 20/44] refs-be-files.c: add methods for misc ref operations David Turner
2015-10-13 7:44 ` Michael Haggerty
2015-10-12 21:51 ` [PATCH v3 21/44] refs-be-files.c: add methods for the ref iterators David Turner
2015-10-12 21:51 ` [PATCH v3 22/44] refs-be-files.c: add method for for_each_reftype_ David Turner
2015-10-12 21:51 ` [PATCH v3 23/44] refs-be-files.c: add do_for_each_per_worktree_ref David Turner
2015-10-12 21:51 ` [PATCH v3 24/44] refs.c: move refname_is_safe to the common code David Turner
2015-10-12 21:51 ` [PATCH v3 25/44] refs.h: document make refname_is_safe and add it to header David Turner
2015-10-13 7:33 ` Michael Haggerty
2015-10-13 9:18 ` Michael Haggerty
2015-10-13 18:32 ` David Turner
2015-10-12 21:51 ` [PATCH v3 26/44] refs.c: move copy_msg to the common code David Turner
2015-10-13 9:25 ` Michael Haggerty
2015-10-12 21:51 ` [PATCH v3 27/44] refs.c: move peel_object " David Turner
2015-10-13 9:34 ` Michael Haggerty
2015-10-12 21:51 ` [PATCH v3 28/44] refs.c: move should_autocreate_reflog to " David Turner
2015-10-12 21:51 ` [PATCH v3 29/44] refs.c: add ref backend init function David Turner
2015-10-12 21:51 ` [PATCH v3 30/44] refs.c: add methods for reflog David Turner
2015-10-12 21:51 ` [PATCH v3 31/44] refs.c: add method for initial ref transaction commit David Turner
2015-10-12 21:51 ` [PATCH v3 32/44] initdb: move safe_create_dir into common code David Turner
2015-10-12 21:51 ` [PATCH v3 33/44] refs.c: add method for initializing refs db David Turner
2015-10-12 21:51 ` [PATCH v3 34/44] refs-be-files.c: add method to rename refs David Turner
2015-10-12 21:51 ` [PATCH v3 35/44] refs: make lock generic David Turner
2015-10-12 21:51 ` [PATCH v3 36/44] refs: make files_log_ref_write functions public David Turner
2015-10-12 21:51 ` [PATCH v3 37/44] refs: break out a ref conflict check David Turner
2015-10-13 10:25 ` Michael Haggerty
2015-10-13 18:46 ` David Turner
2015-10-12 21:51 ` [PATCH v3 38/44] refs: move duplicate check to common code David Turner
2015-10-12 21:52 ` [PATCH v3 39/44] refs: always handle non-normal refs in files backend David Turner
2015-10-12 21:52 ` [PATCH v3 40/44] refs: allow ref backend to be set for clone David Turner
2015-10-12 21:52 ` [PATCH v3 41/44] refs: add register_refs_backend David Turner
2015-10-12 21:52 ` [PATCH v3 42/44] introduce "extensions" form of core.repositoryformatversion David Turner
2015-10-12 21:52 ` [PATCH v3 43/44] refs: add LMDB refs backend David Turner
2015-10-12 21:52 ` [PATCH v3 44/44] refs: tests for db backend David Turner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1444686725-27660-8-git-send-email-dturner@twopensource.com \
--to=dturner@twopensource.com \
--cc=git@vger.kernel.org \
--cc=mhagger@alum.mit.edu \
--cc=sahlberg@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).