Zum Inhalt springen

Analyse eines Git-Repositorys

Sie können DuckDB verwenden, um Git-Logs anhand der Ausgabe des Befehls git log zu analysieren.

Export des Git-Logs

Zuerst wählen wir ein Zeichen, das in keinem Teil des Commit-Logs vorkommt (Autorennamen, Nachrichten usw.). Seit Version v1.2.0 unterstützt der CSV-Reader von DuckDB 4-Byte-Trennzeichen, sodass Emojis verwendet werden können! 🎉

Obwohl es im Emoji Movie vorkommt (IMDb-Bewertung: 3,4), können wir annehmen, dass das Emoji „Fish Cake with Swirl“ (🍥) in den meisten Git-Logs nicht häufig vorkommt. Klonen wir also das Repository duckdb/duckdb und exportieren das Log wie folgt:

Terminal window
git log --date=iso-strict --pretty=format:%ad🍥%h🍥%an🍥%s > git-log.csv

Die resultierende Datei sieht so aus:

2025-02-25T18:12:54+01:00🍥d608a31e13🍥Mark🍥MAIN_BRANCH_VERSIONING: Adopt also for Python build and amalgamation (#16400)
2025-02-25T15:05:56+01:00🍥920b39ad96🍥Mark🍥Read support for Parquet Float16 (#16395)
2025-02-25T13:43:52+01:00🍥61f55734b9🍥Carlo Piovesan🍥MAIN_BRANCH_VERSIONING: Adopt also for Python build and amalgamation
2025-02-25T12:35:28+01:00🍥87eff7ebd3🍥Mark🍥Fix issue #16377 (#16391)
2025-02-25T10:33:49+01:00🍥35af26476e🍥Hannes Mühleisen🍥Read support for Parquet Float16

Laden des Git-Logs in DuckDB

Starten Sie DuckDB und lesen Sie das Log als CSV 🍥SV:

CREATE TABLE commits AS
FROM read_csv(
'git-log.csv',
delim = '🍥',
header = false,
column_names = ['timestamp', 'hash', 'author', 'message']
);

Das ergibt eine übersichtliche DuckDB-Tabelle:

FROM commits
LIMIT 5;
┌─────────────────────┬────────────┬──────────────────┬───────────────────────────────────────────────────────────────────────────────┐
│ timestamp │ hash │ author │ message │
│ timestamp │ varchar │ varchar │ varchar │
├─────────────────────┼────────────┼──────────────────┼───────────────────────────────────────────────────────────────────────────────┤
│ 2025-02-25 17:12:54 │ d608a31e13 │ Mark │ MAIN_BRANCH_VERSIONING: Adopt also for Python build and amalgamation (#16400) │
│ 2025-02-25 14:05:56 │ 920b39ad96 │ Mark │ Read support for Parquet Float16 (#16395) │
│ 2025-02-25 12:43:52 │ 61f55734b9 │ Carlo Piovesan │ MAIN_BRANCH_VERSIONING: Adopt also for Python build and amalgamation │
│ 2025-02-25 11:35:28 │ 87eff7ebd3 │ Mark │ Fix issue #16377 (#16391) │
│ 2025-02-25 09:33:49 │ 35af26476e │ Hannes Mühleisen │ Read support for Parquet Float16 │
└─────────────────────┴────────────┴──────────────────┴───────────────────────────────────────────────────────────────────────────────┘

Analyse des Logs

Wir können die Tabelle wie jede andere in DuckDB analysieren.

Häufige Themen

Beginnen wir mit einer einfachen Frage: Welches Thema wurde in den Commit-Nachrichten am häufigsten erwähnt: CI, CLI oder Python?

SELECT
message.lower().regexp_extract('\b(ci|cli|python)\b') AS topic,
count(*) AS num_commits
FROM commits
WHERE topic <> ''
GROUP BY ALL
ORDER BY num_commits DESC;
┌─────────┬─────────────┐
│ topic │ num_commits │
│ varchar │ int64 │
├─────────┼─────────────┤
│ ci │ 828 │
│ python │ 666 │
│ cli │ 49 │
└─────────┴─────────────┘

Von diesen drei Themen dominieren Commits zur kontinuierlichen Integration das Log!

Wir können auch eine explorativere Analyse durchführen, indem wir alle Wörter in den Commit-Nachrichten betrachten. Dazu tokenisieren wir zunächst die Nachrichten:

CREATE TABLE words AS
SELECT unnest(
message
.lower()
.regexp_replace('\W', ' ')
.trim(' ')
.string_split_regex('\W')
) AS word
FROM commits;

Anschließend entfernen wir Stoppwörter anhand einer vordefinierten Liste:

CREATE TABLE stopwords AS
SELECT unnest(['a', 'about', 'above', 'after', 'again', 'against', 'all', 'am', 'an', 'and', 'any', 'are', 'as', 'at', 'be', 'because', 'been', 'before', 'being', 'below', 'between', 'both', 'but', 'by', 'can', 'did', 'do', 'does', 'doing', 'don', 'down', 'during', 'each', 'few', 'for', 'from', 'further', 'had', 'has', 'have', 'having', 'he', 'her', 'here', 'hers', 'herself', 'him', 'himself', 'his', 'how', 'i', 'if', 'in', 'into', 'is', 'it', 'its', 'itself', 'just', 'me', 'more', 'most', 'my', 'myself', 'no', 'nor', 'not', 'now', 'of', 'off', 'on', 'once', 'only', 'or', 'other', 'our', 'ours', 'ourselves', 'out', 'over', 'own', 's', 'same', 'she', 'should', 'so', 'some', 'such', 't', 'than', 'that', 'the', 'their', 'theirs', 'them', 'themselves', 'then', 'there', 'these', 'they', 'this', 'those', 'through', 'to', 'too', 'under', 'until', 'up', 'very', 'was', 'we', 'were', 'what', 'when', 'where', 'which', 'while', 'who', 'whom', 'why', 'will', 'with', 'you', 'your', 'yours', 'yourself', 'yourselves']) AS word;
CREATE OR REPLACE TABLE words AS
FROM words
NATURAL ANTI JOIN stopwords
WHERE word != '';

Hier verwenden wir die Klausel NATURAL ANTI JOIN, mit der wir elegant Werte herausfiltern, die in der Tabelle stopwords vorkommen.

Abschließend wählen wir die 20 häufigsten Wörter.

SELECT word, count(*) AS count FROM words
GROUP BY ALL
ORDER BY count DESC
LIMIT 20;
┌──────────┬───────┐
│ w │ count │
│ varchar │ int64 │
├──────────┼───────┤
│ merge │ 12550 │
│ fix │ 6402 │
│ branch │ 6005 │
│ pull │ 5950 │
│ request │ 5945 │
│ add │ 5687 │
│ test │ 3801 │
│ master │ 3289 │
│ tests │ 2339 │
│ issue │ 1971 │
│ main │ 1935 │
│ remove │ 1884 │
│ format │ 1819 │
│ duckdb │ 1710 │
│ use │ 1442 │
│ mytherin │ 1410 │
│ fixes │ 1333 │
│ hawkfish │ 1147 │
│ feature │ 1139 │
│ function │ 1088 │
├──────────┴───────┤
│ 20 rows │
└──────────────────┘

Wie erwartet gibt es viele Git-Begriffe (merge, branch, pull usw.), gefolgt von entwicklungsbezogener Terminologie (fix, test/tests, issue, format). Wir sehen auch die Account-Namen einiger Entwickler (mytherin, hawkfish), die wahrscheinlich von Commit-Nachrichten zum Mergen von Pull Requests stammen (z. B. „Merge pull request #13776 from Mytherin/expressiondepth“). Schließlich sehen wir auch einige DuckDB-bezogene Begriffe wie duckdb (überraschend!) und function.

Visualisierung der Commit-Anzahl

Visualisieren wir die Anzahl der Commits pro Jahr:

SELECT
year(timestamp) AS year,
count(*) AS num_commits,
num_commits.bar(0, 20_000) AS num_commits_viz
FROM commits
GROUP BY ALL
ORDER BY ALL;
┌───────┬─────────────┬──────────────────────────────────────────────────────────────────────────────────┐
│ year │ num_commits │ num_commits_viz │
│ int64 │ int64 │ varchar │
├───────┼─────────────┼──────────────────────────────────────────────────────────────────────────────────┤
│ 2018 │ 870 │ ███▍ │
│ 2019 │ 1621 │ ██████▍ │
│ 2020 │ 3484 │ █████████████▉ │
│ 2021 │ 6488 │ █████████████████████████▉ │
│ 2022 │ 9817 │ ███████████████████████████████████████▎ │
│ 2023 │ 14585 │ ██████████████████████████████████████████████████████████▎ │
│ 2024 │ 15949 │ ███████████████████████████████████████████████████████████████▊ │
│ 2025 │ 1788 │ ███████▏ │
└───────┴─────────────┴──────────────────────────────────────────────────────────────────────────────────┘

Wir sehen ein stetiges Wachstum über die Jahre – insbesondere wenn man bedenkt, dass viele Funktionen und Clients von DuckDB, die ursprünglich Teil des Haupt-Repositorys waren, inzwischen in eigenen Repositories gepflegt werden (z. B. Java, R).

Fröhliches Hacken!