about summary refs log tree commit diff
path: root/pkgs/profpatsch/git-commit-index/default.nix
blob: d7b9a781847a7f6a1a6c4e6379a8a4b0e042dacf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
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
  ''