• S
    Replace use_packed_git with window cursors. · 03e79c88
    Shawn O. Pearce 提交于
    Part of the implementation concept of the sliding mmap window for
    pack access is to permit multiple windows per pack to be mapped
    independently.  Since the inuse_cnt is associated with the mmap and
    not with the file, this value is in struct pack_window and needs to
    be incremented/decremented for each pack_window accessed by any code.
    
    To faciliate that implementation we need to replace all uses of
    use_packed_git() and unuse_packed_git() with a different API that
    follows struct pack_window objects rather than struct packed_git.
    
    The way this works is when we need to start accessing a pack for
    the first time we should setup a new window 'cursor' by declaring
    a local and setting it to NULL:
    
      struct pack_windows *w_curs = NULL;
    
    To obtain the memory region which contains a specific section of
    the pack file we invoke use_pack(), supplying the address of our
    current window cursor:
    
      unsigned int len;
      unsigned char *addr = use_pack(p, &w_curs, offset, &len);
    
    the returned address `addr` will be the first byte at `offset`
    within the pack file.  The optional variable len will also be
    updated with the number of bytes remaining following the address.
    
    Multiple calls to use_pack() with the same window cursor will
    update the window cursor, moving it from one window to another
    when necessary.  In this way each window cursor variable maintains
    only one struct pack_window inuse at a time.
    
    Finally before exiting the scope which originally declared the window
    cursor we must invoke unuse_pack() to unuse the current window (which
    may be different from the one that was first obtained from use_pack):
    
      unuse_pack(&w_curs);
    
    This implementation is still not complete with regards to multiple
    windows, as only one window per pack file is supported right now.
    Signed-off-by: NShawn O. Pearce <spearce@spearce.org>
    Signed-off-by: NJunio C Hamano <junkio@cox.net>
    03e79c88
builtin-pack-objects.c 41.3 KB