1---
2title: How Gitfs works
3linktitle: Gitfs explained
4description: Gitfs uses fuse to create current and history directories
5categories: [gitfs]
6keywords: [gitfs, readonlyview, passthroughview, currentview, historyview, commitview, indexview, fetchworker, mergeworker]
7weight: 2
8draft: false
9aliases: []
10toc: true
11related: true
12slug: how-gitfs-works
13---
14
15## FUSE
16
17gitfs uses [FUSE](http://fuse.sourceforge.net/) to create its filesystem. It’s used to create the `current` and `history` directories that you can find where you mounted the repository. More on that [here](usage.md#user-content-directory-structure).
18
19### pygit2
20
21[pygit2](https://github.com/libgit2/pygit2) gives us direct access to git and makes room for a lot of optimization. The alternative, using shell commands, would have been a pain to implement and so would have been tying it to a state too.
22
23### Structure
24This is a simplified overview of the `gitfs` structure.
25
26### Class diagram
27
28
29### Router
30
31The `Router` class is used in order to dispatch paths to different `Views`.
32
33### View
34
35Views are used to offer different functionality depending on your current path.
36
37They are divided into two super classes:
38- `PassthroughView`
39- `ReadOnlyView`
40
41The `PassthroughView` will work just like you would expect a normal directory to. It’s purpose is to map all of `FUSE`'s operations to the similar ones in `Python`.
42
43The `ReadOnlyView` is used when user writes are not desired.
44
45The subclasses of these are:
46
47- `PassthroughView`
48  - `CurrentView` – this is the view which handles the current directory and does the automated commits and pushes
49- `ReadOnlyView`
50  - `HistoryView` – this is the view which handles the history directory and categorizes commits by date
51  - `CommitView` – this is the view which handles the `history/*day*` directory
52  - `IndexView` – this is the view which handles the `history/*day*/*commit*` directory and shows you a read-only snapshot pointing to that commit
53
54### Worker
55
56All workers inherit the `Peasant` class which is nothing more than a specialized `Thread`.
57
58Here are the workers with their more than explicit names:
59- `FetchWorker`
60- `MergeWorker`
61
62### Idle mode
63
64gitfs uses the FetchWorker in order to bring your changes from upstream.
65The FetchWorker will fetch, by default, at a period of 30 seconds (you can change the timeout at mount, using `-o fetch_timeout=5`, for 5 seconds).
66
67If nothing was changed, for more than 5min on the filesystem, gitfs will enter in idle mode. In this mode, will fetch each 30min. You can modify those parameters using `min_idle_times` in order to change the amount of idle cycles required until gitfs will go in idle mode (by default 10 times, which means 5min) and `idle_fetch_timeout` to control the period of time between fetches, for idle mode.
68