From 225a3064a9b683586862a65e5663dee059172b4a Mon Sep 17 00:00:00 2001 From: Taylor Blau Date: Thu, 24 Aug 2017 18:19:17 -0400 Subject: [PATCH 1/2] git: introduce type 'FilterProcessStatus' --- git/filter_process_status.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 git/filter_process_status.go diff --git a/git/filter_process_status.go b/git/filter_process_status.go new file mode 100644 index 00000000..2735bd7b --- /dev/null +++ b/git/filter_process_status.go @@ -0,0 +1,33 @@ +package git + +import "fmt" + +// FilterProcessStatus is a constant type representing the various valid +// responses for `status=` in the Git filtering process protocol. +type FilterProcessStatus uint8 + +const ( + // StatusSuccess is a valid response when a successful event has + // occurred. + StatusSuccess FilterProcessStatus = iota + 1 + // StatusDelay is a valid response when a delay has occurred. + StatusDelay + // StatusError is a valid response when an error has occurred. + StatusError +) + +// String implements fmt.Stringer by returning a protocol-compliant +// representation of the receiving status, or panic()-ing if the Status is +// unknown. +func (s FilterProcessStatus) String() string { + switch s { + case StatusSuccess: + return "success" + case StatusDelay: + return "delayed" + case StatusError: + return "error" + } + + panic(fmt.Sprintf("git: unknown FilterProcessStatus '%d'", s)) +} From 0e9afa7732ee68ac7f32604fa694767255ed34d6 Mon Sep 17 00:00:00 2001 From: Taylor Blau Date: Thu, 24 Aug 2017 18:19:26 -0400 Subject: [PATCH 2/2] commands,git: make 'WriteStatus' accept a 'FilterProcessStatus' --- commands/command_filter_process.go | 14 +++++++------- git/filter_process_scanner.go | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/commands/command_filter_process.go b/commands/command_filter_process.go index d73f415a..e2659c1a 100644 --- a/commands/command_filter_process.go +++ b/commands/command_filter_process.go @@ -165,7 +165,7 @@ func filterCommand(cmd *cobra.Command, args []string) { malformedOnWindows = append(malformedOnWindows, req.Header["pathname"]) } - var status string + var status git.FilterProcessStatus if delayed { // If delayed, there is no need to call w.Flush() since // no data was written. Calculate the status from the @@ -341,22 +341,22 @@ func pathnames(ts []*tq.Transfer) []string { // statusFromErr returns the status code that should be sent over the filter // protocol based on a given error, "err". -func statusFromErr(err error) string { +func statusFromErr(err error) git.FilterProcessStatus { if err != nil && err != io.EOF { - return "error" + return git.StatusError } - return "success" + return git.StatusSuccess } // delayedStatusFromErr returns the status code that should be sent over the // filter protocol based on a given error, "err" when the blob smudge operation // was delayed. -func delayedStatusFromErr(err error) string { +func delayedStatusFromErr(err error) git.FilterProcessStatus { status := statusFromErr(err) switch status { - case "success": - return "delayed" + case git.StatusSuccess: + return git.StatusDelay default: return status } diff --git a/git/filter_process_scanner.go b/git/filter_process_scanner.go index be0bdb8f..f56059a3 100644 --- a/git/filter_process_scanner.go +++ b/git/filter_process_scanner.go @@ -198,8 +198,8 @@ func (o *FilterProcessScanner) WriteList(list []string) error { return o.pl.writePacketList(list) } -func (o *FilterProcessScanner) WriteStatus(status string) error { - return o.pl.writePacketList([]string{"status=" + status}) +func (o *FilterProcessScanner) WriteStatus(status FilterProcessStatus) error { + return o.pl.writePacketList([]string{"status=" + status.String()}) } // isStringInSlice returns whether a given string "what" is contained in a