mirror of
https://github.com/martinvonz/jj.git
synced 2024-12-26 14:00:51 +00:00
refactor(jj-lib): remove nightly_shims gunk
Summary: Now that we have Rust 1.71.0 at our fingertips, the `map_first_last` feature has been stabilized. That means we can get rid of the `jj-lib` build script and also the `nightly_shims` module. Signed-off-by: Austin Seipp <aseipp@pobox.com> Change-Id: Ibb5ce3258818a2de670763fbbaf3c2e7
This commit is contained in:
parent
8cb429d065
commit
017ce851b4
6 changed files with 7 additions and 144 deletions
23
lib/build.rs
23
lib/build.rs
|
@ -1,23 +0,0 @@
|
||||||
// Copyright 2020 The Jujutsu Authors
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// https://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
fn main() -> std::io::Result<()> {
|
|
||||||
println!("cargo:rerun-if-changed=build.rs");
|
|
||||||
|
|
||||||
if let Some(true) = version_check::supports_feature("map_first_last") {
|
|
||||||
println!("cargo:rustc-cfg=feature=\"map_first_last\"");
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
|
@ -40,11 +40,6 @@ use crate::file_util::persist_content_addressed_temp_file;
|
||||||
use crate::index::{
|
use crate::index::{
|
||||||
HexPrefix, Index, IndexStore, IndexWriteError, MutableIndex, PrefixResolution, ReadonlyIndex,
|
HexPrefix, Index, IndexStore, IndexWriteError, MutableIndex, PrefixResolution, ReadonlyIndex,
|
||||||
};
|
};
|
||||||
#[cfg(not(feature = "map_first_last"))]
|
|
||||||
// This import is used on Rust 1.61, but not on recent version.
|
|
||||||
// TODO: Remove it when our MSRV becomes recent enough.
|
|
||||||
#[allow(unused_imports)]
|
|
||||||
use crate::nightly_shims::BTreeSetExt;
|
|
||||||
use crate::op_store::OperationId;
|
use crate::op_store::OperationId;
|
||||||
use crate::operation::Operation;
|
use crate::operation::Operation;
|
||||||
use crate::revset::{ResolvedExpression, Revset, RevsetEvaluationError};
|
use crate::revset::{ResolvedExpression, Revset, RevsetEvaluationError};
|
||||||
|
|
|
@ -19,7 +19,6 @@ use std::collections::{BTreeMap, HashSet};
|
||||||
|
|
||||||
use crate::backend::CommitId;
|
use crate::backend::CommitId;
|
||||||
use crate::default_index_store::{IndexEntry, IndexPosition};
|
use crate::default_index_store::{IndexEntry, IndexPosition};
|
||||||
use crate::nightly_shims::BTreeMapExt;
|
|
||||||
use crate::revset::{RevsetGraphEdge, RevsetGraphEdgeType};
|
use crate::revset::{RevsetGraphEdge, RevsetGraphEdgeType};
|
||||||
|
|
||||||
/// Given an iterator over some set of revisions, yields the same revisions with
|
/// Given an iterator over some set of revisions, yields the same revisions with
|
||||||
|
@ -122,7 +121,7 @@ impl<'revset, 'index> RevsetGraphIterator<'revset, 'index> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn next_index_entry(&mut self) -> Option<IndexEntry<'index>> {
|
fn next_index_entry(&mut self) -> Option<IndexEntry<'index>> {
|
||||||
if let Some(index_entry) = self.look_ahead.pop_last_value() {
|
if let Some(index_entry) = self.look_ahead.last_entry().map(|x| x.remove()) {
|
||||||
return Some(index_entry);
|
return Some(index_entry);
|
||||||
}
|
}
|
||||||
self.input_set_iter.next()
|
self.input_set_iter.next()
|
||||||
|
|
|
@ -22,8 +22,6 @@ use std::slice;
|
||||||
|
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
|
|
||||||
use crate::nightly_shims::BTreeMapExt;
|
|
||||||
|
|
||||||
pub fn find_line_ranges(text: &[u8]) -> Vec<Range<usize>> {
|
pub fn find_line_ranges(text: &[u8]) -> Vec<Range<usize>> {
|
||||||
let mut ranges = vec![];
|
let mut ranges = vec![];
|
||||||
let mut start = 0;
|
let mut start = 0;
|
||||||
|
@ -185,7 +183,7 @@ pub(crate) fn unchanged_ranges(
|
||||||
|
|
||||||
let max_occurrences = 100;
|
let max_occurrences = 100;
|
||||||
let mut left_histogram = Histogram::calculate(left, left_ranges, max_occurrences);
|
let mut left_histogram = Histogram::calculate(left, left_ranges, max_occurrences);
|
||||||
if *left_histogram.count_to_words.first_key().unwrap() > max_occurrences {
|
if *left_histogram.count_to_words.keys().next().unwrap() > max_occurrences {
|
||||||
// If there are very many occurrences of all words, then we just give up.
|
// If there are very many occurrences of all words, then we just give up.
|
||||||
return vec![];
|
return vec![];
|
||||||
}
|
}
|
||||||
|
@ -195,7 +193,11 @@ pub(crate) fn unchanged_ranges(
|
||||||
// the LCS.
|
// the LCS.
|
||||||
let mut uncommon_shared_words = vec![];
|
let mut uncommon_shared_words = vec![];
|
||||||
while !left_histogram.count_to_words.is_empty() && uncommon_shared_words.is_empty() {
|
while !left_histogram.count_to_words.is_empty() && uncommon_shared_words.is_empty() {
|
||||||
let left_words = left_histogram.count_to_words.pop_first_value().unwrap();
|
let left_words = left_histogram
|
||||||
|
.count_to_words
|
||||||
|
.first_entry()
|
||||||
|
.map(|x| x.remove())
|
||||||
|
.unwrap();
|
||||||
for left_word in left_words {
|
for left_word in left_words {
|
||||||
if right_histogram.word_to_positions.contains_key(left_word) {
|
if right_histogram.word_to_positions.contains_key(left_word) {
|
||||||
uncommon_shared_words.push(left_word);
|
uncommon_shared_words.push(left_word);
|
||||||
|
|
|
@ -43,7 +43,6 @@ pub mod local_backend;
|
||||||
pub mod lock;
|
pub mod lock;
|
||||||
pub mod matchers;
|
pub mod matchers;
|
||||||
pub mod merge;
|
pub mod merge;
|
||||||
pub mod nightly_shims;
|
|
||||||
pub mod op_heads_store;
|
pub mod op_heads_store;
|
||||||
pub mod op_store;
|
pub mod op_store;
|
||||||
pub mod operation;
|
pub mod operation;
|
||||||
|
|
|
@ -1,109 +0,0 @@
|
||||||
// Copyright 2023 The Jujutsu Authors
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// https://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
#![allow(missing_docs)]
|
|
||||||
|
|
||||||
#[cfg(feature = "map_first_last")]
|
|
||||||
pub trait BTreeMapExt<K, V> {
|
|
||||||
fn first_key(&self) -> Option<&K>;
|
|
||||||
fn last_key(&self) -> Option<&K>;
|
|
||||||
fn pop_first_value(&mut self) -> Option<V>;
|
|
||||||
fn pop_last_value(&mut self) -> Option<V>;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "map_first_last")]
|
|
||||||
impl<K: Ord + Clone, V> BTreeMapExt<K, V> for std::collections::BTreeMap<K, V> {
|
|
||||||
fn first_key(&self) -> Option<&K> {
|
|
||||||
self.keys().next()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn last_key(&self) -> Option<&K> {
|
|
||||||
self.keys().next_back()
|
|
||||||
}
|
|
||||||
fn pop_first_value(&mut self) -> Option<V> {
|
|
||||||
self.first_entry().map(|x| x.remove())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn pop_last_value(&mut self) -> Option<V> {
|
|
||||||
self.last_entry().map(|x| x.remove())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(not(feature = "map_first_last"))]
|
|
||||||
pub trait BTreeMapExt<K, V> {
|
|
||||||
fn first_key(&self) -> Option<&K>;
|
|
||||||
fn last_key(&self) -> Option<&K>;
|
|
||||||
fn pop_first_key(&mut self) -> Option<K>;
|
|
||||||
fn pop_last_key(&mut self) -> Option<K>;
|
|
||||||
fn pop_first_value(&mut self) -> Option<V>;
|
|
||||||
fn pop_last_value(&mut self) -> Option<V>;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(not(feature = "map_first_last"))]
|
|
||||||
impl<K: Ord + Clone, V> BTreeMapExt<K, V> for std::collections::BTreeMap<K, V> {
|
|
||||||
fn first_key(&self) -> Option<&K> {
|
|
||||||
self.keys().next()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn last_key(&self) -> Option<&K> {
|
|
||||||
self.keys().next_back()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn pop_first_key(&mut self) -> Option<K> {
|
|
||||||
let key = self.first_key()?;
|
|
||||||
let key = key.clone(); // ownership hack
|
|
||||||
Some(self.remove_entry(&key).unwrap().0)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn pop_last_key(&mut self) -> Option<K> {
|
|
||||||
let key = self.last_key()?;
|
|
||||||
let key = key.clone(); // ownership hack
|
|
||||||
Some(self.remove_entry(&key).unwrap().0)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn pop_first_value(&mut self) -> Option<V> {
|
|
||||||
let key = self.first_key()?;
|
|
||||||
let key = key.clone(); // ownership hack
|
|
||||||
Some(self.remove_entry(&key).unwrap().1)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn pop_last_value(&mut self) -> Option<V> {
|
|
||||||
let key = self.last_key()?;
|
|
||||||
let key = key.clone(); // ownership hack
|
|
||||||
Some(self.remove_entry(&key).unwrap().1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "map_first_last")]
|
|
||||||
pub trait BTreeSetExt<K> {}
|
|
||||||
|
|
||||||
#[cfg(not(feature = "map_first_last"))]
|
|
||||||
pub trait BTreeSetExt<K> {
|
|
||||||
fn last(&self) -> Option<&K>;
|
|
||||||
fn pop_last(&mut self) -> Option<K>;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(not(feature = "map_first_last"))]
|
|
||||||
impl<K: Ord + Clone> BTreeSetExt<K> for std::collections::BTreeSet<K> {
|
|
||||||
fn last(&self) -> Option<&K> {
|
|
||||||
self.iter().next_back()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn pop_last(&mut self) -> Option<K> {
|
|
||||||
#[allow(unstable_name_collisions)]
|
|
||||||
let key = self.last()?;
|
|
||||||
let key = key.clone(); // ownership hack
|
|
||||||
self.take(&key)
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in a new issue