Skip to content

Commit 020cd6a

Browse files
authored
Merge pull request #3 from cockroachdb/add_snappy
add snapshot
2 parents 977a579 + 06853a5 commit 020cd6a

File tree

4 files changed

+106
-6
lines changed

4 files changed

+106
-6
lines changed
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
From c11283e6d2342e0801ace7d1a8badbfe63ee71a4 Mon Sep 17 00:00:00 2001
2+
From: Oliver Tan <otan@cockroachlabs.com>
3+
Date: Thu, 3 Nov 2022 15:05:20 +1100
4+
Subject: [PATCH] add extra pretty option for no new lines
5+
6+
---
7+
pkg/sql/sem/tree/pretty.go | 8 +++++---
8+
pkg/util/pretty/util.go | 9 ++++++---
9+
2 files changed, 11 insertions(+), 6 deletions(-)
10+
11+
diff --git a/pkg/sql/sem/tree/pretty.go b/pkg/sql/sem/tree/pretty.go
12+
index 6df5efe..5e3715f 100644
13+
--- a/pkg/sql/sem/tree/pretty.go
14+
+++ b/pkg/sql/sem/tree/pretty.go
15+
@@ -47,6 +47,8 @@ type PrettyCfg struct {
16+
// TabWidth is the amount of spaces to use for tabs when UseTabs is
17+
// false.
18+
TabWidth int
19+
+ // DoNotNewLineAfterColName is true if we do not new line after table column names.
20+
+ DoNotNewLineAfterColName bool
21+
// Align, when set to another value than PrettyNoAlign, uses
22+
// alignment for some constructs as a first choice. If not set or if
23+
// the line width is insufficient, nesting is used instead.
24+
@@ -195,7 +197,7 @@ func (p *PrettyCfg) rlTable(rows ...pretty.TableRow) pretty.Doc {
25+
if p.Align != PrettyNoAlign {
26+
alignment = pretty.TableRightAlignFirstColumn
27+
}
28+
- return pretty.Table(alignment, pretty.Keyword, rows...)
29+
+ return pretty.Table(alignment, pretty.Keyword, p.DoNotNewLineAfterColName, rows...)
30+
}
31+
32+
// llTable produces a Table using Left alignment of the first column.
33+
@@ -204,7 +206,7 @@ func (p *PrettyCfg) llTable(docFn func(string) pretty.Doc, rows ...pretty.TableR
34+
if p.Align != PrettyNoAlign {
35+
alignment = pretty.TableLeftAlignFirstColumn
36+
}
37+
- return pretty.Table(alignment, docFn, rows...)
38+
+ return pretty.Table(alignment, docFn, p.DoNotNewLineAfterColName, rows...)
39+
}
40+
41+
func (p *PrettyCfg) row(lbl string, d pretty.Doc) pretty.TableRow {
42+
@@ -242,7 +244,7 @@ func (p *PrettyCfg) joinNestedOuter(lbl string, d ...pretty.Doc) pretty.Doc {
43+
}
44+
items[i].Doc = dd
45+
}
46+
- return pretty.Table(pretty.TableRightAlignFirstColumn, pretty.Keyword, items...)
47+
+ return pretty.Table(pretty.TableRightAlignFirstColumn, pretty.Keyword, p.DoNotNewLineAfterColName, items...)
48+
default:
49+
return pretty.JoinNestedRight(pretty.Keyword(lbl), d...)
50+
}
51+
diff --git a/pkg/util/pretty/util.go b/pkg/util/pretty/util.go
52+
index 568461a..b754eb8 100644
53+
--- a/pkg/util/pretty/util.go
54+
+++ b/pkg/util/pretty/util.go
55+
@@ -238,11 +238,11 @@ const (
56+
//
57+
// docFn should be set to Text or Keyword and will be used when converting
58+
// TableRow label's to Docs.
59+
-func Table(alignment TableAlignment, docFn func(string) Doc, rows ...TableRow) Doc {
60+
+func Table(alignment TableAlignment, docFn func(string) Doc, noNewLine bool, rows ...TableRow) Doc {
61+
// Compute the nested formatting in "sections". It's simple.
62+
// Note that we do not use NestUnder() because we are not grouping
63+
// at this level (the group is done for the final form below).
64+
- items := makeTableNestedSections(docFn, rows)
65+
+ items := makeTableNestedSections(docFn, rows, noNewLine)
66+
nestedSections := Stack(items...)
67+
68+
finalDoc := nestedSections
69+
@@ -300,7 +300,7 @@ func makeAlignedTableItems(
70+
return items
71+
}
72+
73+
-func makeTableNestedSections(docFn func(string) Doc, rows []TableRow) []Doc {
74+
+func makeTableNestedSections(docFn func(string) Doc, rows []TableRow, noNewLine bool) []Doc {
75+
items := make([]Doc, 0, len(rows))
76+
for _, r := range rows {
77+
if r.Doc == nil || (r.Label == "" && r.Doc == Nil) {
78+
@@ -309,6 +309,9 @@ func makeTableNestedSections(docFn func(string) Doc, rows []TableRow) []Doc {
79+
if r.Label != "" {
80+
d := simplifyNil(docFn(r.Label), r.Doc,
81+
func(a, b Doc) Doc {
82+
+ if noNewLine {
83+
+ return ConcatSpace(a, b)
84+
+ }
85+
return Concat(a, NestT(Concat(Line, Group(b))))
86+
})
87+
items = append(items, d)
88+
--
89+
2.37.1 (Apple Git-137.1)
90+

pkg/sql/sem/tree/pretty.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ type PrettyCfg struct {
4747
// TabWidth is the amount of spaces to use for tabs when UseTabs is
4848
// false.
4949
TabWidth int
50+
// DoNotNewLineAfterColName is true if we do not new line after table column names.
51+
DoNotNewLineAfterColName bool
5052
// Align, when set to another value than PrettyNoAlign, uses
5153
// alignment for some constructs as a first choice. If not set or if
5254
// the line width is insufficient, nesting is used instead.
@@ -195,7 +197,7 @@ func (p *PrettyCfg) rlTable(rows ...pretty.TableRow) pretty.Doc {
195197
if p.Align != PrettyNoAlign {
196198
alignment = pretty.TableRightAlignFirstColumn
197199
}
198-
return pretty.Table(alignment, pretty.Keyword, rows...)
200+
return pretty.Table(alignment, pretty.Keyword, p.DoNotNewLineAfterColName, rows...)
199201
}
200202

201203
// llTable produces a Table using Left alignment of the first column.
@@ -204,7 +206,7 @@ func (p *PrettyCfg) llTable(docFn func(string) pretty.Doc, rows ...pretty.TableR
204206
if p.Align != PrettyNoAlign {
205207
alignment = pretty.TableLeftAlignFirstColumn
206208
}
207-
return pretty.Table(alignment, docFn, rows...)
209+
return pretty.Table(alignment, docFn, p.DoNotNewLineAfterColName, rows...)
208210
}
209211

210212
func (p *PrettyCfg) row(lbl string, d pretty.Doc) pretty.TableRow {
@@ -242,7 +244,7 @@ func (p *PrettyCfg) joinNestedOuter(lbl string, d ...pretty.Doc) pretty.Doc {
242244
}
243245
items[i].Doc = dd
244246
}
245-
return pretty.Table(pretty.TableRightAlignFirstColumn, pretty.Keyword, items...)
247+
return pretty.Table(pretty.TableRightAlignFirstColumn, pretty.Keyword, p.DoNotNewLineAfterColName, items...)
246248
default:
247249
return pretty.JoinNestedRight(pretty.Keyword(lbl), d...)
248250
}

pkg/util/pretty/util.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,11 +238,11 @@ const (
238238
//
239239
// docFn should be set to Text or Keyword and will be used when converting
240240
// TableRow label's to Docs.
241-
func Table(alignment TableAlignment, docFn func(string) Doc, rows ...TableRow) Doc {
241+
func Table(alignment TableAlignment, docFn func(string) Doc, noNewLine bool, rows ...TableRow) Doc {
242242
// Compute the nested formatting in "sections". It's simple.
243243
// Note that we do not use NestUnder() because we are not grouping
244244
// at this level (the group is done for the final form below).
245-
items := makeTableNestedSections(docFn, rows)
245+
items := makeTableNestedSections(docFn, rows, noNewLine)
246246
nestedSections := Stack(items...)
247247

248248
finalDoc := nestedSections
@@ -300,7 +300,7 @@ func makeAlignedTableItems(
300300
return items
301301
}
302302

303-
func makeTableNestedSections(docFn func(string) Doc, rows []TableRow) []Doc {
303+
func makeTableNestedSections(docFn func(string) Doc, rows []TableRow, noNewLine bool) []Doc {
304304
items := make([]Doc, 0, len(rows))
305305
for _, r := range rows {
306306
if r.Doc == nil || (r.Label == "" && r.Doc == Nil) {
@@ -309,6 +309,9 @@ func makeTableNestedSections(docFn func(string) Doc, rows []TableRow) []Doc {
309309
if r.Label != "" {
310310
d := simplifyNil(docFn(r.Label), r.Doc,
311311
func(a, b Doc) Doc {
312+
if noNewLine {
313+
return ConcatSpace(a, b)
314+
}
312315
return Concat(a, NestT(Concat(Line, Group(b))))
313316
})
314317
items = append(items, d)

snapshot.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ find pkg -type f -name 'BUILD.bazel' | xargs rm
5555
# command works on both linux and macos.
5656
find pkg -type f -name '*.bak' | xargs rm
5757

58+
for f in patches/*; do
59+
echo "applying patch $f"
60+
git apply $f
61+
done
62+
5863
echo "Cleaning up go and testing everything works"
5964
go mod tidy
6065
git clean -fd

0 commit comments

Comments
 (0)