2 unstable releases

0.2.0 Jul 2, 2020
0.1.0 May 4, 2020

#19 in #md5

BSD-3-Clause

8KB
73 lines

dirsh

built with nix

Dirsh hashes the contents of a directory, but respects your .gitignore file and its own .hashignore.

Motivation

Hashing the inputs of a build is a convenient way to avoid rebuilding. Current solutions to this problem are either domain-specific, or lack a convenient way to configure which files should be included in the hash.

Usage

By default, dirsh hashes the current directory. .gitignore and .hashignore are parsed in the gitignore spec and used for filtering.

Dirsh calculates the md5 for the directory contents and returns the hash in base32 without padding.

$ dirsh -h
dirsh 0.2.0
Ignore-file-respecting consistent hasher of directory contents

USAGE:
    dirsh [FLAGS] [paths]...

FLAGS:
    -h, --help            Prints help information
        --no-gitignore    don't parse gitignore (including global gitignore and local git excludes)
    -V, --version         Prints version information

ARGS:
    <paths>...     [default: ./]

The algorithm

Paths are recursively walked in alphabetical order.

File contents are fed to the digest, followed by 64 bits of modification time, and 32 bits of mode.

The md5 hash is then computed and base32 encoded without padding (for ease of url encoding, and compatibility with filesystems which ignore capitalization).

Development

This project is built with nix, and the development environment is available with nix-shell, or even better, lorri.

You can build the release binary with nix-build.

Without nix

This is a standard rust project. You'll need the rust toolchain to build this project.

cargo build

Dependencies

~7–17MB
~197K SLoC