[HN Gopher] GQL - Git Query Language ___________________________________________________________________ GQL - Git Query Language Author : amrdeveloper Score : 95 points Date : 2023-12-02 14:06 UTC (8 hours ago) (HTM) web link (github.com) (TXT) w3m dump (github.com) | pokstad wrote: | Looks very cool. Does this produce a shell snippet with the | appropriate git commands? I like the idea of this being a very | thin frontend to git. | chx wrote: | The concept is interesting but the data exposed makes it kind of | hard to run interesting queries. Like, do we have a branch where | the last commit was a year ago? | | Also it seems up arrow doesn't work to recall the previous | command? | dafelst wrote: | This is a super cool idea, I've been playing with Git internals | and having this as a tool/reference will be super helpful. Thanks | for sharing! | | I don't see it in the code, but have you considered creating | secondary indexes to speed up some operations? Things like | looking up the path of a deleted file in a large repo? | zffr wrote: | Have you considered using SQLite vtables for this? | savolai wrote: | +1 Being able to browse with an sqlite ui would be lovely. | bastardoperator wrote: | I like the idea, and I like sql, but I feel like this is a lot | more typing for the same information you could extract using just | git commands. Am I missing something? Take for instance: | | The commit example: select name, count(name), | from commits group by name | | is actually: git shortlog -sn | | The tag example: select * from tags | | is actually: git tag | | The branch example: select * from branches | | is actually: git branch | snordgren wrote: | It may be more typing but I can write SQL in my sleep whereas | the git CLI I cannot. | | Though if I regularly needed the information that this tool | retrieves I would probably have memorized the relevant CLI | commands by now. | umvi wrote: | Sql is a more well known DSL than git CLI | dtgriscom wrote: | The git CLI is notoriously irregular, as can be seen by your | examples. Having a clean, regular language to query git objects | seems valuable. | esafak wrote: | This approach falls flat when you start doing analytical | queries, and it assumes you already know the git incantations, | which most people don't. | joshuanapoli wrote: | At least the SQL-like syntax is more consistent. It might be | easier to figure out how to make any given query starting from | the SQL "schema". | paulddraper wrote: | 1. SQL is more consistent | | 2. SQL is more capable | | 3. SQL is more well-known | fragmede wrote: | Unfortunate name, given that GraphQL already exists. | | https://en.wikipedia.org/wiki/Graph_Query_Language | jakewins wrote: | Also an ISO track thing https://www.gqlstandards.org/ | ghusbands wrote: | I've always seen it written as GraphQL, rather than GQL, though | that wikipedia page indeed calls it GQL multiple times. | 8n4vidtmkvmk wrote: | Because that one is apparently unrelated to GraphQL. Horrible | naming. | Hamuko wrote: | I guess it's not the only unfortunate name considering your | link begins with the words "Not to be confused with GraphQL". | lloydatkinson wrote: | What would a more complex query look like with that, for example, | querying for any commit that affected any file in a list of | files, by a specific author? | setheron wrote: | Apache Calcite has this as an integration as does SQLite though | virtual tables. | | Nonetheless nice work | jakubmazanec wrote: | Why would someone use SQL, famously bad language, as a query | language for git, famously badly designed CLI? | mpalmer wrote: | "Famously bad" is an opinion cloaked in adverbial authority. | Plenty of people like both, and even if they don't like them, | they think better in one vs the other. | 8n4vidtmkvmk wrote: | SQL is ok, it just needs to be refined a bit. This was such | an opportunity but they didn't cease it. | ebfe1 wrote: | Lovely! I only learnt today that clickhouse has a git-import tool | from my colleagues at ClickHouse. So if you also want to give it | a go: | | Download clickhouse: curl https://clickhouse.com/ | sh | | Check out documentation for git-import: ./clickhouse git-import | --help | | Then the tool can be run directly inside the git repository. It | will collect data like commits, file changes and changes of every | line in every file for further analysis. It works well even on | largest repositories like Linux or Chromium. | | Example of a trivial query: | | SELECT author AS k, count() AS c FROM line_changes WHERE | file_extension IN ('h', 'cpp') GROUP BY k ORDER BY c DESC LIMIT | 20 | | Example of some non-trivial query - a matrix of authors, how much | code of one author is removed by another: | | SELECT k, written_code.c, removed_code.c, round(removed_code.c * | 100 / written_code.c) AS remove_ratio FROM ( SELECT author AS k, | count() AS c FROM line_changes WHERE sign = 1 AND file_extension | IN ('h', 'cpp') AND line_type NOT IN ('Punct', 'Empty') GROUP BY | k ) AS written_code INNER JOIN ( SELECT prev_author AS k, count() | AS c FROM line_changes WHERE sign = -1 AND file_extension IN | ('h', 'cpp') AND line_type NOT IN ('Punct', 'Empty') AND author | != prev_author GROUP BY k ) AS removed_code USING (k) WHERE | written_code.c > 1000 ORDER BY c DESC LIMIT 500 | koolba wrote: | > Download clickhouse: curl https://clickhouse.com/ | sh | | Does this check the useragent to change the response? Clicking | that link shows their home page. | ebfe1 wrote: | that is exaxtly what it does ;) if you don't feel comfortable | with curl | sh , you can download clickhouse binary from the | repo here https://github.com/ClickHouse/ClickHouse/releases | | ;) | nittanymount wrote: | this seems converting graph/tree data model to relational data | model ? hmm... | ellisv wrote: | Looks cool. Reminds me of Steampipe except this works on a local | git repository. ___________________________________________________________________ (page generated 2023-12-02 23:00 UTC)