Skip to content

Pass --depth 1 to git #4345

Closed
Closed

Description

@domenkozar

Some git repositories can be really big (i.e. amazonka), does stack need anything else from the git history besides the latest revision? This would save bandwidth and time fetching git dependencies.

Activity

  1. mihaimaruseac commented on Oct 13, 2018

    @mihaimaruseac
    Member

    It seems that we are already doing this?

    let args = [ "clone", repo , "stack", "--depth", "1", "--recursive", "--branch", branch]

  2. mgsloan commented on Oct 13, 2018

    @mgsloan
    Contributor

    @mihaimaruseac That is the invocation for stack upgrading from its own source repo. I believe that @domenkozar is referring to the invocations for fetching dependencies from git.

    IIRC the reason depth wasn't set to 1 was in order to have sharing of git objects when updating the git dependencies - I believe at some point it would try to reuse the existing repo instead of recloning. Looks like now it simply reclones each time, though, so indeed --depth 1 could be used here -

    RepoGit -> cloneAndExtract "git" ["--recursive"] ["--git-dir=.git", "reset", "--hard"]

  3. mihaimaruseac commented on Oct 13, 2018

    @mihaimaruseac
    Member

    Makes sense then. i'll do a PR asap in that case.

  4. mihaimaruseac commented on Oct 13, 2018

    @mihaimaruseac
    Member

    Oh, but that file has been dropped from master

  5. mihaimaruseac commented on Oct 13, 2018

    @mihaimaruseac
    Member

    If I understand

    github = withObjectWarnings "PLArchive:github" $ \o -> do
    GitHubRepo ghRepo <- o ..: "github"
    commit <- o ..: "commit"
    let archiveLocation = ALUrl $ T.concat
    [ "https://github.com/"
    , ghRepo
    , "/archive/"
    , commit
    , ".tar.gz"
    ]
    archiveHash <- o ..:? "sha256"
    archiveSize <- o ..:? "size"
    os <- optionalSubdirs o
    pure $ pure $ NE.map (\(archiveSubdir, pm) -> PLIArchive Archive {..} pm) (osToPms os)
    correctly then it's now cloning at a specified commit.

    Guess I'll just have to trace it when I get some more free time and see how it behaves.

  6. domenkozar commented on Oct 14, 2018

    @domenkozar
    ContributorAuthor

    That is using the tarball without git, which is a good alternative. But using git could have a similar performance, if --depth 1 was added a few lines above.

  7. dbaynard commented on Oct 21, 2018

    @dbaynard
    Contributor

    I believe there was a discussion with @snoyberg and @sol about a new way to proceed here (I think it involved caching somewhere).

  8. snoyberg commented on Oct 22, 2018

    @snoyberg
    Contributor

    With the new way we do things with Pantry (checking out the repo and caching it in the SQLite store), skipping the history clone would be great. The relevant code for doing the cloning is here:

    let (commandName, resetArgs, submoduleArgs, archiveArgs) =
    case repoType' of
    RepoGit ->
    ( "git"
    , ["reset", "--hard", T.unpack commit]
    , Just ["submodule", "update", "--init", "--recursive"]
    , ["archive", "-o", tarball, "HEAD"]
    )
    RepoHg ->
    ( "hg"
    , ["update", "-C", T.unpack commit]
    , Nothing
    , ["archive", tarball, "-X", ".hg_archival.txt"]
    )
    let runCommand args = void $ proc commandName args readProcess_
    logInfo $ "Cloning " <> display commit <> " from " <> display url
    runCommand ("clone" : [T.unpack url, suffix])
    -- On Windows 10, an upstream issue with the `git clone` command means that
    -- command clears, but does not then restore, the
    -- ENABLE_VIRTUAL_TERMINAL_PROCESSING flag for native terminals. The
    -- folowing hack re-enables the lost ANSI-capability.
    when osIsWindows $ void $ liftIO $ hSupportsANSIWithoutEmulation stdout
    created <- doesDirectoryExist dir
    unless created $ throwIO $ FailedToCloneRepo repo

    The problem is that, to my recollection, some older versions of Git do not support cloning at a specific commit. Therefore, cloning at depth 1 would prevent us from then resetting to the commit we want.

  9. domenkozar commented on Oct 22, 2018

    @domenkozar
    ContributorAuthor

    I see, it cloning revision even requires special feature on the server: https://stackoverflow.com/questions/31278902/how-to-shallow-clone-a-specific-commit-with-depth-1

    I guess the only thing that can be done then is to make depth an option, so user can hand-pick it.

  10. dbaynard commented on Oct 22, 2018

    @dbaynard
    Contributor

    Yes, a server feature, though we can pick sensible defaults?

  11. snoyberg commented on Jan 18, 2019

    @snoyberg
    Contributor

    How about a setting in the extra-deps itself saying whether to turn on --depth 1 or not? Then we can bikeshed on whether on or off is the correct default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions