Skip to content
  • Junio C Hamano's avatar
    Make sure objects/pack exists before creating a new pack · 6e180cdc
    Junio C Hamano authored
    In a repository created with git older than f49fb35d (git-init-db: create
    "pack" subdirectory under objects, 2005-06-27), objects/pack/ directory is
    not created upon initialization.  It was Ok because subdirectories are
    created as needed inside directories init-db creates, and back then,
    packfiles were recent invention.
    
    After the said commit, new codepaths started relying on the presense of
    objects/pack/ directory in the repository.  This was exacerbated with
    8b4eb6b6
    
     (Do not perform cross-directory renames when creating packs,
    2008-09-22) that moved the location temporary pack files are created from
    objects/ directory to objects/pack/ directory, because moving temporary to
    the final location was done carefully with lazy leading directory creation.
    
    Many packfile related operations in such an old repository can fail
    mysteriously because of this.
    
    This commit introduces two helper functions to make things work better.
    
     - odb_mkstemp() is a specialized version of mkstemp() to refactor the
       code and teach it to create leading directories as needed;
    
     - odb_pack_keep() refactors the code to create a ".keep" file while
       create leading directories as needed.
    
    Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
    6e180cdc