diff options
author | Profpatsch <mail@profpatsch.de> | 2019-03-25 13:50:16 +0100 |
---|---|---|
committer | Profpatsch <mail@profpatsch.de> | 2019-03-25 13:53:46 +0100 |
commit | 419be355e2c200f940e02aba1a5f503974399bec (patch) | |
tree | 58b7ed864cd16d85e72a5426a577be66186d2788 /pkgs/profpatsch/git-commit-index/default.nix | |
parent | 2217ba46e3e93d049c5e6aadf3b1c0090e8c7725 (diff) |
pkgs.profpatsch: add git-commit-index tools
A set of utilities to generate and query a git commit index, which is a database that knows which revs (that is: commits) are in which git repository. That way we can query for the project that contains a commit and show them, e.g. with xdg-open.
Diffstat (limited to 'pkgs/profpatsch/git-commit-index/default.nix')
-rw-r--r-- | pkgs/profpatsch/git-commit-index/default.nix | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/pkgs/profpatsch/git-commit-index/default.nix b/pkgs/profpatsch/git-commit-index/default.nix new file mode 100644 index 00000000..d7b9a781 --- /dev/null +++ b/pkgs/profpatsch/git-commit-index/default.nix @@ -0,0 +1,69 @@ +{ cdb, git, writeShellScriptBin, symlinkJoin, lib, script, runCommandLocal }: + +let + pathPlus = ''PATH="$PATH:${lib.makeBinPath [cdb git]}"''; + + mkIndex = script.withOptions { + name = "git-commit-index-create"; + synopsis = "Create a git commit index for all .git directories, recursively."; + + options = { + index = { + description = "Location of the index. Must not exist."; + checks = [ script.optionChecks.emptyPath ]; + }; + }; + + extraArgs = { + description = "List of root directories to recursively search"; + name = "DIRS"; + checks = [ script.argsChecks.allAreDirs ]; + }; + + script = '' + ${pathPlus} + source ${./lib.sh} + mkdir "$index" + for root in "$@"; do + for repo in $(findRepos "$root"); do + genIndex "$index" "$repo" + done + done + ''; + }; + + queryIndex = script.withOptions { + name = "git-commit-index-query"; + + synopsis = "Search a git commit index for a rev, return the repository that rev is in."; + + options = { + index = { + description = "Location of the populated index."; + checks = [ script.optionChecks.isDir ]; + }; + rev = { + description = "Full git rev hash to look up"; + # TODO: check that it is a commit hash? + checks = []; + }; + }; + + script = '' + ${pathPlus} + source ${./lib.sh} + + query "$index" "$rev" + ''; + }; + + # magitOpenCommit = writeShellScriptBin "git-commit-index-magit-open" '' + # ${pathPlus} +# emacsclient -e '(let ((default-directory "/home/philip/kot/work/tweag/lorri")) +# (magit-mode-setup #\'magit-revision-mode "43a72bc220dae8f34bd0d889f2b1b1ce2a6092b7" nil nil nil))' + +in + runCommandLocal "git-commit-index" {} '' + install -D ${mkIndex} $out/bin/git-commit-index-create + install -D ${queryIndex} $out/bin/git-commit-index-query + '' |