Re: [4/5] Add option for hardlinkable cache of extracted blobs
- From
Petr Baudis <pasky@ucw.cz>
- Date
- Apr 17, 2005, 17:47 UTC
- Message-ID
- <20050417174736.GA1461@pasky.ji.cz>
- In-Reply-To
- <Pine.LNX.4.21.0504171131230.30848-100000@iabervon.org>
Dear diary, on Sun, Apr 17, 2005 at 05:35:19PM CEST, I got a letter where Daniel Barkalow <barkalow@iabervon.org> told me that...
Show 17 quoted lines
> Index: checkout-cache.c
> ===================================================================
> --- 157b46ce1d82b3579e2e1258927b0d9bdbc033ab/checkout-cache.c (mode:100644 sha1:5d3028df0a45329e45fff2006719c9267adeb946)
> +++ 08f7700831e056ad710af69f91e3a8a705b6b2b1/checkout-cache.c (mode:100644 sha1:338588259e17dd235fdc7db759d770004a760e15)
> @@ -67,6 +71,80 @@
> return fd;
> }
>
> +#ifdef HARDLINK_CACHE
> +
> +/*
> + * NOTE! This returns a statically allocated buffer, so you have to be
> + * careful about using it. Do a "strdup()" if you need to save the
> + * filename.
> + */
> +char *sha1_blob_cache_file_name(const unsigned char *sha1)
> +{..code basically identical with sha1_file_name()..
> +}
You can guess what would I like you to do. ;-)
Show 14 quoted lines
> +
> +static int write_entry(struct cache_entry *ce)
> +{
> + int fd;
> + void *new;
> + unsigned long size;
> + long wrote;
> + char type[20];
> + char *cache_name;
> + struct stat st;
> +
> + cache_name = sha1_blob_cache_file_name(ce->sha1);
> +
> + if (stat(cache_name, &st)) {..basically cut'n'paste of non-hardlinking write_entry()..
BTW, I'd just use access(F_OK) instead of stat() it I don't care about the file's stat at all anyway.
Show 9 quoted lines
> + }
> + if (link(cache_name, ce->name)) {
> + if (errno == ENOENT) {
> + create_directories(ce->name);
> + link(cache_name, ce->name);
> + }
> + }
> + return 0;
> +}I think it would be better to have this as hardlink_entry() and write_entry() to take the file name to write the entry to. Then you should explicitly multiplex in checkout_cache() between what you do.
-- Petr "Pasky" Baudis Stuff: http://pasky.or.cz/ C++: an octopus made by nailing extra legs onto a dog. -- Steve Taylor