Last active
March 26, 2018 20:55
-
-
Save ga2arch/5b80b0048f28c424c32d7f62d4cb73b4 to your computer and use it in GitHub Desktop.
gitdb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns core | |
(:require [clj-jgit.porcelain :as git] | |
[clj-jgit.querying :refer :all] | |
[clj-jgit.internal :refer [new-rev-walk]] | |
[clojure.set :refer [rename-keys]] | |
[datascript.core :as d] | |
[clojure.pprint :as pp]) | |
(:import (org.eclipse.jgit.internal.storage.file RefDirectory$LooseUnpeeled))) | |
(defn branch->map | |
[^RefDirectory$LooseUnpeeled branch] | |
{:branch/name (.getName branch) | |
:branch/id (.name (.getObjectId branch))}) | |
(defn commit->map | |
[commit] | |
(let [new-m {:email :commit/email | |
:time :commit/time | |
:branches :commit/branches | |
:changed_files :commit/changed_files | |
:merge :commit/merge | |
:author :commit/author | |
:id :commit/id | |
:message :commit/message}] | |
(into {} (for [[k v] new-m] [v (get commit k)])))) | |
(defn load-commit | |
[repo] | |
(let [rev-walk (new-rev-walk repo) | |
commit-map (build-commit-map repo rev-walk) | |
commits (git/git-log repo)] | |
(map (comp commit->map (partial commit-info repo rev-walk commit-map)) commits))) | |
(defn create-db | |
[] | |
(let [schema {:commit/branches {:db/cardinality :db.cardinality/many} | |
:commit/changed_files {:db/cardinality :db.cardinality/many} | |
:commit/id {:db/unique :db.unique/identity} | |
:branch/id {:db/unique :db.unique/identity}}] | |
(d/create-conn schema))) | |
(defn load-repo | |
[path] | |
(let [repo (git/load-repo path) | |
branches (mapv branch->map (git/git-branch-list repo)) | |
commits (load-commit repo) | |
conn (create-db)] | |
(d/transact! conn branches) | |
(d/transact! conn commits) | |
conn)) | |
(defn -main | |
[& args] | |
(let [path (first args) | |
query (read-string (second args)) | |
conn (load-repo (first args))] | |
(pp/print-table (mapv first (d/q query @conn))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{:paths ["."] | |
:deps | |
{org.clojure/clojure {:mvn/version "1.9.0"} | |
clj-jgit {:mvn/version "0.8.10"} | |
datascript {:mvn/version "0.16.4"} | |
org.slf4j/slf4j-nop {:mvn/version "1.7.25"}}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment