Re: [PATCH 08/11] streaming_write_entry(): support files with holes

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, May 15, 2011 at 9:30 PM, Junio C Hamano <gitster@xxxxxxxxx> wrote:
> One typical use of a large binary file is to hold a sparse on-disk hash
> table with a lot of holes. Help preserving the holes with lseek().
>
> Signed-off-by: Junio C Hamano <gitster@xxxxxxxxx>
> ---
> Âentry.c | Â 18 +++++++++++++++++-
> Â1 files changed, 17 insertions(+), 1 deletions(-)
>
> diff --git a/entry.c b/entry.c
> index 7733a6b..d50e388 100644
> --- a/entry.c
> +++ b/entry.c
> @@ -123,6 +123,7 @@ static int streaming_write_entry(struct cache_entry *ce, char *path,
> Â Â Â Âenum object_type type;
> Â Â Â Âunsigned long sz;
> Â Â Â Âint result = -1;
> + Â Â Â ssize_t kept = 0;
> Â Â Â Âint fd = -1;
>
> Â Â Â Âst = open_istream(ce->sha1, &type, &sz);
> @@ -137,17 +138,32 @@ static int streaming_write_entry(struct cache_entry *ce, char *path,
>
> Â Â Â Âfor (;;) {
> Â Â Â Â Â Â Â Âchar buf[10240];
> - Â Â Â Â Â Â Â ssize_t wrote;
> + Â Â Â Â Â Â Â ssize_t wrote, holeto;
> Â Â Â Â Â Â Â Âssize_t readlen = read_istream(st, buf, sizeof(buf));
>
> Â Â Â Â Â Â Â Âif (!readlen)
> Â Â Â Â Â Â Â Â Â Â Â Âbreak;
> + Â Â Â Â Â Â Â for (holeto = 0; holeto < readlen; holeto++)
> + Â Â Â Â Â Â Â Â Â Â Â if (buf[holeto])
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â break;
> + Â Â Â Â Â Â Â if (readlen == holeto) {
> + Â Â Â Â Â Â Â Â Â Â Â kept += holeto;
> + Â Â Â Â Â Â Â Â Â Â Â continue;
> + Â Â Â Â Â Â Â }
>
> + Â Â Â Â Â Â Â if (kept && lseek(fd, kept, SEEK_CUR) == (off_t) -1)
> + Â Â Â Â Â Â Â Â Â Â Â goto close_and_exit;
> + Â Â Â Â Â Â Â else
> + Â Â Â Â Â Â Â Â Â Â Â kept = 0;
> Â Â Â Â Â Â Â Âwrote = write_in_full(fd, buf, readlen);
>
> Â Â Â Â Â Â Â Âif (wrote != readlen)
> Â Â Â Â Â Â Â Â Â Â Â Âgoto close_and_exit;
> Â Â Â Â}
> + Â Â Â if (kept &&
> + Â Â Â Â Â (( Âlseek(fd, kept - 1, SEEK_CUR) == (off_t) -1)
There is an extra whitespace after ((

> + Â Â Â Â Â Â|| write(fd, "", 1) != 1))
> + Â Â Â Â Â Â Â goto close_and_exit;
> Â Â Â Â*fstat_done = fstat_output(fd, state, statbuf);
>
> Âclose_and_exit:
> --
> 1.7.5.1.365.g32b65
>
> --
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@xxxxxxxxxxxxxxx
> More majordomo info at Âhttp://vger.kernel.org/majordomo-info.html
>
ÿô.nlj·Ÿ®‰­†+%ŠË±é¥Šwÿº{.nlj· ŠßžØn‡r¡öë¨è&£ûz¹Þúzf£¢·hšˆ§~†­†Ûÿÿïÿ‘ê_èæ+v‰¨þ)ßø

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]