All of lore.kernel.org
 help / color / mirror / Atom feed
From: Glen Choo <chooglen@google.com>
To: git@vger.kernel.org
Cc: Glen Choo <chooglen@google.com>
Subject: [PATCH v1 1/3] refs/files-backend: remove the_repository
Date: Thu, 11 Nov 2021 09:16:41 -0800	[thread overview]
Message-ID: <20211111171643.13805-2-chooglen@google.com> (raw)
In-Reply-To: <20211111171643.13805-1-chooglen@google.com>

refs/files-backend.c references the_repository in order to validate
object ids. However, 34224e14d6 (refs: plumb repo into ref stores,
2021-10-08), added repository pointers to ref stores, so we no longer
need to hardcode the_repository.

Replace the reference to the_repository with files_ref_store.base.repo.
This allows the files backend to work with in-core repositories other
than the_repository.

Signed-off-by: Glen Choo <chooglen@google.com>
---
 refs/files-backend.c | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/refs/files-backend.c b/refs/files-backend.c
index 4b14f30d48..10eac93cd4 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -1353,8 +1353,9 @@ static int rename_tmp_log(struct files_ref_store *refs, const char *newrefname)
 	return ret;
 }
 
-static int write_ref_to_lockfile(struct ref_lock *lock,
-				 const struct object_id *oid, struct strbuf *err);
+static int write_ref_to_lockfile(struct repository *repo, struct ref_lock *lock,
+				 const struct object_id *oid,
+				 struct strbuf *err);
 static int commit_ref_update(struct files_ref_store *refs,
 			     struct ref_lock *lock,
 			     const struct object_id *oid, const char *logmsg,
@@ -1501,7 +1502,7 @@ static int files_copy_or_rename_ref(struct ref_store *ref_store,
 	}
 	oidcpy(&lock->old_oid, &orig_oid);
 
-	if (write_ref_to_lockfile(lock, &orig_oid, &err) ||
+	if (write_ref_to_lockfile(refs->base.repo, lock, &orig_oid, &err) ||
 	    commit_ref_update(refs, lock, &orig_oid, logmsg, &err)) {
 		error("unable to write current sha1 into %s: %s", newrefname, err.buf);
 		strbuf_release(&err);
@@ -1521,7 +1522,7 @@ static int files_copy_or_rename_ref(struct ref_store *ref_store,
 
 	flag = log_all_ref_updates;
 	log_all_ref_updates = LOG_REFS_NONE;
-	if (write_ref_to_lockfile(lock, &orig_oid, &err) ||
+	if (write_ref_to_lockfile(refs->base.repo, lock, &orig_oid, &err) ||
 	    commit_ref_update(refs, lock, &orig_oid, NULL, &err)) {
 		error("unable to write current sha1 into %s: %s", oldrefname, err.buf);
 		strbuf_release(&err);
@@ -1756,14 +1757,15 @@ static int files_log_ref_write(struct files_ref_store *refs,
  * Write oid into the open lockfile, then close the lockfile. On
  * errors, rollback the lockfile, fill in *err and return -1.
  */
-static int write_ref_to_lockfile(struct ref_lock *lock,
-				 const struct object_id *oid, struct strbuf *err)
+static int write_ref_to_lockfile(struct repository *repo, struct ref_lock *lock,
+				 const struct object_id *oid,
+				 struct strbuf *err)
 {
 	static char term = '\n';
 	struct object *o;
 	int fd;
 
-	o = parse_object(the_repository, oid);
+	o = parse_object(repo, oid);
 	if (!o) {
 		strbuf_addf(err,
 			    "trying to write ref '%s' with nonexistent object %s",
@@ -2576,8 +2578,8 @@ static int lock_ref_for_update(struct files_ref_store *refs,
 			 * The reference already has the desired
 			 * value, so we don't need to write it.
 			 */
-		} else if (write_ref_to_lockfile(lock, &update->new_oid,
-						 err)) {
+		} else if (write_ref_to_lockfile(refs->base.repo, lock,
+						 &update->new_oid, err)) {
 			char *write_err = strbuf_detach(err, NULL);
 
 			/*
-- 
2.33.GIT


  reply	other threads:[~2021-11-11 17:16 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-11 17:16 [PATCH v1 0/3] make create_branch() accept any repository Glen Choo
2021-11-11 17:16 ` Glen Choo [this message]
2021-11-11 17:16 ` [PATCH v1 2/3] config: introduce repo_config_set* functions Glen Choo
2021-11-11 20:24   ` Junio C Hamano
2021-11-12  0:45     ` Glen Choo
2021-11-15 22:17       ` Glen Choo
2021-11-11 17:16 ` [PATCH v1 3/3] branch: remove implicit the_repository from create_branch() Glen Choo

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=20211111171643.13805-2-chooglen@google.com \
    --to=chooglen@google.com \
    --cc=git@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.