Mercurial > public > mercurial-scm > hg-stable
comparison rust/hg-core/src/dirstate_tree/status.rs @ 49550:363923bd51cd stable
dirstate-v2: hash the source of the ignore patterns as well
Fixes the test introduced in the last changeset. This caused the hash
to change, which means that the check in the test had to be adapted.
Since this hash is only done as a caching mechanism, invalidation does
not pose any backwards compatibility issues.
author | Rapha?l Gom?s <rgomes@octobus.net> |
---|---|
date | Wed, 02 Nov 2022 12:05:34 +0100 |
parents | 8ee3889bab92 |
children | c52435820bbd 18282cf18aa2 |
comparison
equal
deleted
inserted
replaced
49549:ca19335e86e5 | 49550:363923bd51cd |
---|---|
8 use crate::dirstate_tree::dirstate_map::NodeRef; | 8 use crate::dirstate_tree::dirstate_map::NodeRef; |
9 use crate::dirstate_tree::on_disk::DirstateV2ParseError; | 9 use crate::dirstate_tree::on_disk::DirstateV2ParseError; |
10 use crate::matchers::get_ignore_function; | 10 use crate::matchers::get_ignore_function; |
11 use crate::matchers::Matcher; | 11 use crate::matchers::Matcher; |
12 use crate::utils::files::get_bytes_from_os_string; | 12 use crate::utils::files::get_bytes_from_os_string; |
13 use crate::utils::files::get_bytes_from_path; | |
13 use crate::utils::files::get_path_from_bytes; | 14 use crate::utils::files::get_path_from_bytes; |
14 use crate::utils::hg_path::HgPath; | 15 use crate::utils::hg_path::HgPath; |
15 use crate::BadMatch; | 16 use crate::BadMatch; |
16 use crate::DirstateStatus; | 17 use crate::DirstateStatus; |
17 use crate::HgPathBuf; | 18 use crate::HgPathBuf; |
64 let (ignore_fn, warnings, changed) = match dmap.dirstate_version { | 65 let (ignore_fn, warnings, changed) = match dmap.dirstate_version { |
65 DirstateVersion::V1 => { | 66 DirstateVersion::V1 => { |
66 let (ignore_fn, warnings) = get_ignore_function( | 67 let (ignore_fn, warnings) = get_ignore_function( |
67 ignore_files, | 68 ignore_files, |
68 &root_dir, | 69 &root_dir, |
69 &mut |_pattern_bytes| {}, | 70 &mut |_source, _pattern_bytes| {}, |
70 )?; | 71 )?; |
71 (ignore_fn, warnings, None) | 72 (ignore_fn, warnings, None) |
72 } | 73 } |
73 DirstateVersion::V2 => { | 74 DirstateVersion::V2 => { |
74 let mut hasher = Sha1::new(); | 75 let mut hasher = Sha1::new(); |
75 let (ignore_fn, warnings) = get_ignore_function( | 76 let (ignore_fn, warnings) = get_ignore_function( |
76 ignore_files, | 77 ignore_files, |
77 &root_dir, | 78 &root_dir, |
78 &mut |pattern_bytes| hasher.update(pattern_bytes), | 79 &mut |source, pattern_bytes| { |
80 // If inside the repo, use the relative version to | |
81 // make it deterministic inside tests. | |
82 // The performance hit should be negligible. | |
83 let source = source | |
84 .strip_prefix(&root_dir) | |
85 .unwrap_or(source); | |
86 let source = get_bytes_from_path(source); | |
87 | |
88 let mut subhasher = Sha1::new(); | |
89 subhasher.update(pattern_bytes); | |
90 let patterns_hash = subhasher.finalize(); | |
91 | |
92 hasher.update(source); | |
93 hasher.update(b" "); | |
94 hasher.update(patterns_hash); | |
95 hasher.update(b"\n"); | |
96 }, | |
79 )?; | 97 )?; |
80 let new_hash = *hasher.finalize().as_ref(); | 98 let new_hash = *hasher.finalize().as_ref(); |
81 let changed = new_hash != dmap.ignore_patterns_hash; | 99 let changed = new_hash != dmap.ignore_patterns_hash; |
82 dmap.ignore_patterns_hash = new_hash; | 100 dmap.ignore_patterns_hash = new_hash; |
83 (ignore_fn, warnings, Some(changed)) | 101 (ignore_fn, warnings, Some(changed)) |