Skip to content

Commit

Permalink
kbfsgit: support the lfs init command, and start in LFS mode
Browse files Browse the repository at this point in the history
If the arguments to the `git-remote-keybase` process are something
like "lfs origin keybase://type/name/repo".

Issue: HOTPOT-1273
  • Loading branch information
strib committed Nov 14, 2019
1 parent c902399 commit 56f7476
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 10 deletions.
12 changes: 8 additions & 4 deletions go/kbfs/kbfsgit/git-remote-keybase/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,17 @@ func start() (startErr *libfs.Error) {

remote := flag.Arg(0)
var repo string
lfs := false
if len(flag.Args()) > 1 {
repo = flag.Arg(1)
} else {
// For LFS invocation, the arguments actually come together in
// a single quoted argument for some reason.
s := strings.Split(remote, " ")
if len(s) > 1 {
remote = s[0]
repo = s[1]
if len(s) > 2 {
lfs = s[0] == "lfs"
remote = s[1]
repo = s[2]
}
}

Expand All @@ -146,11 +148,13 @@ func start() (startErr *libfs.Error) {
Remote: remote,
Repo: repo,
GitDir: getLocalGitDir(),
LFS: lfs,
}

ctx := context.Background()
return kbfsgit.Start(
ctx, options, kbCtx, defaultLogPath, os.Stdin, os.Stdout, stderrFile)
ctx, options, kbCtx, defaultLogPath, os.Stdin, os.Stdout,
stderrFile)
}

func main() {
Expand Down
21 changes: 17 additions & 4 deletions go/kbfs/kbfsgit/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const (
gitOptionPushcert = "pushcert"
gitOptionIfAsked = "if-asked"

gitLFSInitEvent = "init"
gitLFSUploadEvent = "upload"
gitLFSCompleteEvent = "complete"
gitLFSTerminateEvent = "terminate"
Expand Down Expand Up @@ -2048,10 +2049,12 @@ type lfsError struct {
}

type lfsRequest struct {
Event string `json:"event"`
Oid string `json:"oid"`
Size int `json:"size,omitempty"`
Path string `json:"path,omitempty"`
Event string `json:"event"`
Oid string `json:"oid"`
Size int `json:"size,omitempty"`
Path string `json:"path,omitempty"`
Operation string `json:"operation,omitempty"`
Remote string `json:"remote,omitempty"`
}

type lfsResponse struct {
Expand All @@ -2062,6 +2065,7 @@ type lfsResponse struct {

func (r *runner) processCommandLFS(
ctx context.Context, commandChan <-chan string) (err error) {
lfsLoop:
for {
select {
case cmd := <-commandChan:
Expand All @@ -2079,6 +2083,15 @@ func (r *runner) processCommandLFS(
Oid: req.Oid,
}
switch req.Event {
case gitLFSInitEvent:
r.log.CDebugf(
ctx, "Initialize message, operation=%s, remote=%s",
req.Operation, req.Remote)
_, err := r.output.Write([]byte("{}\n"))
if err != nil {
return err
}
continue lfsLoop
case gitLFSUploadEvent:
r.log.CDebugf(ctx, "Handling upload, oid=%s", req.Oid)
err := r.handleLFSUpload(ctx, req.Oid, req.Path)
Expand Down
11 changes: 9 additions & 2 deletions go/kbfs/kbfsgit/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ type StartOptions struct {
// GitDir is the filepath leading to the .git directory of the
// caller's local on-disk repo.
GitDir string
// LFS indicates whether we should listen for LFS commands instead
// of normal git commands.
LFS bool
}

// Start starts the kbfsgit logic, and begins listening for git
Expand Down Expand Up @@ -61,9 +64,13 @@ func Start(ctx context.Context, options StartOptions,
return libfs.InitError(err.Error())
}

r, err := newRunner(
t := processGit
if options.LFS {
t = processLFS
}
r, err := newRunnerWithType(
ctx, config, options.Remote, options.Repo, options.GitDir,
input, output, errput)
input, output, errput, t)
if err != nil {
return libfs.InitError(err.Error())
}
Expand Down

0 comments on commit 56f7476

Please sign in to comment.