summaryrefslogtreecommitdiffstats
path: root/mm/interval_tree.c
blob: b476643587966102e90813663b2039461d1dc679 (plain)
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
 * mm/interval_tree.c - interval tree for mapping->i_mmap
 *
 * Copyright (C) 2012, Michel Lespinasse <walken@google.com>
 *
 * This file is released under the GPL v2.
 */

#include <linux/mm.h>
#include <linux/fs.h>
#include <linux/rmap.h>
#include <linux/interval_tree_generic.h>

static inline unsigned long vma_start_pgoff(struct vm_area_struct *v)
{
	return v->vm_pgoff;
}

static inline unsigned long vma_last_pgoff(struct vm_area_struct *v)
{
	return v->vm_pgoff + ((v->vm_end - v->vm_start) >> PAGE_SHIFT) - 1;
}

INTERVAL_TREE_DEFINE(struct vm_area_struct, shared.rb,
		     unsigned long, shared.rb_subtree_last,
		     vma_start_pgoff, vma_last_pgoff,, vma_interval_tree)

/* Insert node immediately after prev in the interval tree */
void vma_interval_tree_insert_after(struct vm_area_struct *node,
				    struct vm_area_struct *prev,
				    struct rb_root_cached *root)
{
	struct rb_node **link;
	struct vm_area_struct *parent;
	unsigned long last = vma_last_pgoff(node);

	VM_BUG_ON_VMA(vma_start_pgoff(node) != vma_start_pgoff(prev), node);

	if (!prev->shared.rb.rb_right) {
		parent = prev;
		link = &prev->shared.rb.rb_right;
	} else {
		parent = rb_entry(prev->shared.rb.rb_right,
				  struct vm_area_struct, shared.rb);
		if (parent->shared.rb_subtree_last < last)
			parent->shared.rb_subtree_last = last;
		while (parent->shared.rb.rb_left) {
			parent = rb_entry(parent->shared.rb.rb_left,
				struct vm_area_struct, shared.rb);
			if (parent->shared.rb_subtree_last < last)
				parent->shared.rb_subtree_last = last;
		}
		link = &parent->shared.rb.rb_left;
	}

	node->shared.rb_subtree_last = last;
	rb_link_node(&node->shared.rb, &parent->shared.rb, link);
	rb_insert_augmented(&node->shared.rb, &root->rb_root,
			    &vma_interval_tree_augment);
}

static inline unsigned long avc_start_pgoff(struct anon_vma_chain *avc)
{
	return vma_start_pgoff(avc->vma);
}

static inline unsigned long avc_last_pgoff(struct anon_vma_chain *avc)
{
	return vma_last_pgoff(avc->vma);
}

INTERVAL_TREE_DEFINE(struct anon_vma_chain, rb, unsigned long, rb_subtree_last,
		     avc_start_pgoff, avc_last_pgoff,
		     static inline, __anon_vma_interval_tree)

void anon_vma_interval_tree_insert(struct anon_vma_chain *node,
				   struct rb_root_cached *root)
{
#ifdef CONFIG_DEBUG_VM_RB
	node->cached_vma_start = avc_start_pgoff(node);
	node->cached_vma_last = avc_last_pgoff(node);
#endif
	__anon_vma_interval_tree_insert(node, root);
}

void anon_vma_interval_tree_remove(struct anon_vma_chain *node,
				   struct rb_root_cached *root)
{
	__anon_vma_interval_tree_remove(node, root);
}

struct anon_vma_chain *
anon_vma_interval_tree_iter_first(struct rb_root_cached *root,
				  unsigned long first, unsigned long last)
{
	return __anon_vma_interval_tree_iter_first(root, first, last);
}

struct anon_vma_chain *
anon_vma_interval_tree_iter_next(struct anon_vma_chain *node,
				 unsigned long first, unsigned long last)
{
	return __anon_vma_interval_tree_iter_next(node, first, last);
}

#ifdef CONFIG_DEBUG_VM_RB
void anon_vma_interval_tree_verify(struct anon_vma_chain *node)
{
	WARN_ON_ONCE(node->cached_vma_start != avc_start_pgoff(node));
	WARN_ON_ONCE(node->cached_vma_last != avc_last_pgoff(node));
}
#endif
ger */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
### next
- add support for backtab key (by default it's bound to :previous_match)
- `:rename` built-in verb, best used with its keyboard shortcut F2
- new verb argument: `auto_exec`
- new standard verb arguments: `{file-stem}`, `{file-extension}`, and `{file-dot-extension}`,
- new `:toggle_second_tree` internal - Fix #388
- fix a few minor bugs

<a name="v1.4.0"></a>
### v1.4.0 - 2021-05-11
- the default (non prefixed) search is now "path fuzzy" instead of "name fuzzy". You can still change the default mode and mode bindings in the config. This was done after a survey in chat.
- new "unordered tokens" search type: `t/ab,cd` searches for tokens "ab" and "cd" in any order and case insensitive in the subpath, matches for example `src/dcd/Bab.rs` - Fix #378
- fix search modes configuration removing all default mappings - Fix #383
- conf / quit_on_last_cancel to allow quitting with esc when there's nothing to cancel - Fix #380
- new `parent` skin entry for the part of the sub-path before the file name (visible when you search on subpath)
- when a content search has been done, opening a file with a compatible command (like the standard `:edit`) opens on the first line with a match

<a name="v1.3.1"></a>
### v1.3.1 - 2021-04-30
- fix `:previous_match` not jumping over indirect matches - Fix #377
- fix typing a prefixed pattern then emptying it while keeping the prefix doesn't remove filtering - Fix #379
- fix shifted matching chars highlighting with regex patterns when showing icons - Fix #376

<a name="v1.3.0"></a>
### v1.3.0 - 2021-04-28
#### Minor changes:
- modal mode: revert to command mode on command execution - Fix #372
- modal mode: when in command mode, '/' only enters input mode and is never appended to the input
- better handle failing external programs when not leaving broot
#### Major feature: staging area
You may add files to the staging area then apply a command on all of them. This new feature is described [here](https://dystroy.org/broot/staging-area).
Several verbs have been added. Type "stag" in help to see them and their keyboard shortcuts.

<a name="v1.2.10"></a>
### v1.2.10 - 2021-04-03
- fix shift based key shortcuts - Fix #363
- check there's another panel before executing verbs with other-panel argument - Fix #366

<a name="v1.2.9"></a>
### v1.2.9 - 2021-03-18
- fix crash on `:input_del_word_left` - Fix #361
- remove diacritics and normalize unicode from input on fuzzy search (an unnormalized string with unwanted diacritics most often happen when you paste a string in the input)

<a name="v1.2.8"></a>
### v1.2.8 - 2021-03-11
- it's possible to define several key shortcuts for a verb, using the "keys" property
- improvements of fuzzy matching

<a name="v1.2.7"></a>
### v1.2.7 - 2021-02-28
- don't ask again for installation if no sourcing file has been found

<a name="v1.2.6"></a>
### v1.2.6 - 2021-02-27
- clipboard features (copy and paste verbs) now work on Android/Termux (needs the Termux API to be installed)
- fix a compilation problem on non gnu windows - Thanks @Stargateur
- obey '--color no' even in standard application mode. In that case, automatically enable selection marks or you wouldn't know what line is selected

<a name="v1.2.5"></a>
### v1.2.5 - 2021-02-25
- fix style characters being written in `--no-style` mode - Fix #346
- replace `--no-style` with `--color` taking `yes`, `no` or `auto`, with detection of output being piped in `auto` mode (default). `--no-style` is still usable but it's not documented anymore - Fix #347
- fix wrong version number written in log file - Fix #349
- by default the number of panels is now limited to 2 (can be changed in conf with `max_panels_count`). The goal is to improve the global ergonomics for the most common (universal?) use case - Fix #345

<a name="v1.2.4"></a>
### v1.2.4 - 2021-02-14
- :line_down_no_cycle and :line_up_nocycle. They may be mapped instead of :line_up and :line_down when you don't want to cycle (ie arrive on top when you go down past the end of the tree/list) - Fix #344
- fix selected line number rendering in text preview

<a name="v1.2.3"></a>
### v1.2.3 - 2021-02-06
- special paths in "no-enter" or "hide" aren't counted when summing sizes or dates. It's a compromise: it makes all sums a little slower, especially if you have a lot of special paths or complex ones, but it allows skipping over the very slow disks and thus makes some cases much faster - Fix #331
- br fish shell function uses shell completion of broot
- tree height in `:pt` now applies even when there are more root items (thus truncating the tree) - Fix #341
- fix the F5 and F6 shortcuts (copy and move between panels) in the default configuration

<a name="v1.2.1"></a>
### v1.2.1 - 2021-01-27
- allow dashes instead of underscores in conf property names. This fixes a regression as "special-paths", "ext-colors" and "search-modes" were defined with a dash up to version 1.0.7. Now both spellings are OK - Fix #330
- fix some problems with paths containing spaces (regression since 1.1.11)- Fix #329

<a name="v1.2.0"></a>
### v1.2.0 - 2021-01-14
- experimental "modal mode" (or "vim mode") in broot. See https://dystroy.org/broot/vim_mode/
- fix mouse staying captured during external app execution - Fix #325

<a name="v1.1.11"></a>
### v1.1.11 - 2021-01-07
- fix handling of rules starting with '/' in the global gitignore - Fix #321
- alt-c now mapped to the new :copy_line verb which, when in tree, puts the selected path in the clipboard and, when in text preview, puts the selected text line in the clipboard - Fix #322
- it's possible to define verb execution patterns as arrays instead of simple strings, to avoid having to escape quotes - Fix #319

<a name="v1.1.10"></a>
### v1.1.10 - 2020-12-24
broot now accepts both TOML and Hjson files for configuration. Default is Hjson. I explain the change [here](https://dystroy.org/blog/hjson-in-broot/)

<a name="v1.0.9"></a>
### v1.0.9 - 2020-12-19
- fix handling on quotes in configured verbs - Fix #316

<a name="v1.0.8"></a>
### v1.0.8 - 2020-12-01
- when sizes are displayed (eg on `br -s`), show size of root line and root filesystem info
- modified size cache management makes some size computations faster
- sizes (and dates and counts) are progressively displayed

<a name="v1.0.7"></a>
### v1.0.7 - 2020-11-27
* :previous_same_depth and :next_same_depth internals
* in kitty terminal, image preview is high definition

<a name="v1.0.6"></a>
### v1.0.6 - 2020-11-19
* optional icons, thanks to @asdf8dfafjk (@fiAtcBr on Miaou) - See https://dystroy.org/broot/icons
* dev.log renamed into broot.log
* `:line_up` and `:line_down` accept an optional count as argument - Fix #301

<a name="v1.0.5"></a>
### v1.0.5 - 2020-11-05
* in case of IO error when previewing a file, display the error instead of quitting
* fix regression related to display of texts with characters taking several columns
* preview now supports opening system files with size 0 (eg /proc "files")

<a name="v1.0.4"></a>
### v1.0.4 - 2020-10-22
* don't use absolute paths for built-in verbs
* fix freeze on circular symlink chains
* `:filesystems` (alias `:fs`) display all mounted filesystems in a filtrable view. You can enter to browse at the mount point (unix only for now)
* `:toggle_root_fs` (alias `:rfs`) toogles showing information on the filesystem of the current directory
* filesystem information (mainly size and usage) related to the current filesystem displayed in whale-spotting mode

<a name="v1.0.3"></a>
### v1.0.3 - 2020-10-07
* change the syntax of cols_order in conf
* fix left key moving the cursor to start of input (instead of just one char left)

<a name="v1.0.2"></a>
### v1.0.2 - 2020-10-04
* `cr/` patterns search on file content with regular expressions
* search modes and their prefixes listed in help

<a name="v1.0.1"></a>
### v1.0.1 - 2020-09-30
* don't apply .gitignore files (including the global one) when not in a git repository - Fix #274
* the "clipboard" optional feature adds:
	* the `:copy_path` verb which copies the selected path to the clipboard (mapped to alt-c)
	* the `:input_paste` verb which inserts the clipboard content in the input (mapped to ctrl-v)
* it's now possible to define verbs executing sequences of commands - Fix #277
* fix opening of link of link - Fix #280
* broot is now compatible with Android, you can use it on Termux for example
* help page lists all optional features enabled at compilation
* list of verbs in help page is searchable

<a name="v1.0.0"></a>
### v1.0.0 - 2020-09-01
- nothing new, which is better when you want to call your software stable

<a name="v0.20.3"></a>
### v0.20.3 - 2020-08-23
- fix a few problems with tabulation rendering
- fix a few cases of files being called "huge" while they're only very big

<a name="v0.20.2"></a>
### v0.20.2 - 2020-08-18
- fix esc key not removing the filter in text preview

<a name="v0.20.1"></a>
### v0.20.1 - 2020-08-18
- completion of the "client-server" feature (see client-server.md)
- the tree tries to keep the selection when you remove a filter using the esc key
- :focus now has a shortcut for when a file is selected too: ctrl-f
- show_selection_mark preference in config (mostly for cases the background isn't clear enough)
- **breaking change:** The working directory of external processes launched by broot isn't set anymore by default.
If you want it to be changed, add `set_working_dir = true` to the verb definition.

<a name="v0.20.0"></a>
### v0.20.0 - 2020-08-16
- it's now possible to launch a terminal as sub process from broot (and be back to broot on exit)
- the selected directory is now the working dir for subprocess launched from broot
- images are previewed as such
- :preview_binay, :preview_text, and :preview_image verbs allow the choice of previewing mode
- fix a possible crash in previewed files on displaying fuzzy pattern matches

<a name="v0.19.4"></a>
### v0.19.4 - 2020-07-31
- don't install the br shell function when --outcmd is set or $BR_INSTALL is "no" - Fix #265
- more relevant status hints - Fix #261

<a name="v0.19.3"></a>
### v0.19.3 - 2020-07-27
- refined search in preview interaction (see blog https://dystroy.org/blog/broot-c-search/)

<a name="v0.19.2"></a>
### v0.19.2 - 2020-07-26
- "client-server" feature (see client-server.md)
- preview's pattern is kept when changing file
- selected line in preview, interesting when removing the pattern (to see what's around a match)
- faster availability of huge files in preview
- search in preview now interrupted by key events (just like the trees)
- a content search in a tree is propagated as a regex in a preview on :panel_right (ctrl-right)
- syntax theme choice in conf.toml
- {line} in a verb execution pattern refers to the line number

<a name="v0.19.1"></a>
### v0.19.1 - 2020-07-17
Force trimming root when searching (trimming root when not searching is no longer the default)

<a name="v0.19.0"></a>
### v0.19.0 - 2020-07-16
#### Major feature: the preview panel
Hit ctrl-right when a file is selected and you get the preview.

<a name="v0.18.6"></a>
### v0.18.6 - 2020-07-10
- `[ext-colors]` section in config
- a few minor fixes and changes

<a name="v0.18.5"></a>
### v0.18.5 - 2020-07-05
- git status takes into accout overloading of enter and alt-enter
- a few minor fixes and changes

<a name="v0.18.4"></a>
### v0.18.4 - 2020-07-02
- `--git-status` launch option
- fix rendering on windows

<a name="v0.18.3"></a>
### v0.18.3 - 2020-06-30
Faster rendering (0.18.2 made it slower on some terminals)

<a name="v0.18.2"></a>
### v0.18.2 - 2020-06-29
Remove flickering

<a name="v0.18.1"></a>
### v0.18.1 - 2020-06-28
Column order is now configurable - Fix #127

<a name="v0.18.0"></a>
### v0.18.0 - 2020-06-26

#### Major change: Recursive last modified date computation
The date of directories is now the modification date of the last modified inner file, whatever its depth. This is computed in the background and doesn't slow your navigation.

#### Major change: Sort mode
Size can now be displayed out of sort mode, which concerns either size or dates.

There are new launch arguments:
* `--sort-by-count` : sort by number of files in directories
* `--sort-by-date` : sort by dates, taking content into account (make it easy to find deep recent files)
* `--sort-by-size` : sort by size
* `--whale-spotting` or `-w` : "whale spotting" mode (sort by size and show all files)

The `-s` launch argument now works similarly to -d or -p : it doesn't activate a sort mode but activates showing the sizes. `-s` has been replaced with `-w`.

Similarly new verbs have been defined:
* `:toggle_counts`, with shortcut `counts` shows the number of files in directories
* `:toggle_sizes`, with shortcut `sizes` shows the sizes of files and directories
* `:sort_by_count` has for shortcut `sc`
* `:sort_by_date` has for shortcut `sd`
* `:sort_by_size` has `ss` as shortcut
* `:no_sort` removes the current sort mode, if any

<a name="v0.17.0"></a>
### v0.17.0 - 2020-06-21
#### Major feature: keep broot open behind terminal editors
If you now open vi or emacs from broot with `leave_broot = false` you should
be back in broot after you quit the editor - Fix #34 - Fix #144 - Fix #158
#### Minor changes:
- it's possible to define input edition shortcuts - Fix #235
- MacOS: config directory for new install is ~/.config/broot - Fix #103

<a name="v0.16.0"></a>
### v0.16.0 - 2020-06-20
#### Major feature: composite patterns
It's now possible to use logical operators on patterns.

For example:
* `!/txt$/` : files whose name doesn't end in "txt"
* `carg|c/carg` : files whose name or content has "carg"
* `(json|xml)&c/test` : files containing "test" and whose name fuzzily contains either "json" or "xml"
The document contains other examples and precisions.

<a name="v0.15.1"></a>
### v0.15.1 - 2020-06-12
- fix some problems related to relative paths in built in cp and mv

<a name="v0.15.0"></a>
### v0.15.0 - 2020-06-12
#### Major feature: new input syntax - Breaking Change
New search modes (see https://dystroy.org/broot/input/#the-filtering-pattern) :
	- fuzzy or regex on sub-paths (the path starting from the displayed root)
	- search in file content
- it's possible to configure how search modes are selected in config
- search pattern characters can be escaped with a '\'
#### Minor changes:
- tab goes to next direct match when there's no verb in input - Fix #234
- `:open_stay_filter` to be used if you want to keep the pattern when you navigate - Fix #240
- mouse capture can be disabled with `capture_mouse = false` - Fix #238
- several small fixes

<a name="v0.14.2"></a>
### v0.14.2 - 2020-06-01
- `apply_to` verb property - fix #237

<a name="v0.14.1"></a>
### v0.14.1 - 2020-05-29
- fix uppercase letters ignored in input field

<a name="v0.14.0"></a>
### v0.14.0 - 2020-05-29
#### Major feature: `:focus` verb
This verb can be called, and parameterized, with a path as argument, which makes it possible to have a shortcut to a specific location.
As a result, the specific `:focus_user_home` and `:focus_root` verbs have been removed (`:focus ~` works on all OS).
#### Major feature: panels!
There are three major ways to open a new panel:
- by using ctrl-left or ctrl-right, which can also be used to navigate between panels
- when a verb is edited, by using ctrl-p, which opens a panel which on closure will fill the argument
- by using any verb with a bang. For example `:focus! ~` or `:!help`
When you have two panels, you may use some new verbs like :copy_to_panel which copies the selection to the selected location in the other panel.
Many new verbs and functions are related to panels but broot can still be used exactly as before without using panels.
#### Major feature: autocompletion
Using the Tab key you can complete verbs or paths
#### Major feature: special paths
Some paths can be handled in a specific way. Fix #205 and #208
You can for example decide that some slow disk shouldn't be entered automatically
#### Minor changes:
- date/time format configurable - Fix #229
- esc doesn't quit broot anymore (by popular demand)
It's probably a good idea to remove your existing conf.toml file so that broot creates a brand new one with suggestions of shortcuts.

<a name="v0.13.6"></a>
### v0.13.6 - 2020-04-08
- ignore diacritics in searches - Fix #216

<a name="v0.13.5"></a>
### v0.13.5 - 2020-03-28
- right key open directory, left key gets back (when input is empty) - Fix #179
- replace ~ in path arguments with user home dir - Fix #211
- use $XDG_CONFIG_HOME/git/ignore when the normal core.excludesFile git setting is missing - Fix #212
- add a man page to archive - Fix #165

<a name="v0.13.4"></a>
### v0.13.4 - 2020-03-13
- support for an arg made of an optional group - Fix #210

<a name="v0.13.3"></a>
### v0.13.3 - 2020-02-27
- fix a compilation problem related to dependency (termimad) version

<a name="v0.13.2"></a>
### v0.13.2 - 2020-02-16
- fix -i and -I launch arguments being ignored (fix #202)

<a name="v0.13.1"></a>
### v0.13.1 - 2020-02-08
- fix background not always removed when skin requires no background (Fix #194)

<a name="v0.13.0"></a>
### v0.13.0 - 2020-02-05
#### Major change: git related features
- `:show_git_file_info` compute git repo statistics and file statuses. Statistics are computed in background and cached.
- `:git_diff` verb launching `git diff {file}`
- `:git_status` filter files to show only the ones which are relevant for `git status` (warning: slow on big repositories)
#### Major change: rewamped launch flags
Several new launch flags have been added, mostly doing the opposite of previous ones (eg `-S` negates `-s`) and a new entry in the conf.toml lets you define default flags (which can be overriden by the ones you pass on the command line).
Do `br --help` to view the comp