This repository was archived by the owner on Sep 11, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 534
server: add git server implementation #190
Merged
Merged
Changes from 13 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
84ab49b
server: add git server implementation.
smola 64e4b34
add storer.Storer interface.
smola 6d68b52
server: move internal functions to internal/common.
smola 2050ad9
server: clarify TODOs.
smola 386cd18
server: move code to functions.
smola 8a967a7
requested changes
smola 640233f
server: move repo loading code to server.Loader.
smola 4e0406d
capability: implement All.
smola 59a993a
add cli
smola bde1e3e
packp: add UploadPackResponse constructor with packfile.
smola 8a00430
changes
smola dc30b0a
fix UploadPackResponse encoding, add tests.
smola 231e386
implement tranport RPC-like
smola 03438c5
requested changes
smola File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/jessevdk/go-flags" | ||
) | ||
|
||
const ( | ||
bin = "go-git" | ||
receivePackBin = "git-receive-pack" | ||
uploadPackBin = "git-upload-pack" | ||
) | ||
|
||
func main() { | ||
switch filepath.Base(os.Args[0]) { | ||
case receivePackBin: | ||
os.Args = append([]string{"git", "receive-pack"}, os.Args[1:]...) | ||
case uploadPackBin: | ||
os.Args = append([]string{"git", "upload-pack"}, os.Args[1:]...) | ||
} | ||
|
||
parser := flags.NewNamedParser(bin, flags.Default) | ||
parser.AddCommand("receive-pack", "", "", &CmdReceivePack{}) | ||
parser.AddCommand("upload-pack", "", "", &CmdUploadPack{}) | ||
parser.AddCommand("version", "Show the version information.", "", &CmdVersion{}) | ||
|
||
_, err := parser.Parse() | ||
if err != nil { | ||
if e, ok := err.(*flags.Error); ok && e.Type == flags.ErrCommandRequired { | ||
parser.WriteHelp(os.Stdout) | ||
} | ||
|
||
os.Exit(1) | ||
} | ||
} | ||
|
||
type cmd struct { | ||
Verbose bool `short:"v" description:"Activates the verbose mode"` | ||
} | ||
|
||
func (c *cmd) print(format string, a ...interface{}) { | ||
if !c.Verbose { | ||
return | ||
} | ||
|
||
fmt.Printf(format, a...) | ||
} | ||
|
||
func resolvePath(path string) (string, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this can be done calling There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
if filepath.IsAbs(path) { | ||
return path, nil | ||
} | ||
|
||
wd, err := os.Getwd() | ||
if err != nil { | ||
return path, err | ||
} | ||
|
||
return filepath.Join(wd, path), nil | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"gopkg.in/src-d/go-git.v4/plumbing/transport/file" | ||
) | ||
|
||
type CmdReceivePack struct { | ||
cmd | ||
|
||
Args struct { | ||
GitDir string `positional-arg-name:"git-dir" required:"true"` | ||
} `positional-args:"yes"` | ||
} | ||
|
||
func (CmdReceivePack) Usage() string { | ||
//TODO: git-receive-pack returns error code 129 if arguments are invalid. | ||
return fmt.Sprintf("usage: %s <git-dir>", os.Args[0]) | ||
} | ||
|
||
func (c *CmdReceivePack) Execute(args []string) error { | ||
gitDir, err := resolvePath(c.Args.GitDir) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if err := file.ServeReceivePack(gitDir); err != nil { | ||
fmt.Fprintln(os.Stderr, "ERR:", err) | ||
os.Exit(128) | ||
} | ||
|
||
return nil | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"gopkg.in/src-d/go-git.v4/plumbing/transport/file" | ||
) | ||
|
||
//TODO: usage: git upload-pack [--strict] [--timeout=<n>] <dir> | ||
type CmdUploadPack struct { | ||
cmd | ||
|
||
Args struct { | ||
GitDir string `positional-arg-name:"git-dir" required:"true"` | ||
} `positional-args:"yes"` | ||
} | ||
|
||
func (CmdUploadPack) Usage() string { | ||
//TODO: git-upload-pack returns error code 129 if arguments are invalid. | ||
return fmt.Sprintf("usage: %s <git-dir>", os.Args[0]) | ||
} | ||
|
||
func (c *CmdUploadPack) Execute(args []string) error { | ||
gitDir, err := resolvePath(c.Args.GitDir) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if err := file.ServeUploadPack(gitDir); err != nil { | ||
fmt.Fprintln(os.Stderr, "ERR:", err) | ||
os.Exit(128) | ||
} | ||
|
||
return nil | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package main | ||
|
||
import "fmt" | ||
|
||
var version string | ||
var build string | ||
|
||
type CmdVersion struct{} | ||
|
||
func (c *CmdVersion) Execute(args []string) error { | ||
fmt.Printf("%s (%s) - build %s\n", bin, version, build) | ||
|
||
return nil | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this dead code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. Removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍