diff options
-rw-r--r-- | cmd.go | 2 | ||||
-rw-r--r-- | cmd_command.go | 43 |
2 files changed, 44 insertions, 1 deletions
@@ -27,7 +27,7 @@ // A program can read commands from a frontend by wrapping the // appropriate io.Reader with a Frontend object. // -// This is up-to-date with full syntax supported by git v2.23.0. +// This is up-to-date with full syntax supported by git v2.24.0. package libfastimport type fiReader interface { diff --git a/cmd_command.go b/cmd_command.go index 9249e75..700e47d 100644 --- a/cmd_command.go +++ b/cmd_command.go @@ -305,6 +305,49 @@ func (CmdBlob) fiCmdRead(fir fiReader) (cmd Cmd, err error) { return } +// alias /////////////////////////////////////////////////////////////////////// + +// CmdAlias requests that the Backend record that a merk refers to a +// given object without first creating any new object. +type CmdAlias struct { + Mark int + CommitIsh string +} + +func (c CmdAlias) fiCmdClass() cmdClass { return cmdClassCommand } +func (c CmdAlias) fiCmdWrite(fiw fiWriter) error { + ez := &ezfiw{fiw: fiw} + ez.WriteLine("alias") + ez.WriteMark(c.Mark) + ez.WriteLine("to", c.CommitIsh) + return ez.err +} +func init() { parser_registerCmd("alias\n", CmdCheckpoint{}) } +func (CmdAlias) fiCmdRead(fir fiReader) (cmd Cmd, err error) { + ez := &ezfir{fir: fir} + defer func() { err = ez.Defer() }() + + // 'alias' LF + _ = ez.ReadLine() + c := CmdAlias{} + + // mark + if !strings.HasPrefix(ez.PeekLine(), "mark :") { + ez.Errcheck(errors.Errorf("alias: expected mark command: %v", ez.ReadLine())) + } + c.Mark, err = strconv.Atoi(trimLinePrefix(ez.ReadLine(), "mark :")) + ez.Errcheck(err) + + // 'to' SP <commit-ish LF + if !strings.HasPrefix(ez.PeekLine(), "to ") { + ez.Errcheck(errors.Errorf("alias: expected to command: %v", ez.ReadLine())) + } + c.CommitIsh = trimLinePrefix(ez.ReadLine(), "to ") + + cmd = c + return +} + // checkpoint ////////////////////////////////////////////////////////////////// // CmdCheckpoint requests that the Backend flush already-sent data. |