vincenthz / hit Goto Github PK
View Code? Open in Web Editor NEWlibrary to manipulate git repositories in haskell (no bindings)
License: Other
library to manipulate git repositories in haskell (no bindings)
License: Other
I can't find a "git" implementation that uses anything but SHA-1. Since this is a re-implementation, being able to use another hash function would be useful in the case where the security properties of the hash function is important.
> /tmp/stackage-build14/git-0.1$ dist/build/test-repository/test-repository
cannot run this test without repository. clone the original repository for test
test/git/monad [FAILED]
- not a git repository
CallStack (from HasCallStack):
error, called at ./Data/Git/Storage.hs:137:27 in git-0.1-4KwDRjzZHIf41TzbJEfNYk:Data.Git.Storage
I just got this failure from Stackage. Tests have been passing for a while now, so it might be a change in a dependency.
Unpacking to hit-0.4.3/
Resolving dependencies...
Configuring hit-0.4.3...
Building hit-0.4.3...
Preprocessing library hit-0.4.3...
[ 1 of 17] Compiling Data.Git.Internal ( Data/Git/Internal.hs, dist/build/Data/Git/Internal.o )
[ 2 of 17] Compiling Data.Git.Storage.CacheFile ( Data/Git/Storage/CacheFile.hs, dist/build/Data/Git/Storage/CacheFile.o )
[ 3 of 17] Compiling Data.Git.Storage.FileReader ( Data/Git/Storage/FileReader.hs, dist/build/Data/Git/Storage/FileReader.o )
[ 4 of 17] Compiling Data.Git.Delta ( Data/Git/Delta.hs, dist/build/Data/Git/Delta.o )
[ 5 of 17] Compiling Data.Git.Revision ( Data/Git/Revision.hs, dist/build/Data/Git/Revision.o )
[ 6 of 17] Compiling Data.Git.Ref ( Data/Git/Ref.hs, dist/build/Data/Git/Ref.o )
[ 7 of 17] Compiling Data.Git.Types ( Data/Git/Types.hs, dist/build/Data/Git/Types.o )
[ 8 of 17] Compiling Data.Git.Path ( Data/Git/Path.hs, dist/build/Data/Git/Path.o )
[ 9 of 17] Compiling Data.Git.Named ( Data/Git/Named.hs, dist/build/Data/Git/Named.o )
[10 of 17] Compiling Data.Git.Storage.PackIndex ( Data/Git/Storage/PackIndex.hs, dist/build/Data/Git/Storage/PackIndex.o )
[11 of 17] Compiling Data.Git.Storage.Object ( Data/Git/Storage/Object.hs, dist/build/Data/Git/Storage/Object.o )
[12 of 17] Compiling Data.Git.Storage.Pack ( Data/Git/Storage/Pack.hs, dist/build/Data/Git/Storage/Pack.o )
[13 of 17] Compiling Data.Git.Storage.FileWriter ( Data/Git/Storage/FileWriter.hs, dist/build/Data/Git/Storage/FileWriter.o )
[14 of 17] Compiling Data.Git.Storage.Loose ( Data/Git/Storage/Loose.hs, dist/build/Data/Git/Storage/Loose.o )
[15 of 17] Compiling Data.Git.Storage ( Data/Git/Storage.hs, dist/build/Data/Git/Storage.o )
[16 of 17] Compiling Data.Git.Repository ( Data/Git/Repository.hs, dist/build/Data/Git/Repository.o )
[17 of 17] Compiling Data.Git ( Data/Git.hs, dist/build/Data/Git.o )
In-place registering hit-0.4.3...
Preprocessing test suite 'test-repository' for hit-0.4.3...
[1 of 1] Compiling Main ( Tests/Repo.hs, dist/build/test-repository/test-repository-tmp/Main.o )
Linking dist/build/test-repository/test-repository ...
Preprocessing test suite 'test-unit' for hit-0.4.3...
[1 of 1] Compiling Main ( Tests/Tests.hs, dist/build/test-unit/test-unit-tmp/Main.o )
Linking dist/build/test-unit/test-unit ...
Running 2 test suites...
Test suite test-repository: RUNNING...
Test suite test-repository: PASS
Test suite logged to: dist/test/hit-0.4.3-test-repository.log
Test suite test-unit: RUNNING...
ref marshalling:
hexadecimal: [OK, passed 100 tests]
binary: [OK, passed 100 tests]
object marshalling:
unmarshall.marshall==id: [Failed]
*** Failed! (after 84 tests):
Exception:
not equal:
ObjCommit (Commit {commitTreeish = 869208302745e90bdf90a3b5f29445f9afec002b, commitParents = [e891e373941f57fe457bc01775ea0ba5adc04435,8a6c833dc48d98653098239b220614a481044f62], commitAuthor = Person {personName = "kc\\aol\DELHwNq\DELt|X^", personEmail = "_XMZNWwg`FoL]VQM", personTime = GitTime 32 600}, commitCommitter = Person {personName = "ghhLiapI\\xQkCX~G", personEmail = "jAho\\jBf}gt_IT`U", personTime = GitTime 33 600}, commitEncoding = Nothing, commitExtras = [CommitExtra {commitExtraKey = "aIG-eLS['W-2vFk6u5.dd_{1akldCIZvS(I@z!1JBsr0gHJQ$A+Uo*]Z>';P@PKu(C@ 47JDrNy]_P>z", commitExtraValue = "\b"},CommitExtra {commitExtraKey = "[83DWmE''{LP-~zsIY>_}|_Z0H#$..y*AqH'/boVXwu!B+7[L>]ys@HHBC0$;ozZti@y9>\\kkMkTS|=_", commitExtraValue = "\131"},CommitExtra {commitExtraKey = " #JOy}.DKdi=dI>H7iV6:B'_D|mosLIx*SY<pvzl]zf]i%BMsp>}(HlK(8GU/>|E9?+}@P@d4>Ie\DEL9\"\"", commitExtraValue = "\180"}], commitMessage = "\139"})
got: ObjCommit (Commit {commitTreeish = 869208302745e90bdf90a3b5f29445f9afec002b, commitParents = [e891e373941f57fe457bc01775ea0ba5adc04435,8a6c833dc48d98653098239b220614a481044f62], commitAuthor = Person {personName = "kc\\aol\DELHwNq\DELt|X^", personEmail = "_XMZNWwg`FoL]VQM", personTime = GitTime 32 600}, commitCommitter = Person {personName = "ghhLiapI\\xQkCX~G", personEmail = "jAho\\jBf}gt_IT`U", personTime = GitTime 33 600}, commitEncoding = Nothing, commitExtras = [CommitExtra {commitExtraKey = "aIG-eLS['W-2vFk6u5.dd_{1akldCIZvS(I@z!1JBsr0gHJQ$A+Uo*]Z>';P@PKu(C@ 47JDrNy]_P>z", commitExtraValue = "\b"},CommitExtra {commitExtraKey = "[83DWmE''{LP-~zsIY>_}|_Z0H#$..y*AqH'/boVXwu!B+7[L>]ys@HHBC0$;ozZti@y9>\\kkMkTS|=_", commitExtraValue = "\131\n#JOy}.DKdi=dI>H7iV6:B'_D|mosLIx*SY<pvzl]zf]i%BMsp>}(HlK(8GU/>|E9?+}@P@d4>Ie\DEL9\"\"\n\180"}], commitMessage = "\139"})
ObjCommit (Commit {commitTreeish = 869208302745e90bdf90a3b5f29445f9afec002b, commitParents = [e891e373941f57fe457bc01775ea0ba5adc04435,8a6c833dc48d98653098239b220614a481044f62], commitAuthor = Person {personName = "kc\\aol\DELHwNq\DELt|X^", personEmail = "_XMZNWwg`FoL]VQM", personTime = GitTime 32 600}, commitCommitter = Person {personName = "ghhLiapI\\xQkCX~G", personEmail = "jAho\\jBf}gt_IT`U", personTime = GitTime 33 600}, commitEncoding = Nothing, commitExtras = [CommitExtra {commitExtraKey = "aIG-eLS['W-2vFk6u5.dd_{1akldCIZvS(I@z!1JBsr0gHJQ$A+Uo*]Z>';P@PKu(C@ 47JDrNy]_P>z", commitExtraValue = "\b"},CommitExtra {commitExtraKey = "[83DWmE''{LP-~zsIY>_}|_Z0H#$..y*AqH'/boVXwu!B+7[L>]ys@HHBC0$;ozZti@y9>\\kkMkTS|=_", commitExtraValue = "\131"},CommitExtra {commitExtraKey = " #JOy}.DKdi=dI>H7iV6:B'_D|mosLIx*SY<pvzl]zf]i%BMsp>}(HlK(8GU/>|E9?+}@P@d4>Ie\DEL9\"\"", commitExtraValue = "\180"}], commitMessage = "\139"})
(used seed 7829374350396384261)
Properties Total
Passed 2 2
Failed 1 1
Total 3 3
Test suite test-unit: FAIL
Test suite logged to: dist/test/hit-0.4.3-test-unit.log
1 of 2 test suites (1 of 2 test cases) passed.
First off, solid work on this project. I'm really happy with the pure-Haskell, non-FFI implementation, and your Haskell is nicely abstracted. A+ work, seriously.
I need to write a patch to sign commits with GPG (like the -S
flag for git commit
). Would you like this work in a pull request? I'm going to see if I can avoid delegating to shell commands and instead use hOpenPGP, a Haskell implementation of the standard.
I'm going to do this work regardless, but if I know you're interested in my work, I'll make sure to keep it as clean and loosely-coupled as possible.
While it's obviously great to test against a real git repo, requiring it to be the same one as used to manage the library causes issues for some tooling (for example here). Perhaps a new repo could be created somewhere like /tmp
instead?
There appars to be a build issue with Hit.hs:
$ runhaskell Hit/Hit.hs
Data/Git/Storage/Object.hs:63:0:
error: missing binary operator before token "("
#if MIN_VERSION_bytestring(0,10,0)
^
phase `C pre-processor' failed (exitcode = 1)
Git requires trees on disk to be sorted by
https://github.com/git/git/blob/master/builtin/mktree.c#L34-L40
and
https://github.com/git/git/blob/bca181109d6f054d525c71a84963bbdc1f0c40bf/read-cache.c#L385-L402
Since GHC 7.4 ships with a version of bytestring in the 0.9 series, it can be problematic to depend on bytestring 0.10. Would it be possible to relax the lower bound on the bytestring dependency?
if your git repo uses pack-refs, hit can technically handle this. It makes it very round about and unclean though.
I believe the only function to directly handle both cases is resolveRevision. Said probes for what might work and I believe leads to an incomplete ability to resolve.
There exists no pseudo-inverse to branchWrite, and friends. This leaves you using readRefFile, and readPackedRefs. readRefFile uses exceptions to handle non-existence. At which point you have to fall back to readPackedRefs.
While nice to be able to process them separately, I think it would be a notable improvement to have one function that properly handles the combined case. Additionally I think branchRead, etc would be nice additions.
Whenever a gpg signature is present in a commit it is parsed and formatted in such a way that -----BEGIN PGP SIGNATURE-----
ends up being part of the commit extra key instead of value (and has to be part of the key, in case of formatting)
CommitExtra
{ commitExtraKey = "gpgsig -----BEGIN PGP SIGNATURE-----"
, commitExtraValue =
"Version: GnuPG v2\n\niQEcBAABCAAGBQJYArwUAAoJEA3rPXrzBY/5JB4IAJJUZsWuxKdMt/ssaG7+g2aK\nMmvnY07iksFyK6ma7eX0juyvLm86q0ewtMUgXQ4orBCgeX3iug51+67+GOgTBXoC\nA/4tN1bjsXJ59p5KQSVZ2AFqosRzzwIJM/1+dJFQtwVYc6qROs0sqleHHGEKhLfB\nxdY+hfzKwCzUqU/f/kTBeaxYspiOs297NhMeaiXlh9sfFHN/EJ0oLjJnrb4kDCxb\n25aL00DA5xAeC8Yd7qUu4RoO7bSYyYJcWM0Na53wcDkJVwnjnGNI2dAtpmeByPfu\nW126XrOw6+ROz+hsAw2ufgCTiFIi39f9yiHDTmIR3EpGVa8ZrcSjU3cULIRWQ/k=\n=7hLk\n-----END PGP SIGNATURE-----\n"
}
]
Other than that, it is formatted and parsed properly, namely, each line of a signature is getting prepended with a space character)
I'm seeing:
[13 of 17] Compiling Data.Git.Storage.FileWriter (
Data/Git/Storage/FileWriter.hs, dist/build/Data/Git/Storage/FileWriter.o )
Data/Git/Storage/FileWriter.hs:45:9:
Not in scope: modifyIORef'
Perhaps you meant `modifyIORef' (imported from Data.IORef)
Reported by @jwiegley on a Mac Stackage build, and reproduced on Linux with a cabal install hit --enable-tests
.
Running 2 test suites...
Test suite test-repository: RUNNING...
test-repository: not a git repository
Test suite test-repository: FAIL
Test suite logged to: dist/test/hit-0.4.1-test-repository.log
Test suite test-unit: RUNNING...
Test suite test-unit: PASS
Test suite logged to: dist/test/hit-0.4.1-test-unit.log
1 of 2 test suites (1 of 2 test cases) passed.
Does the below suffice?
blobMode, execMode, treeMode, submMode, linkMode :: ModePerm
blobMode = ModePerm 0o100644
execMode = ModePerm 0o100755
treeMode = ModePerm 0o040000
submMode = ModePerm 0o160000
linkMode = ModePerm 0o120000
getFileType :: ModePerm -> ObjectFileType
getFiletype perm | perm == blobMode = FileTypeRegularFile
| perm == execMode = FileTypeRegularFile
| perm == treeMode = FileTypeDirectory
| perm == linkMode = FileTypeSymbolicLink
| perm == submMode = FileTypeGitLink
| otherwise = error $ "don't file type for permission " ++ show perm
It would also be useful to export the {blob,exec,tree,subm,link}Mode
s
Steps to replicate:
$ cd /tmp
$ git clone https://github.com/vincenthz/hit
$ cd hit
$ git branch bugfix/branchList # note the forward-slash included *in* the branch name
$ cabal sandbox init
$ cabal install
$ cabal repl
λ: import Filesystem.Path.CurrentOS
λ: repo <- openRepo $ decodeString ".git"
λ: branchList repo
(^C or wait until execution is killed)
This can also be replicated by even deleting the branch, after the above, because the .git/refs/heads/bugfix
dir will still be around.
I've already drilled down and found the problem function:
Data/Git/Repository.hs#256:
ls <- Set.fromList <$>
looseHeadsList(gitRepoPath git)
Data/Git/Named.hs#170:
looseHeadsList gitRepo =
listRefs(headsPath gitRepo)
Data/Git/Named.h#151-167
-- | list all the loose refs available recursively from a directory starting point
listRefs :: FilePath -> IO [RefName]
listRefs root = listRefsAcc [] root
where listRefsAcc acc dir = do
files <- F.listDirectory dir
getRefsRecursively dir acc files
getRefsRecursively _ acc [] = return acc
getRefsRecursively dir acc (x:xs) = do
isDir <- F.isDirectory x
extra <- if isDir
then listRefsAcc [] dir
else let r = stripRoot x
in if isValidRefFilepath r
then return [fromString $ encodeString r]
else return []
getRefsRecursively dir (extra ++ acc) xs
stripRoot p = maybe (error "stripRoot invalid") id $ stripPrefix root p
Version 0.6.3 of hit introduces new types (EntName) and changes the type signature of functions in a non-comparable way. This breaks dependent packages with policy-based version bounds.
There exists no inputs for which it satisfies its type signature.
Simply deleting it until it is actually implemented would save people some debugging time.
Hi,
I'd like to use the Hit library on windows, would it be possible to remove the dependency on the Unix package?
Thanks
It is unclear from documentation how to resolve RefName
(returned by for example tagList) and Revision
(accepted by most functions and acceptable to convert to Ref
). I come up with fromString . refNameRaw
but that doesn't return any errors etc. The difference between Ref
, Revision
and RefName
are also not clearly documented.
Configuring hit-0.6.0...
Flags chosen: debug=False, executable=False
Dependency attoparsec ==0.11.3.4: using attoparsec-0.11.3.4
Dependency base ==4.7.0.0: using base-4.7.0.0
Dependency bytestring ==0.10.4.0: using bytestring-0.10.4.0
Dependency containers ==0.5.5.1: using containers-0.5.5.1
Dependency cryptohash ==0.11.5: using cryptohash-0.11.5
Dependency hourglass ==0.2.0: using hourglass-0.2.0
Dependency mtl ==2.1.3.1: using mtl-2.1.3.1
Dependency parsec ==3.1.5: using parsec-3.1.5
Dependency patience ==0.1.1: using patience-0.1.1
Dependency random ==1.0.1.1: using random-1.0.1.1
Dependency system-fileio ==0.3.14: using system-fileio-0.3.14
Dependency system-filepath ==0.4.12: using system-filepath-0.4.12
Dependency unix ==2.7.0.1: using unix-2.7.0.1
Dependency vector ==0.10.10.0: using vector-0.10.10.0
Dependency zlib ==0.5.4.1: using zlib-0.5.4.1
Dependency zlib-bindings ==0.1.1.5: using zlib-bindings-0.1.1.5
Using Cabal-1.20.0.0 compiled by ghc-7.8
Using compiler: ghc-7.8.2
Using install prefix: /var/lib/jenkins/.cabal
Binaries installed in:
/var/lib/jenkins/workspace/Stackage/ghcversion/7.8.2/stackage/sandbox/bin
Libraries installed in:
/var/lib/jenkins/workspace/Stackage/ghcversion/7.8.2/stackage/sandbox/lib/x86_64-linux-ghc-7.8.2/hit-0.6.0
Private binaries installed in: /var/lib/jenkins/.cabal/libexec
Data files installed in:
/var/lib/jenkins/workspace/Stackage/ghcversion/7.8.2/stackage/sandbox/share/x86_64-linux-ghc-7.8.2/hit-0.6.0
Documentation installed in:
/var/lib/jenkins/workspace/Stackage/ghcversion/7.8.2/stackage/sandbox/share/doc/hit-0.6.0
Configuration files installed in: /var/lib/jenkins/.cabal/etc
Using alex version 3.1.3 found on system at:
/var/lib/jenkins/workspace/Stackage/ghcversion/7.8.2/stackage/sandbox/bin/alex
Using ar found on system at: /usr/bin/ar
No c2hs found
Using cpphs version 1.18.4 found on system at:
/var/lib/jenkins/workspace/Stackage/ghcversion/7.8.2/stackage/sandbox/bin/cpphs
No ffihugs found
Using gcc version 4.8 found on system at: /usr/bin/gcc
Using ghc version 7.8.2 found on system at: /opt/ghc/7.8.2/bin/ghc
Using ghc-pkg version 7.8.2 found on system at: /opt/ghc/7.8.2/bin/ghc-pkg
No greencard found
Using haddock version 2.14.2 found on system at: /opt/ghc/7.8.2/bin/haddock
Using happy version 1.19.3 found on system at:
/var/lib/jenkins/workspace/Stackage/ghcversion/7.8.2/stackage/sandbox/bin/happy
Using haskell-suite found on system at: haskell-suite-dummy-location
Using haskell-suite-pkg found on system at: haskell-suite-pkg-dummy-location
No hmake found
Using hpc version 0.67 found on system at: /opt/ghc/7.8.2/bin/hpc
Using hsc2hs version 0.67 found on system at: /opt/ghc/7.8.2/bin/hsc2hs
Using hscolour version 1.20 found on system at:
/var/lib/jenkins/workspace/Stackage/ghcversion/7.8.2/stackage/sandbox/bin/HsColour
No hugs found
No jhc found
Using ld found on system at: /usr/bin/ld
No lhc found
No lhc-pkg found
No nhc98 found
Using pkg-config version 0.26 found on system at: /usr/bin/pkg-config
Using strip found on system at: /usr/bin/strip
Using tar found on system at: /bin/tar
No uhc found
Component build order: library
creating dist/build
creating dist/build/autogen
Building hit-0.6.0...
Preprocessing library hit-0.6.0...
Building library...
creating dist/build
/opt/ghc/7.8.2/bin/ghc --make -fbuilding-cabal-package -O -static -dynamic-too -dynosuf dyn_o -dynhisuf dyn_hi -outputdir dist/build -odir dist/build -hidir dist/build -stubdir dist/build -i -idist/build -i. -idist/build/autogen -Idist/build/autogen -Idist/build -optP-include -optPdist/build/autogen/cabal_macros.h -package-name hit-0.6.0 -hide-all-packages -no-user-package-db -package-db /var/lib/jenkins/workspace/Stackage/ghcversion/7.8.2/stackage/sandbox/package-db -package-db dist/package.conf.inplace -package-id attoparsec-0.11.3.4-fff97c604c2797a595f60a55fd804ae8 -package-id base-4.7.0.0-018311399e3b6350d5be3a16b144df9b -package-id bytestring-0.10.4.0-7de5230c6d895786641a4de344336838 -package-id containers-0.5.5.1-19036437a266c66c860794334111ee93 -package-id cryptohash-0.11.5-9ac9f22de3d8155ca5cabc50d6d0f15b -package-id hourglass-0.2.0-434f363174a8f50db6e884f8d5edcb6d -package-id mtl-2.1.3.1-89ed04036fb57647047a12ac69cffae6 -package-id parsec-3.1.5-63f9ebe822dcccf7dfa67bacbd4289df -package-id patience-0.1.1-3541f03281699edc49b2ebbb23559f86 -package-id random-1.0.1.1-6ee738046e61b4cfbe8ae4a5ddcd83ac -package-id system-fileio-0.3.14-0a75f9404c7d78b467547bca9f0804a7 -package-id system-filepath-0.4.12-bfb948e5dfa1464e05c4fe1877d58ad5 -package-id unix-2.7.0.1-23f79f72106a0fbca2437feb33a4e846 -package-id vector-0.10.10.0-22ca6b1b15aa387862648602a0b7d89c -package-id zlib-0.5.4.1-28f4afec94c21c1745f93b2774aac5ad -package-id zlib-bindings-0.1.1.5-6fdfa5199bb38c5c56765b2e6ee5a095 -XHaskell98 Data.Git Data.Git.Types Data.Git.Storage Data.Git.Storage.PackIndex Data.Git.Storage.Pack Data.Git.Storage.Object Data.Git.Storage.Loose Data.Git.Named Data.Git.Delta Data.Git.Ref Data.Git.Revision Data.Git.Repository Data.Git.Diff Data.Git.Internal Data.Git.Config Data.Git.Storage.FileReader Data.Git.Storage.FileWriter Data.Git.Storage.CacheFile Data.Git.Path -Wall -fno-warn-missing-signatures
[ 1 of 19] Compiling Data.Git.Internal ( Data/Git/Internal.hs, dist/build/Data/Git/Internal.o )
[ 2 of 19] Compiling Data.Git.Storage.CacheFile ( Data/Git/Storage/CacheFile.hs, dist/build/Data/Git/Storage/CacheFile.o )
[ 3 of 19] Compiling Data.Git.Storage.FileReader ( Data/Git/Storage/FileReader.hs, dist/build/Data/Git/Storage/FileReader.o )
[ 4 of 19] Compiling Data.Git.Delta ( Data/Git/Delta.hs, dist/build/Data/Git/Delta.o )
[ 5 of 19] Compiling Data.Git.Revision ( Data/Git/Revision.hs, dist/build/Data/Git/Revision.o )
[ 6 of 19] Compiling Data.Git.Ref ( Data/Git/Ref.hs, dist/build/Data/Git/Ref.o )
[ 7 of 19] Compiling Data.Git.Types ( Data/Git/Types.hs, dist/build/Data/Git/Types.o )
Data/Git/Types.hs:63:5: Not in scope: data constructor ‘LocalTime’
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.