aboutsummaryrefslogtreecommitdiffstats
path: root/config/branch.go
diff options
context:
space:
mode:
authormerlin <clamores.pro@gmail.com>2021-11-08 00:33:17 +0300
committermerlin <clamores.pro@gmail.com>2021-11-08 00:50:26 +0300
commitefc74e7730b7cfd72ae66602815e6acd67b2c01a (patch)
tree6071d53bd35aaed393b5756ef270fb748ad66494 /config/branch.go
parente0567bda08fcee09a2c24010d63c10d5f933faad (diff)
downloadgo-git-efc74e7730b7cfd72ae66602815e6acd67b2c01a.tar.gz
config: describe reason for custom quote functions
Diffstat (limited to 'config/branch.go')
-rw-r--r--config/branch.go10
1 files changed, 10 insertions, 0 deletions
diff --git a/config/branch.go b/config/branch.go
index a8fe0b5..652270a 100644
--- a/config/branch.go
+++ b/config/branch.go
@@ -92,6 +92,13 @@ func (b *Branch) marshal() *format.Subsection {
return b.raw
}
+// hack to trigger conditional quoting in the
+// plumbing/format/config/Encoder.encodeOptions
+//
+// Current Encoder implementation uses Go %q format if value contains a backslash character,
+// which is not consistent with reference git implementation.
+// git just replaces newline characters with \n, while Encoder prints them directly.
+// Until value quoting fix, we should escape description value by replacing newline characters with \n.
func quoteDescription(desc string) string {
return strings.ReplaceAll(desc, "\n", `\n`)
}
@@ -108,6 +115,9 @@ func (b *Branch) unmarshal(s *format.Subsection) error {
return b.Validate()
}
+// hack to enable conditional quoting in the
+// plumbing/format/config/Encoder.encodeOptions
+// goto quoteDescription for details.
func unquoteDescription(desc string) string {
return strings.ReplaceAll(desc, `\n`, "\n")
}