You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/using-gitbase/examples.md
+20-38Lines changed: 20 additions & 38 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,34 +18,30 @@ FROM refs
18
18
WHERE ref_name ='HEAD';
19
19
```
20
20
21
-
## First commit on HEAD history for all repositories
21
+
## Files in the first commit on HEAD history for all repositories
22
22
23
23
```sql
24
24
SELECT file_path,
25
25
ref_commits.repository_id
26
26
FROM commit_files
27
27
NATURAL JOIN ref_commits
28
-
WHEREref_commits.ref_name='HEAD'
29
-
ANDref_commits.history_index=0;
28
+
WHERE ref_name ='HEAD'
29
+
AND history_index =0;
30
30
```
31
31
32
32
## Commits that appear in more than one reference
33
33
34
34
```sql
35
-
SELECT*
36
-
FROM
37
-
(SELECTCOUNT(c.commit_hash) AS num,
38
-
c.commit_hash
39
-
FROM ref_commits r
40
-
NATURAL JOIN commits c
41
-
GROUP BYc.commit_hash) t
42
-
WHERE num >1;
35
+
SELECTCOUNT(commit_hash) AS num, commit_hash
36
+
FROM ref_commits
37
+
GROUP BY commit_hash
38
+
HAVING num >1;
43
39
```
44
40
45
41
## Get the number of blobs per HEAD commit
46
42
47
43
```sql
48
-
SELECTCOUNT(commit_hash),
44
+
SELECTCOUNT(commit_blob),
49
45
commit_hash
50
46
FROM ref_commits
51
47
NATURAL JOIN commits
@@ -85,8 +81,8 @@ SELECT
85
81
SUM(JSON_EXTRACT(LOC(file_path, blob_content), '$.Comments')) as comments,
86
82
SUM(JSON_EXTRACT(LOC(file_path, blob_content), '$.Blanks')) as blanks,
87
83
COUNT(1) as files
88
-
FROMcommit_files
89
-
NATURAL JOINrefs
84
+
FROMrefs
85
+
NATURAL JOINcommit_files
90
86
NATURAL JOIN blobs
91
87
WHERE ref_name='HEAD'
92
88
GROUP BY lang;
@@ -98,13 +94,13 @@ GROUP BY lang;
98
94
SELECT file_path,
99
95
repository_id,
100
96
blob_content
101
-
FROMfiles
97
+
FROMref_commits
102
98
NATURAL JOIN commit_files
103
-
NATURAL JOINref_commits
99
+
NATURAL JOINfiles
104
100
WHERE ref_name ='HEAD'
105
-
ANDref_commits.history_index BETWEEN 0AND5
106
-
ANDis_binary(blob_content)= FALSE
107
-
ANDfiles.file_pathNOT REGEXP '^vendor.*'
101
+
AND history_index BETWEEN 0AND5
102
+
ANDNOT IS_BINARY(blob_content)
103
+
AND NOT IS_VENDOR(file_path)
108
104
AND (blob_content REGEXP '(?i)facebook.*[\'\\"][0-9a-f]{32}[\'\\"]'
109
105
OR blob_content REGEXP '(?i)twitter.*[\'\\"][0-9a-zA-Z]{35,44}[\'\\"]'
110
106
OR blob_content REGEXP '(?i)github.*[\'\\"][0-9a-zA-Z]{35,40}[\'\\"]'
@@ -145,7 +141,7 @@ DROP INDEX files_lang_idx ON files;
145
141
146
142
This query will report how many lines of actual code (only code, not comments, blank lines or text) changed in the last commit of each repository.
147
143
148
-
```
144
+
```sql
149
145
SELECT
150
146
repo,
151
147
JSON_EXTRACT(stats, '$.Code.Additions') AS code_lines_added,
@@ -175,7 +171,7 @@ The output will be similar to this:
175
171
This query will report how many lines of actual code (only code, not comments, blank lines or text) changed in each file of the last commit of each repository. It's similar to the previous example. `COMMIT_STATS` is an aggregation over the result of `COMMIT_FILE_STATS` so to speak.
176
172
We will only report those files that whose language has been identified.
177
173
178
-
```
174
+
```sql
179
175
SELECT
180
176
repo,
181
177
JSON_UNQUOTE(JSON_EXTRACT(stats, '$.Path')) AS file_path,
@@ -210,29 +206,15 @@ First of all, you should check out the [bblfsh documentation](https://docs.sourc
210
206
211
207
Also, you can take a look to all the UDFs and their signatures in the [functions section](/docs/using-gitbase/functions.md)
212
208
213
-
## Extract all import paths for every *Go* file on *HEAD* reference
214
-
215
-
```sql
216
-
SELECT repository_id,
217
-
file_path,
218
-
uast_extract(uast(blob_content, LANGUAGE(file_path), '//uast:Import/Path'), "Value") AS imports
219
-
FROM commit_files
220
-
NATURAL JOIN refs
221
-
NATURAL JOIN blobs
222
-
WHERE ref_name ='HEAD'
223
-
AND LANGUAGE(file_path) ='Go'
224
-
AND ARRAY_LENGTH(imports) >0;
225
-
```
226
-
227
209
## Extracting all identifier names
228
210
229
211
```sql
230
212
SELECT file_path,
231
213
uast_extract(uast(blob_content, LANGUAGE(file_path), '//uast:Identifier'), "Name") name
232
-
FROMcommit_files
233
-
NATURAL JOINrefs
214
+
FROMrefs
215
+
NATURAL JOINcommit_files
234
216
NATURAL JOIN blobs
235
-
WHERE ref_name='HEAD'AND LANGUAGE(file_path) ='Go';
217
+
WHERE ref_name='HEAD'AND LANGUAGE(file_path) ='Go';
236
218
```
237
219
238
220
As result, you will get an array showing a list of the retrieved information. Each element in the list matches a node in the given sequence of nodes having a value for that property. It means that the length of the properties list may not be equal to the length of the given sequence of nodes:
Copy file name to clipboardExpand all lines: docs/using-gitbase/functions.md
+20Lines changed: 20 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -169,6 +169,26 @@ Also, if you want to retrieve values from a non common property, you can pass it
169
169
170
170
> uast_extract(nodes_column, 'some-property')
171
171
172
+
## How to use `loc`
173
+
174
+
`loc` will return statistics about the lines of code in a file, such as the code lines, comment lines, etc.
175
+
176
+
It requires a file path and a file content.
177
+
178
+
> loc(file_path, blob_content)
179
+
180
+
The result of this function is a JSON document with the following shape:
181
+
182
+
```
183
+
{
184
+
"Code": code lines,
185
+
"Comment": comment lines,
186
+
"Blank": blank lines,
187
+
"Name": file name,
188
+
"Lang": language
189
+
}
190
+
```
191
+
172
192
## How to use `commit_file_stats`
173
193
174
194
`commit_file_stats` will return statistics about the line changes in all files in the given range of commits classifying them in 4 categories: code, comments, blank lines and other.
0 commit comments