git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Michael Haggerty <mhagger@alum.mit.edu>
To: Junio C Hamano <gitster@pobox.com>
Cc: Johannes Sixt <j6t@kdbg.org>,
	git@vger.kernel.org, Michael Haggerty <mhagger@alum.mit.edu>
Subject: [PATCH v2 03/16] lockfile: add accessors get_lock_file_fd() and get_lock_file_fp()
Date: Mon, 10 Aug 2015 11:47:38 +0200	[thread overview]
Message-ID: <4676c6a550fecceb921cc71b3cc5320004c6b0c8.1439198011.git.mhagger@alum.mit.edu> (raw)
In-Reply-To: <cover.1439198011.git.mhagger@alum.mit.edu>

We are about to move those members, so change client code to read them
through accessor functions.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
---
 credential-store.c |  2 +-
 lockfile.c         | 14 ++++++++++++++
 lockfile.h         |  3 +++
 read-cache.c       |  2 +-
 refs.c             | 12 +++++++-----
 5 files changed, 26 insertions(+), 7 deletions(-)

diff --git a/credential-store.c b/credential-store.c
index f692509..00aea3a 100644
--- a/credential-store.c
+++ b/credential-store.c
@@ -52,7 +52,7 @@ static void print_entry(struct credential *c)
 static void print_line(struct strbuf *buf)
 {
 	strbuf_addch(buf, '\n');
-	write_or_die(credential_lock.fd, buf->buf, buf->len);
+	write_or_die(get_lock_file_fd(&credential_lock), buf->buf, buf->len);
 }
 
 static void rewrite_credential_file(const char *fn, struct credential *c,
diff --git a/lockfile.c b/lockfile.c
index 2369eff..df9c704 100644
--- a/lockfile.c
+++ b/lockfile.c
@@ -364,6 +364,20 @@ FILE *fdopen_lock_file(struct lock_file *lk, const char *mode)
 	return lk->fp;
 }
 
+int get_lock_file_fd(struct lock_file *lk)
+{
+	if (!lk->active)
+		die("BUG: get_lock_file_fd() called for unlocked object");
+	return lk->fd;
+}
+
+FILE *get_lock_file_fp(struct lock_file *lk)
+{
+	if (!lk->active)
+		die("BUG: get_lock_file_fp() called for unlocked object");
+	return lk->fp;
+}
+
 char *get_locked_file_path(struct lock_file *lk)
 {
 	if (!lk->active)
diff --git a/lockfile.h b/lockfile.h
index a483cc9..d9dfbc9 100644
--- a/lockfile.h
+++ b/lockfile.h
@@ -203,6 +203,9 @@ extern NORETURN void unable_to_lock_die(const char *path, int err);
  */
 extern FILE *fdopen_lock_file(struct lock_file *lk, const char *mode);
 
+extern int get_lock_file_fd(struct lock_file *lk);
+extern FILE *get_lock_file_fp(struct lock_file *lk);
+
 /*
  * Return the path of the file that is locked by the specified
  * lock_file object. The caller must free the memory.
diff --git a/read-cache.c b/read-cache.c
index 723d48d..96cb9a3 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -2112,7 +2112,7 @@ static int commit_locked_index(struct lock_file *lk)
 static int do_write_locked_index(struct index_state *istate, struct lock_file *lock,
 				 unsigned flags)
 {
-	int ret = do_write_index(istate, lock->fd, 0);
+	int ret = do_write_index(istate, get_lock_file_fd(lock), 0);
 	if (ret)
 		return ret;
 	assert((flags & (COMMIT_LOCK | CLOSE_LOCK)) !=
diff --git a/refs.c b/refs.c
index a742d79..0f49a62 100644
--- a/refs.c
+++ b/refs.c
@@ -3162,6 +3162,7 @@ static int write_ref_to_lockfile(struct ref_lock *lock,
 {
 	static char term = '\n';
 	struct object *o;
+	int fd;
 
 	o = parse_object(sha1);
 	if (!o) {
@@ -3178,8 +3179,9 @@ static int write_ref_to_lockfile(struct ref_lock *lock,
 		errno = EINVAL;
 		return -1;
 	}
-	if (write_in_full(lock->lk->fd, sha1_to_hex(sha1), 40) != 40 ||
-	    write_in_full(lock->lk->fd, &term, 1) != 1 ||
+	fd = get_lock_file_fd(lock->lk);
+	if (write_in_full(fd, sha1_to_hex(sha1), 40) != 40 ||
+	    write_in_full(fd, &term, 1) != 1 ||
 	    close_ref(lock) < 0) {
 		int save_errno = errno;
 		error("Couldn't write %s", lock->lk->filename.buf);
@@ -4264,10 +4266,10 @@ int reflog_expire(const char *refname, const unsigned char *sha1,
 			status |= error("couldn't write %s: %s", log_file,
 					strerror(errno));
 		} else if (update &&
-			   (write_in_full(lock->lk->fd,
+			   (write_in_full(get_lock_file_fd(lock->lk),
 				sha1_to_hex(cb.last_kept_sha1), 40) != 40 ||
-			 write_str_in_full(lock->lk->fd, "\n") != 1 ||
-			 close_ref(lock) < 0)) {
+			    write_str_in_full(get_lock_file_fd(lock->lk), "\n") != 1 ||
+			    close_ref(lock) < 0)) {
 			status |= error("couldn't write %s",
 					lock->lk->filename.buf);
 			rollback_lock_file(&reflog_lock);
-- 
2.5.0

  parent reply	other threads:[~2015-08-10  9:48 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-10  9:47 [PATCH v2 00/16] Introduce a tempfile module Michael Haggerty
2015-08-10  9:47 ` [PATCH v2 01/16] Move lockfile documentation to lockfile.h and lockfile.c Michael Haggerty
2015-08-11 19:27   ` Junio C Hamano
2015-08-10  9:47 ` [PATCH v2 02/16] create_bundle(): duplicate file descriptor to avoid closing it twice Michael Haggerty
2015-08-10  9:47 ` Michael Haggerty [this message]
2015-08-11 19:29   ` [PATCH v2 03/16] lockfile: add accessors get_lock_file_fd() and get_lock_file_fp() Junio C Hamano
2015-08-10  9:47 ` [PATCH v2 04/16] lockfile: add accessor get_lock_file_path() Michael Haggerty
2015-08-11 19:36   ` Junio C Hamano
2015-08-10  9:47 ` [PATCH v2 05/16] commit_lock_file(): use get_locked_file_path() Michael Haggerty
2015-08-10  9:47 ` [PATCH v2 06/16] tempfile: a new module for handling temporary files Michael Haggerty
2015-08-10  9:47 ` [PATCH v2 07/16] prepare_tempfile_object(): new function, extracted from create_tempfile() Michael Haggerty
2015-08-11 19:38   ` Junio C Hamano
2015-08-10  9:47 ` [PATCH v2 08/16] tempfile: add several functions for creating temporary files Michael Haggerty
2015-08-10  9:47 ` [PATCH v2 09/16] register_tempfile(): new function to handle an existing temporary file Michael Haggerty
2015-08-10  9:47 ` [PATCH v2 10/16] write_shared_index(): use tempfile module Michael Haggerty
2015-08-10  9:47 ` [PATCH v2 11/16] setup_temporary_shallow(): " Michael Haggerty
2015-08-10  9:47 ` [PATCH v2 12/16] diff: " Michael Haggerty
2015-08-11 20:03   ` Junio C Hamano
2015-08-12 15:13     ` Michael Haggerty
2015-08-12 16:41       ` Junio C Hamano
2015-08-12 17:12         ` [PATCH v2' " Michael Haggerty
2015-08-10  9:47 ` [PATCH v2 13/16] lock_repo_for_gc(): compute the path to "gc.pid" only once Michael Haggerty
2015-08-11 20:06   ` Junio C Hamano
2015-08-11 20:20     ` Junio C Hamano
2015-08-10  9:47 ` [PATCH v2 14/16] gc: use tempfile module to handle gc.pid file Michael Haggerty
2015-08-10  9:47 ` [PATCH v2 15/16] credential-cache--daemon: delete socket from main() Michael Haggerty
2015-08-10  9:47 ` [PATCH v2 16/16] credential-cache--daemon: use tempfile module Michael Haggerty
2015-08-11 20:21 ` [PATCH v2 00/16] Introduce a " Junio C Hamano
2015-08-12 15:14   ` Michael Haggerty

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

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4676c6a550fecceb921cc71b3cc5320004c6b0c8.1439198011.git.mhagger@alum.mit.edu \
    --to=mhagger@alum.mit.edu \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=j6t@kdbg.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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).