Skip to content

Commit

Permalink
Fix apply-patch documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
nyurik committed Mar 17, 2024
1 parent b28dae4 commit 47cba84
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 18 deletions.
4 changes: 2 additions & 2 deletions docs/src/mbtiles-diff.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ insertions, and deletions as `NULL` values), for both the tile and metadata tabl

There is one exception: `agg_tiles_hash` metadata value will be renamed to `agg_tiles_hash_after_apply`, and a
new `agg_tiles_hash` will be generated for the diff file itself. This is done to avoid confusion when applying the diff
file to the original file, as the `agg_tiles_hash` value will be different after the diff is applied. The `apply-diff`
file to the original file, as the `agg_tiles_hash` value will be different after the diff is applied. The `apply-patch`
command will automatically rename the `agg_tiles_hash_after_apply` value back to `agg_tiles_hash` when applying the
diff.

Expand All @@ -18,7 +18,7 @@ diff.
mbtiles diff file1.mbtiles file2.mbtiles diff.mbtiles

# If diff.mbtiles is applied to file1.mbtiles, it will produce file2.mbtiles
mbtiles apply-diff file1.mbtiles diff.mbtiles file2a.mbtiles
mbtiles apply-patch file1.mbtiles diff.mbtiles file2a.mbtiles

# file2.mbtiles and file2a.mbtiles should now be the same
# Validate both files and see that their hash values are identical
Expand Down
7 changes: 4 additions & 3 deletions mbtiles/src/bin/mbtiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,12 @@ pub struct CopyArgs {
pub options: SharedCopyOpts,
/// Compare source file with this file, and only copy non-identical tiles to destination.
/// Use `mbtiles diff` as a more convenient way to generate this file.
/// It should be later possible to run `mbtiles apply-diff` to merge it in.
/// Use `mbtiles apply-patch` or `mbtiles copy --apply-patch` to apply the diff file.
#[arg(long, conflicts_with("apply_patch"))]
diff_with_file: Option<PathBuf>,
/// Compare source file with this file, and only copy non-identical tiles to destination.
/// It should be later possible to run `mbtiles apply-diff SRC_FILE DST_FILE` to get the same DIFF file.
/// Apply a patch file while copying src to dst.
/// Use `mbtiles diff` or `mbtiles copy --diff-with-file` to generate the patch file.
/// Use `mbtiles apply-patch` to apply the patch file in-place, without making a copy of the original.
#[arg(long, conflicts_with("diff_with_file"))]
apply_patch: Option<PathBuf>,
}
Expand Down
9 changes: 3 additions & 6 deletions mbtiles/src/copier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,8 @@ pub struct MbtilesCopier {
/// Bounding box to copy, in the format `min_lon,min_lat,max_lon,max_lat`. Can be used multiple times.
pub bbox: Vec<Bounds>,
/// Compare source file with this file, and only copy non-identical tiles to destination.
/// Use `mbtiles diff` as a more convenient way to generate this file.
/// It should be later possible to run `mbtiles apply-diff` to merge it in.
pub diff_with_file: Option<PathBuf>,
/// Compare source file with this file, and only copy non-identical tiles to destination.
/// It should be later possible to run `mbtiles apply-diff SRC_FILE DST_FILE` to get the same DIFF file.
/// Apply a patch file while copying src to dst.
pub apply_patch: Option<PathBuf>,
/// Skip generating a global hash for mbtiles validation. By default, `mbtiles` will compute `agg_tiles_hash` metadata value.
pub skip_agg_tiles_hash: bool,
Expand Down Expand Up @@ -183,9 +180,9 @@ impl MbtileCopierInt {
self.init_new_schema(&mut conn, src_type, dst_type).await?;
}

// SAFETY: This must be scoped to make sure the handle is dropped before we continue using conn
// Make sure not to execute any other queries while the handle is locked
{
// SAFETY: This must be scoped to make sure the handle is dropped before we continue using conn
// Make sure not to execute any other queries while the handle is locked
let mut handle_lock = conn.lock_handle().await?;
let handle = handle_lock.as_raw_handle().as_ptr();

Expand Down
5 changes: 2 additions & 3 deletions mbtiles/src/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ use crate::{invert_y_value, Mbtiles};
/// Metadata key for the aggregate tiles hash value
pub const AGG_TILES_HASH: &str = "agg_tiles_hash";

/// Metadata key for a diff file,
/// describing the eventual [`AGG_TILES_HASH`] value once the diff is applied
/// Metadata key for a diff file, describing the eventual [`AGG_TILES_HASH`] value of the resulting tileset once the diff is applied
pub const AGG_TILES_HASH_AFTER_APPLY: &str = "agg_tiles_hash_after_apply";

#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, EnumDisplay, Serialize)]
Expand Down Expand Up @@ -116,7 +115,7 @@ impl Mbtiles {
tested_zoom = r.zoom_level.unwrap_or(-1);
}

// Afterwards, iterate over tiles in all allowed zooms and check for consistency
// Afterward, iterate over tiles in all allowed zooms and check for consistency
for z in tilejson.minzoom.unwrap_or(0)..=tilejson.maxzoom.unwrap_or(18) {
if i64::from(z) == tested_zoom {
continue;
Expand Down
6 changes: 2 additions & 4 deletions mbtiles/tests/copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use std::str::from_utf8;
use ctor::ctor;
use insta::{allow_duplicates, assert_snapshot};
use itertools::Itertools as _;
use log::info;
use martin_tile_utils::xyz_to_bbox;
use mbtiles::AggHashType::Verify;
use mbtiles::IntegrityCheckType::Off;
Expand Down Expand Up @@ -105,14 +104,14 @@ async fn open(file: &str) -> MbtResult<(Mbtiles, SqliteConnection)> {

/// Run [`MbtilesCopier`], the first two params are source and destination [`Mbtiles`] refs, the rest are optional (key => val)* params.
macro_rules! copy {
($src_path:expr, $dst_path:expr $( , $key:tt => $val:expr )* $(,)?) => {{
($src_path:expr, $dst_path:expr $( , $key:tt => $val:expr )* $(,)?) => {
MbtilesCopier {
src_file: $src_path,
dst_file: $dst_path
$(, $key : $val)*,
..Default::default()
}.run().await.unwrap()
}};
};
}

/// Same as the copy! macro, but with the result dumped.
Expand Down Expand Up @@ -509,7 +508,6 @@ async fn patch_on_copy(
let v2 = v2_type.map_or("dflt", shorten);
let prefix = format!("{v1}+{dif}={v2}");

info!("TEST: Compare v1 with v2, and copy anything that's different (i.e. mathematically: v2-v1=diff)");
let (v2_mbt, mut v2_cn) = open!(patch_on_copy, "{prefix}__v2");
copy! {
databases.path("v1", v1_type),
Expand Down

0 comments on commit 47cba84

Please sign in to comment.