File: lfs.go

package info (click to toggle)
gitlab-shell 14.35.0%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 23,652 kB
  • sloc: ruby: 1,129; makefile: 583; sql: 391; sh: 384
file content (34 lines) | stat: -rw-r--r-- 767 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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.
// TODO: this is incomplete as it does not recognize pre-release version of LFS blobs with
// the "https://hawser.github.com/spec/v1" version. For compatibility with the Ruby RPC, we
// leave this as-is for now though.
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
}