Skip to content

Commit dbe032c

Browse files
authored
Make all non-user-creatable structures non-comparable (#802)
This change makes all non-user-creatable structures non-comparable. This makes it easier to add changes later that don't introduce breaking changes from the go compatibility guarantees perspective. This, of course, implies that this change _is_ a breaking change, but since these structures are not intended to be created by users (or de-referenced), it should be okay.
1 parent 549706b commit dbe032c

32 files changed

+62
-7
lines changed

blame.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ func (v *Repository) BlameFile(path string, opts *BlameOptions) (*Blame, error)
8787
}
8888

8989
type Blame struct {
90+
doNotCompare
9091
ptr *C.git_blame
9192
}
9293

blob.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
)
1616

1717
type Blob struct {
18+
doNotCompare
1819
Object
1920
cast_ptr *C.git_blob
2021
}
@@ -96,6 +97,7 @@ func (repo *Repository) CreateFromStream(hintPath string) (*BlobWriteStream, err
9697
}
9798

9899
type BlobWriteStream struct {
100+
doNotCompare
99101
ptr *C.git_writestream
100102
repo *Repository
101103
}

branch.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const (
1919
)
2020

2121
type Branch struct {
22+
doNotCompare
2223
*Reference
2324
}
2425

@@ -27,6 +28,7 @@ func (r *Reference) Branch() *Branch {
2728
}
2829

2930
type BranchIterator struct {
31+
doNotCompare
3032
ptr *C.git_branch_iterator
3133
repo *Repository
3234
}

commit.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const (
2222

2323
// Commit
2424
type Commit struct {
25+
doNotCompare
2526
Object
2627
cast_ptr *C.git_commit
2728
}

config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ func newConfigEntryFromC(centry *C.git_config_entry) *ConfigEntry {
5252
}
5353

5454
type Config struct {
55+
doNotCompare
5556
ptr *C.git_config
5657
}
5758

@@ -361,6 +362,7 @@ func OpenOndisk(path string) (*Config, error) {
361362
}
362363

363364
type ConfigIterator struct {
365+
doNotCompare
364366
ptr *C.git_config_iterator
365367
cfg *Config
366368
}

credentials.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ func (t CredentialType) String() string {
7979
}
8080

8181
type Credential struct {
82+
doNotCompare
8283
ptr *C.git_credential
8384
}
8485

deprecated.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ type SubmoduleCbk = SubmoduleCallback
224224

225225
// Deprecated: SubmoduleVisitor is not used.
226226
func SubmoduleVisitor(csub unsafe.Pointer, name *C.char, handle unsafe.Pointer) C.int {
227-
sub := &Submodule{(*C.git_submodule)(csub), nil}
227+
sub := &Submodule{ptr: (*C.git_submodule)(csub)}
228228

229229
callback, ok := pointerHandles.Get(handle).(SubmoduleCallback)
230230
if !ok {

describe.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ func (repo *Repository) DescribeWorkdir(opts *DescribeOptions) (*DescribeResult,
176176
//
177177
// Use Format() to get a string out of it.
178178
type DescribeResult struct {
179+
doNotCompare
179180
ptr *C.git_describe_result
180181
}
181182

diff.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ func diffLineFromC(line *C.git_diff_line) DiffLine {
132132
}
133133

134134
type Diff struct {
135+
doNotCompare
135136
ptr *C.git_diff
136137
repo *Repository
137138
runFinalizer bool
@@ -219,6 +220,7 @@ func (diff *Diff) FindSimilar(opts *DiffFindOptions) error {
219220
}
220221

221222
type DiffStats struct {
223+
doNotCompare
222224
ptr *C.git_diff_stats
223225
}
224226

git.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ var (
123123
ErrInvalid = errors.New("Invalid state for operation")
124124
)
125125

126+
// doNotCompare is an idiomatic way of making structs non-comparable to avoid
127+
// future field additions to make them non-comparable.
128+
type doNotCompare [0]func()
129+
126130
var pointerHandles *HandleList
127131

128132
func init() {

0 commit comments

Comments
 (0)