diff options
author | John Cai <jcai@gitlab.com> | 2019-08-10 18:04:32 +0300 |
---|---|---|
committer | John Cai <jcai@gitlab.com> | 2019-08-20 22:04:19 +0300 |
commit | 247a96f5b82c461e534f5a0ea1fe61f18a881617 (patch) | |
tree | f20bc39175bc7e9fcf85aecdfe50dafd53464e7b /internal/git | |
parent | 2ca0b52a78b3b48dc51c3992a0b23367bab81f27 (diff) |
Port GetAllLFSPointers to go
Diffstat (limited to 'internal/git')
-rw-r--r-- | internal/git/catfile/objectinfo.go | 3 | ||||
-rw-r--r-- | internal/git/lfs.go | 31 |
2 files changed, 34 insertions, 0 deletions
diff --git a/internal/git/catfile/objectinfo.go b/internal/git/catfile/objectinfo.go index 7f7af80a5..de296287d 100644 --- a/internal/git/catfile/objectinfo.go +++ b/internal/git/catfile/objectinfo.go @@ -28,6 +28,9 @@ func (o *ObjectInfo) IsBlob() bool { return o.Type == "blob" } +// ParseObjectInfo reads from a reader and parses the data into an ObjectInfo struct +var ParseObjectInfo = parseObjectInfo + func parseObjectInfo(stdout *bufio.Reader) (*ObjectInfo, error) { infoLine, err := stdout.ReadString('\n') if err != nil { diff --git a/internal/git/lfs.go b/internal/git/lfs.go new file mode 100644 index 000000000..78f3aadd9 --- /dev/null +++ b/internal/git/lfs.go @@ -0,0 +1,31 @@ +package git + +import ( + "bytes" + "regexp" +) + +var ( + lfsOIDRe = regexp.MustCompile(`(?m)^oid sha256:[0-9a-f]{64}$`) + lfsSizeRe = regexp.MustCompile(`(?m)^size [0-9]+$`) +) + +// IsLFSPointer checks to see if a blob is an LFS pointer. It returns the raw data of the pointer if it is +func IsLFSPointer(b []byte) bool { + // ensure the version exists + if !bytes.HasPrefix(b, []byte("version https://git-lfs.github.com/spec")) { + return false + } + + // ensure the oid exists + if !lfsOIDRe.Match(b) { + return false + } + + // ensure the size exists + if !lfsSizeRe.Match(b) { + return false + } + + return true +} |