diff mbox series

fixup! refs: plumb repo into ref stores

Message ID 20211006174231.80434-1-chooglen@google.com (mailing list archive)
State New, archived
Headers show
Series fixup! refs: plumb repo into ref stores | expand

Commit Message

Glen Choo Oct. 6, 2021, 5:42 p.m. UTC
If we are plumbing repo into ref stores, it makes sense to get rid of
the_repository in refs/files-backend.c and use ref_store.repo instead.

Signed-off-by: Glen Choo <chooglen@google.com>
---
In [1], I made some changes to refs/files-backend.c to get rid of
the_repository and accept struct repository as a parameter instead. But,
if we're changing ref stores to contain their own repository, it makes
sense to use this new interface.

I think the most natural place for this is this series. Let me know what
you think :)

[1] https://lore.kernel.org/git/20210921232529.81811-2-chooglen@google.com/

 refs/files-backend.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

Comments

Jonathan Tan Oct. 8, 2021, 8:05 p.m. UTC | #1
> If we are plumbing repo into ref stores, it makes sense to get rid of
> the_repository in refs/files-backend.c and use ref_store.repo instead.

Doing that would mean changing some functions (e.g. should_pack_ref())
to take a ref store or repository parameter, and as it is, I'm not sure
if there are still implicit references to the_repository. I think that
all these can be done in a separate patch set.
Jonathan Tan Oct. 8, 2021, 8:07 p.m. UTC | #2
> If we are plumbing repo into ref stores, it makes sense to get rid of
> the_repository in refs/files-backend.c and use ref_store.repo instead.
> 
> Signed-off-by: Glen Choo <chooglen@google.com>
> ---
> In [1], I made some changes to refs/files-backend.c to get rid of
> the_repository and accept struct repository as a parameter instead. But,
> if we're changing ref stores to contain their own repository, it makes
> sense to use this new interface.
> 
> I think the most natural place for this is this series. Let me know what
> you think :)
> 
> [1] https://lore.kernel.org/git/20210921232529.81811-2-chooglen@google.com/

[snip]

> @@ -1347,7 +1347,7 @@ 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,
> +static int write_ref_to_lockfile(struct repository *repo, struct ref_lock *lock,

Ah sorry, I didn't see that you already did this. I don't think that
it's natural to do it here - it's probably better to do it in another
patch set that also verifies that there are no implicit references to
the_repository.
diff mbox series

Patch

diff --git a/refs/files-backend.c b/refs/files-backend.c
index 9d50fc91f8..0358268aba 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -1347,7 +1347,7 @@  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,
+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,
@@ -1465,7 +1465,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(ref_store->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);
@@ -1485,7 +1485,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(ref_store->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);
@@ -1720,14 +1720,14 @@  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,
+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",
@@ -2531,7 +2531,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,
+		} else if (write_ref_to_lockfile(refs->base.repo, lock,
+						 &update->new_oid,
 						 err)) {
 			char *write_err = strbuf_detach(err, NULL);