fork of https://github.com/sourcegraph/zoekt
0

Configure Feed

Select the types of activity you want to include in your feed.

api: JSON omitempty on optional fields in FileMatch (#721)

There are several fields which are optional in FileMatch. For example
branch and version are only set if indexing a git repo (zoekt can index
arbitrary files). We mark these fields as optional to marshal in JSON.
The main benefit of this is improving the readability of some golden
files.

Note: I noticed this when an unrelated commit touched these golden
files.

Test Plan: go test

+39 -165
+11 -11
api.go
··· 43 43 44 44 // SubRepositoryName is the globally unique name of the repo, 45 45 // if it came from a subrepository 46 - SubRepositoryName string 46 + SubRepositoryName string `json:",omitempty"` 47 47 48 48 // SubRepositoryPath holds the prefix where the subrepository 49 49 // was mounted. 50 - SubRepositoryPath string 50 + SubRepositoryPath string `json:",omitempty"` 51 51 52 52 // Commit SHA1 (hex) of the (sub)repo holding the file. 53 - Version string 53 + Version string `json:",omitempty"` 54 54 55 55 // Detected language of the result. 56 56 Language string 57 57 58 58 // For debugging. Needs DebugScore set, but public so tests in 59 59 // other packages can print some diagnostics. 60 - Debug string 60 + Debug string `json:",omitempty"` 61 61 62 - Branches []string 62 + Branches []string `json:",omitempty"` 63 63 64 64 // One of LineMatches or ChunkMatches will be returned depending on whether 65 65 // the SearchOptions.ChunkMatches is set. 66 - LineMatches []LineMatch 67 - ChunkMatches []ChunkMatch 66 + LineMatches []LineMatch `json:",omitempty"` 67 + ChunkMatches []ChunkMatch `json:",omitempty"` 68 68 69 69 // Only set if requested 70 - Content []byte 70 + Content []byte `json:",omitempty"` 71 71 72 72 // Checksum of the content. 73 73 Checksum []byte 74 74 75 75 // Ranking; the higher, the better. 76 - Score float64 // TODO - hide this field? 76 + Score float64 `json:",omitempty"` 77 77 78 78 // RepositoryPriority is a Sourcegraph extension. It is used by Sourcegraph to 79 79 // order results from different repositories relative to each other. 80 - RepositoryPriority float64 80 + RepositoryPriority float64 `json:",omitempty"` 81 81 82 82 // RepositoryID is a Sourcegraph extension. This is the ID of Repository in 83 83 // Sourcegraph. 84 - RepositoryID uint32 84 + RepositoryID uint32 `json:",omitempty"` 85 85 } 86 86 87 87 func (m *FileMatch) sizeBytes() (sz uint64) {
+8 -44
testdata/golden/TestReadSearch/ctagsrepo_v16.00000.golden
··· 4 4 "FileMatches": [ 5 5 [ 6 6 { 7 - "Score": 510, 8 - "Debug": "", 9 7 "FileName": "main.go", 10 8 "Repository": "repo", 11 - "Branches": null, 9 + "Language": "go", 12 10 "LineMatches": [ 13 11 { 14 12 "Line": "ZnVuYyBtYWluKCkgew==", ··· 30 28 ] 31 29 } 32 30 ], 33 - "ChunkMatches": null, 34 - "RepositoryID": 0, 35 - "RepositoryPriority": 0, 36 - "Content": null, 37 31 "Checksum": "n9fUYqacPXg=", 38 - "Language": "go", 39 - "SubRepositoryName": "", 40 - "SubRepositoryPath": "", 41 - "Version": "" 32 + "Score": 510 42 33 } 43 34 ], 44 35 [ 45 36 { 46 - "Score": 510, 47 - "Debug": "", 48 37 "FileName": "main.go", 49 38 "Repository": "repo", 50 - "Branches": null, 39 + "Language": "go", 51 40 "LineMatches": [ 52 41 { 53 42 "Line": "cGFja2FnZSBtYWlu", ··· 69 58 ] 70 59 } 71 60 ], 72 - "ChunkMatches": null, 73 - "RepositoryID": 0, 74 - "RepositoryPriority": 0, 75 - "Content": null, 76 61 "Checksum": "n9fUYqacPXg=", 77 - "Language": "go", 78 - "SubRepositoryName": "", 79 - "SubRepositoryPath": "", 80 - "Version": "" 62 + "Score": 510 81 63 } 82 64 ], 83 65 [ 84 66 { 85 - "Score": 8010, 86 - "Debug": "", 87 67 "FileName": "main.go", 88 68 "Repository": "repo", 89 - "Branches": null, 69 + "Language": "go", 90 70 "LineMatches": [ 91 71 { 92 72 "Line": "CW51bSAgICAgPSA1", ··· 113 93 ] 114 94 } 115 95 ], 116 - "ChunkMatches": null, 117 - "RepositoryID": 0, 118 - "RepositoryPriority": 0, 119 - "Content": null, 120 96 "Checksum": "n9fUYqacPXg=", 121 - "Language": "go", 122 - "SubRepositoryName": "", 123 - "SubRepositoryPath": "", 124 - "Version": "" 97 + "Score": 8010 125 98 } 126 99 ], 127 100 [ 128 101 { 129 - "Score": 6060, 130 - "Debug": "", 131 102 "FileName": "main.go", 132 103 "Repository": "repo", 133 - "Branches": null, 104 + "Language": "go", 134 105 "LineMatches": [ 135 106 { 136 107 "Line": "CW1lc3NhZ2UgPSAiaGVsbG8i", ··· 157 128 ] 158 129 } 159 130 ], 160 - "ChunkMatches": null, 161 - "RepositoryID": 0, 162 - "RepositoryPriority": 0, 163 - "Content": null, 164 131 "Checksum": "n9fUYqacPXg=", 165 - "Language": "go", 166 - "SubRepositoryName": "", 167 - "SubRepositoryPath": "", 168 - "Version": "" 132 + "Score": 6060 169 133 } 170 134 ] 171 135 ]
+8 -44
testdata/golden/TestReadSearch/ctagsrepo_v17.00000.golden
··· 4 4 "FileMatches": [ 5 5 [ 6 6 { 7 - "Score": 510, 8 - "Debug": "", 9 7 "FileName": "main.go", 10 8 "Repository": "repo", 11 - "Branches": null, 9 + "Language": "go", 12 10 "LineMatches": [ 13 11 { 14 12 "Line": "ZnVuYyBtYWluKCkgew==", ··· 30 28 ] 31 29 } 32 30 ], 33 - "ChunkMatches": null, 34 - "RepositoryID": 0, 35 - "RepositoryPriority": 0, 36 - "Content": null, 37 31 "Checksum": "n9fUYqacPXg=", 38 - "Language": "go", 39 - "SubRepositoryName": "", 40 - "SubRepositoryPath": "", 41 - "Version": "" 32 + "Score": 510 42 33 } 43 34 ], 44 35 [ 45 36 { 46 - "Score": 510, 47 - "Debug": "", 48 37 "FileName": "main.go", 49 38 "Repository": "repo", 50 - "Branches": null, 39 + "Language": "go", 51 40 "LineMatches": [ 52 41 { 53 42 "Line": "cGFja2FnZSBtYWlu", ··· 69 58 ] 70 59 } 71 60 ], 72 - "ChunkMatches": null, 73 - "RepositoryID": 0, 74 - "RepositoryPriority": 0, 75 - "Content": null, 76 61 "Checksum": "n9fUYqacPXg=", 77 - "Language": "go", 78 - "SubRepositoryName": "", 79 - "SubRepositoryPath": "", 80 - "Version": "" 62 + "Score": 510 81 63 } 82 64 ], 83 65 [ 84 66 { 85 - "Score": 8010, 86 - "Debug": "", 87 67 "FileName": "main.go", 88 68 "Repository": "repo", 89 - "Branches": null, 69 + "Language": "go", 90 70 "LineMatches": [ 91 71 { 92 72 "Line": "CW51bSAgICAgPSA1", ··· 113 93 ] 114 94 } 115 95 ], 116 - "ChunkMatches": null, 117 - "RepositoryID": 0, 118 - "RepositoryPriority": 0, 119 - "Content": null, 120 96 "Checksum": "n9fUYqacPXg=", 121 - "Language": "go", 122 - "SubRepositoryName": "", 123 - "SubRepositoryPath": "", 124 - "Version": "" 97 + "Score": 8010 125 98 } 126 99 ], 127 100 [ 128 101 { 129 - "Score": 6060, 130 - "Debug": "", 131 102 "FileName": "main.go", 132 103 "Repository": "repo", 133 - "Branches": null, 104 + "Language": "go", 134 105 "LineMatches": [ 135 106 { 136 107 "Line": "CW1lc3NhZ2UgPSAiaGVsbG8i", ··· 157 128 ] 158 129 } 159 130 ], 160 - "ChunkMatches": null, 161 - "RepositoryID": 0, 162 - "RepositoryPriority": 0, 163 - "Content": null, 164 131 "Checksum": "n9fUYqacPXg=", 165 - "Language": "go", 166 - "SubRepositoryName": "", 167 - "SubRepositoryPath": "", 168 - "Version": "" 132 + "Score": 6060 169 133 } 170 134 ] 171 135 ]
+4 -22
testdata/golden/TestReadSearch/repo17_v17.00000.golden
··· 4 4 "FileMatches": [ 5 5 [ 6 6 { 7 - "Score": 510, 8 - "Debug": "", 9 7 "FileName": "main.go", 10 8 "Repository": "repo17", 11 - "Branches": null, 9 + "Language": "Go", 12 10 "LineMatches": [ 13 11 { 14 12 "Line": "ZnVuYyBtYWluKCkgew==", ··· 30 28 ] 31 29 } 32 30 ], 33 - "ChunkMatches": null, 34 - "RepositoryID": 0, 35 - "RepositoryPriority": 0, 36 - "Content": null, 37 31 "Checksum": "n9fUYqacPXg=", 38 - "Language": "Go", 39 - "SubRepositoryName": "", 40 - "SubRepositoryPath": "", 41 - "Version": "" 32 + "Score": 510 42 33 } 43 34 ], 44 35 [ 45 36 { 46 - "Score": 510, 47 - "Debug": "", 48 37 "FileName": "main.go", 49 38 "Repository": "repo17", 50 - "Branches": null, 39 + "Language": "Go", 51 40 "LineMatches": [ 52 41 { 53 42 "Line": "cGFja2FnZSBtYWlu", ··· 69 58 ] 70 59 } 71 60 ], 72 - "ChunkMatches": null, 73 - "RepositoryID": 0, 74 - "RepositoryPriority": 0, 75 - "Content": null, 76 61 "Checksum": "n9fUYqacPXg=", 77 - "Language": "Go", 78 - "SubRepositoryName": "", 79 - "SubRepositoryPath": "", 80 - "Version": "" 62 + "Score": 510 81 63 } 82 64 ], 83 65 null,
+4 -22
testdata/golden/TestReadSearch/repo2_v16.00000.golden
··· 4 4 "FileMatches": [ 5 5 [ 6 6 { 7 - "Score": 510, 8 - "Debug": "", 9 7 "FileName": "main.go", 10 8 "Repository": "repo2", 11 - "Branches": null, 9 + "Language": "Go", 12 10 "LineMatches": [ 13 11 { 14 12 "Line": "ZnVuYyBtYWluKCkgew==", ··· 30 28 ] 31 29 } 32 30 ], 33 - "ChunkMatches": null, 34 - "RepositoryID": 0, 35 - "RepositoryPriority": 0, 36 - "Content": null, 37 31 "Checksum": "Ju1TnQKZ6mE=", 38 - "Language": "Go", 39 - "SubRepositoryName": "", 40 - "SubRepositoryPath": "", 41 - "Version": "" 32 + "Score": 510 42 33 } 43 34 ], 44 35 [ 45 36 { 46 - "Score": 510, 47 - "Debug": "", 48 37 "FileName": "main.go", 49 38 "Repository": "repo2", 50 - "Branches": null, 39 + "Language": "Go", 51 40 "LineMatches": [ 52 41 { 53 42 "Line": "cGFja2FnZSBtYWlu", ··· 69 58 ] 70 59 } 71 60 ], 72 - "ChunkMatches": null, 73 - "RepositoryID": 0, 74 - "RepositoryPriority": 0, 75 - "Content": null, 76 61 "Checksum": "Ju1TnQKZ6mE=", 77 - "Language": "Go", 78 - "SubRepositoryName": "", 79 - "SubRepositoryPath": "", 80 - "Version": "" 62 + "Score": 510 81 63 } 82 64 ], 83 65 null,
+4 -22
testdata/golden/TestReadSearch/repo_v16.00000.golden
··· 4 4 "FileMatches": [ 5 5 [ 6 6 { 7 - "Score": 510, 8 - "Debug": "", 9 7 "FileName": "main.go", 10 8 "Repository": "repo", 11 - "Branches": null, 9 + "Language": "Go", 12 10 "LineMatches": [ 13 11 { 14 12 "Line": "ZnVuYyBtYWluKCkgew==", ··· 30 28 ] 31 29 } 32 30 ], 33 - "ChunkMatches": null, 34 - "RepositoryID": 0, 35 - "RepositoryPriority": 0, 36 - "Content": null, 37 31 "Checksum": "n9fUYqacPXg=", 38 - "Language": "Go", 39 - "SubRepositoryName": "", 40 - "SubRepositoryPath": "", 41 - "Version": "" 32 + "Score": 510 42 33 } 43 34 ], 44 35 [ 45 36 { 46 - "Score": 510, 47 - "Debug": "", 48 37 "FileName": "main.go", 49 38 "Repository": "repo", 50 - "Branches": null, 39 + "Language": "Go", 51 40 "LineMatches": [ 52 41 { 53 42 "Line": "cGFja2FnZSBtYWlu", ··· 69 58 ] 70 59 } 71 60 ], 72 - "ChunkMatches": null, 73 - "RepositoryID": 0, 74 - "RepositoryPriority": 0, 75 - "Content": null, 76 61 "Checksum": "n9fUYqacPXg=", 77 - "Language": "Go", 78 - "SubRepositoryName": "", 79 - "SubRepositoryPath": "", 80 - "Version": "" 62 + "Score": 510 81 63 } 82 64 ], 83 65 null,