All of lore.kernel.org
 help / color / mirror / Atom feed
From: Patrick Steinhardt <ps@pks.im>
To: Kaartic Sivaraam <kaartic.sivaraam@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH 4/6] odb/source-loose: deduplicate logic to mmap objects
Date: Wed, 11 Nov 2026 14:40:43 +0100	[thread overview]
Message-ID: <avRwW_Jy2lsNih89@pks.im> (raw)
In-Reply-To: <9794ae30-d6a4-478a-aa25-88f8d9e02810@gmail.com>

On Tue, Nov 10, 2026 at 07:45:58PM +0530, Kaartic Sivaraam wrote:
> On 11/2/26 16:50, Patrick Steinhardt wrote:
> > diff --git a/odb/source-loose.c b/odb/source-loose.c
> > index a90268e200a..5cd679e802c 100644
> > --- a/odb/source-loose.c
> > +++ b/odb/source-loose.c
> > @@ -544,28 +544,11 @@ static void *odb_source_loose_map_object(struct odb_source_loose *loose,
> >   					 const struct object_id *oid,
> >   					 unsigned long *size)
> >   {
> > -	const char *p;
> > -	int fd = open_loose_object(loose, oid, &p);
> > -	void *map = NULL;
> > -	struct stat st;
> > -
> > +	const char *path;
> > +	int fd = open_loose_object(loose, oid, &path);
> >   	if (fd < 0)
> >   		return NULL;
> > -
> > -	if (!fstat(fd, &st)) {
> > -		*size = xsize_t(st.st_size);
> > -		if (!*size) {
> > -			/* mmap() is forbidden on empty files */
> > -			error(_("object file %s is empty"), p);
> > -			goto out;
> > -		}
> > -
> > -		map = xmmap(NULL, *size, PROT_READ, MAP_PRIVATE, fd, 0);
> > -	}
> > -
> > -out:
> > -	close(fd);
> > -	return map;
> > +	return map_fd(fd, path, size);
> 
> I just noticed that map_fd could follow the goto pattern followed above and
> avoid the redundant close() call. Something like:
> 
> diff --git a/odb/source-loose.c b/odb/source-loose.c
> index 737d583f03..4ace94084f 100644
> --- a/odb/source-loose.c
> +++ b/odb/source-loose.c
> @@ -532,11 +532,12 @@ static void *map_fd(int fd, const char *path, unsigned
> long *size)
>  		if (!*size) {
>  			/* mmap() is forbidden on empty files */
>  			error(_("object file %s is empty"), path);
> -			close(fd);
> -			return NULL;
> +			goto out;
>  		}
>  		map = xmmap(NULL, *size, PROT_READ, MAP_PRIVATE, fd, 0);
>  	}
> +
> +out:
>  	close(fd);
>  	return map;
>  }
> 
> Of course, this isn't really a show-stopper for this patch. Just another
> relevant cleanup I noticed.

True, but I'll skip this one as I don't otherwise touch `map_fd()`.

Patrick

  reply	other threads:[~2026-11-11 13:40 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-02 11:20 [PATCH 0/6] object-file: move logic related to the loose backend Patrick Steinhardt
2026-11-02 11:20 ` [PATCH 1/6] object-file: move logic to read loose objects into backend Patrick Steinhardt
2026-11-10 13:10   ` Kaartic Sivaraam
2026-11-11 13:38     ` Patrick Steinhardt
2026-11-02 11:20 ` [PATCH 2/6] object-file: move logic to derive loose object paths " Patrick Steinhardt
2026-11-10 13:28   ` Kaartic Sivaraam
2026-11-11 13:40     ` Patrick Steinhardt
2026-11-02 11:20 ` [PATCH 3/6] object-file: move iteration over loose files " Patrick Steinhardt
2026-11-10 13:57   ` Kaartic Sivaraam
2026-11-02 11:20 ` [PATCH 4/6] odb/source-loose: deduplicate logic to mmap objects Patrick Steinhardt
2026-11-10 14:15   ` Kaartic Sivaraam
2026-11-11 13:40     ` Patrick Steinhardt [this message]
2026-11-02 11:20 ` [PATCH 5/6] object-file: stop including "odb/source-loose.h" Patrick Steinhardt
2026-11-10 16:13   ` Kaartic Sivaraam
2026-11-11 13:40     ` Patrick Steinhardt
2026-11-02 11:20 ` [PATCH 6/6] object-file: stop including "git-zlib.h" Patrick Steinhardt
2026-11-10 16:13   ` Kaartic Sivaraam

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=avRwW_Jy2lsNih89@pks.im \
    --to=ps@pks.im \
    --cc=git@vger.kernel.org \
    --cc=kaartic.sivaraam@gmail.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 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.