JuliaLang/julia

LibGit2 refactor

Open

#19,839 opened on Jan 3, 2017

 (16 comments) (5 reactions) (0 assignees)Julia (5,773 forks)batch import
help wantedlibgit2

Repository metrics

Stars
 (48,709 stars)
PR merge metrics
 (Avg merge 20d 6h) (157 merged PRs in 30d)

Description

The LibGit2 module could do with some work. Some possible changes

  • functions should mirror CLI (command line interface) git functionality when possible
    • e.g. LibGit2.checkout instead of LibGit2.branch!
    • possible exceptions when CLI does multiple things in one go
  • consistent use of ! suffix
  • use Enum and FlagEnum (pending #19470) for constants whenever possible
  • don't swallow errors:
    • e.g. rebase! will silently abort if it fails
    • revparse as well
  • Normalize and check path inputs, ref #18724.
  • Clean up a few objects which allocate memory in a confusing way:
    • StrArrayStruct: manually calls Libc.malloc, but then frees via LibGit2 git_strarray_free
    • Buffer: is an immutable object, but needs a finalizer
    • SignatureStruct, GitSignature, Signature objects should be simplified
  • split out LibGit2.get into more usefully-named functions
    • Maybe via constructors? e.g. GitBlob(repo::GitRepo, hash::GitHash)
    • when returning a GitObject, automatically resolve its type via git_object_type function
    • LibGit2.get(T, repo, oid) should throw an error (TypeError?) if incorrect type T is used.
  • Make GitConfig objects act like an Associative{String,String} (i.e. overload getindex/setindex!)
  • rename GitAnyObject to GitUnknownObject #19935
  • rename Oid to GitHash #19878
  • Different types for full GitHash and short hashes: see https://github.com/JuliaLang/julia/pull/19878#issuecomment-270714556
  • More sensible errors and return values
    • LibGit2.fetch should return nothing (since it will throw an error for any other value)
    • LibGit2.reset! and rebase should return current HEAD commit
    • LibGit2.upstream and LibGit2.lookup_branch should throw errors if not found, instead of returning nothing
    • Don't use "zero" GitHash objects as null values.
  • Support newbase option for rebase! (cf https://github.com/JuliaLang/julia/pull/19651#discussion_r94463640)
  • Use correct iteration protocol for Base.next(::LibGit2.Rebase) (or until new iteration protocol is in place)
  • Combine LibGit2.owner and LibGit2.repository
  • Get rid of a lot of the with and explicit finalize/close calls (pending #19660)
  • Sensible show methods for various objects
    • GitBlob
    • GitCommit
    • GitRemote
    • GitSignature
    • GitTag
    • GitTreeEntry
    • GitReference
    • GitIndex
    • DiffDelta
    • DiffFile
    • FetchHead
    • GitTree
    • GitDiff
    • GitAnnotated
    • GitRebase
  • Better documentation (#18810)
    • what the function/type does
    • arguments/output value
    • equivalent git CLI command where appropriate
  • Better tests:
    • More coverage
    • Can test behaviour against command line Git
  • Consistent handling of git_*_options structs
    • Correct handling of memory allocation of pointer fields
    • Callback interface
  • Rename isdiff to a more descriptive name (https://github.com/JuliaLang/julia/pull/20155#discussion_r97181726)
  • get rid of cat?
    • It's more or less a wrapper around content.
  • document status/GitStatus return types and what results mean https://github.com/JuliaLang/julia/pull/20503#issuecomment-278394964

Some of these are breaking, so we may want to get the deprecations in place before 0.6.

Contributor guide