e9ee401 Allow the repo querying infractracture to load a shallow clone

Authored and Committed by zbyszek a year ago
    Allow the repo querying infractracture to load a shallow clone
    
    The way that pygit2 (libgit2?) reacts to a shallow clone is very unfortunate:
    it throws a KeyError in the iterator so it's hard to handle such cases nicely.
    Let's hope that libgit2 and pygit2 get native support for shallow clones at some
    point. For now, let's just check if .git/shallow is present and cut short the
    loop walking over the commits.
    
    This is enough for 'rpmautospec calculate-release' and 'rpmautospec generate-changelog'
    to work, as long as all the commits that are necessary to get a result are
    present. I.e., if e.g. conversion to rpmautospec happened n commits ago, and the
    repo is shallow clone with at least n+1 commits, things should work. But if it's
    shallower than that, it'll fail with KeyError, the same as before.
    
    "Are present" means exactly how it sounds: any commit that rpmautospec would look
    at must be present, and otherwise the command fails with KeyError. For
    'calculate-release' this means the parent of the commit which changed Version,
    and for 'generate-changelog' the parent of the commit which touched 'changelog'
    file or the root of the repo. I.e. for repos which don't have 'changelog', we
    need full history. Note that this is "safe": we will never generate wrong
    release values, but instead fail with KeyError.
    
    This is only a partial solution. It could be solved more nicely in pygit2/libgit2,
    but let's do the bare minimum to get some common cases working without
    complicating rpmautospec code too much.
    
    Partially fixes #227.
    
    Signed-off-by: Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
    
        
file modified
+15 -0