Skip to content

Commit

Permalink
refactor: factor out remaining options from options.h
Browse files Browse the repository at this point in the history
  • Loading branch information
mhx committed Aug 14, 2024
1 parent 1da9419 commit eba567c
Show file tree
Hide file tree
Showing 29 changed files with 312 additions and 141 deletions.
2 changes: 1 addition & 1 deletion cmake/libdwarfs.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ add_library(
src/logger.cpp
src/mmap.cpp
src/option_map.cpp
src/options.cpp
src/os_access_generic.cpp
src/pcm_sample_transformer.cpp
src/performance_monitor.cpp
Expand Down Expand Up @@ -92,6 +91,7 @@ add_library(
src/writer/compression_metadata_requirements.cpp
src/writer/console_writer.cpp
src/writer/entry_factory.cpp
src/writer/file_order_options.cpp
src/writer/filesystem_block_category_resolver.cpp
src/writer/filesystem_writer.cpp
src/writer/filter_debug.cpp
Expand Down
2 changes: 1 addition & 1 deletion include/dwarfs/history.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

#include <nlohmann/json.hpp>

#include <dwarfs/options.h>
#include <dwarfs/history_config.h>

namespace dwarfs {

Expand Down
30 changes: 30 additions & 0 deletions include/dwarfs/history_config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* vim:set ts=2 sw=2 sts=2 et: */
/**
* \author Marcus Holland-Moritz ([email protected])
* \copyright Copyright (c) Marcus Holland-Moritz
*
* This file is part of dwarfs.
*
* dwarfs is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* dwarfs is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with dwarfs. If not, see <https://www.gnu.org/licenses/>.
*/

#pragma once

namespace dwarfs {

struct history_config {
bool with_timestamps{false};
};

} // namespace dwarfs
5 changes: 2 additions & 3 deletions include/dwarfs/utility/rewrite_filesystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ namespace dwarfs {

class logger;

// TODO: move to writer namespace
struct rewrite_options;

namespace reader {

class filesystem_v2;
Expand All @@ -43,6 +40,8 @@ class filesystem_writer;

namespace utility {

struct rewrite_options;

void rewrite_filesystem(logger& lgr, dwarfs::reader::filesystem_v2 const& fs,
dwarfs::writer::filesystem_writer& writer,
dwarfs::writer::category_resolver const& cat_resolver,
Expand Down
43 changes: 43 additions & 0 deletions include/dwarfs/utility/rewrite_options.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/* vim:set ts=2 sw=2 sts=2 et: */
/**
* \author Marcus Holland-Moritz ([email protected])
* \copyright Copyright (c) Marcus Holland-Moritz
*
* This file is part of dwarfs.
*
* dwarfs is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* dwarfs is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with dwarfs. If not, see <https://www.gnu.org/licenses/>.
*/

#pragma once

#include <optional>
#include <string>
#include <unordered_set>
#include <vector>

#include <dwarfs/history_config.h>

namespace dwarfs::utility {

struct rewrite_options {
bool recompress_block{false};
bool recompress_metadata{false};
std::unordered_set<std::string> recompress_categories;
bool recompress_categories_exclude{false};
bool enable_history{true};
std::optional<std::vector<std::string>> command_line_arguments;
history_config history;
};

} // namespace dwarfs::utility
43 changes: 43 additions & 0 deletions include/dwarfs/writer/file_order_options.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/* vim:set ts=2 sw=2 sts=2 et: */
/**
* \author Marcus Holland-Moritz ([email protected])
* \copyright Copyright (c) Marcus Holland-Moritz
*
* This file is part of dwarfs.
*
* dwarfs is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* dwarfs is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with dwarfs. If not, see <https://www.gnu.org/licenses/>.
*/

#pragma once

#include <iosfwd>

namespace dwarfs::writer {

// TODO: rename? -> inode_order_mode / fragment_order_mode
enum class file_order_mode { NONE, PATH, REVPATH, SIMILARITY, NILSIMSA };

// TODO: rename? -> inode_order_options / fragment_order_options
struct file_order_options {
static constexpr int const kDefaultNilsimsaMaxChildren{16384};
static constexpr int const kDefaultNilsimsaMaxClusterSize{16384};

file_order_mode mode{file_order_mode::NONE};
int nilsimsa_max_children{kDefaultNilsimsaMaxChildren};
int nilsimsa_max_cluster_size{kDefaultNilsimsaMaxClusterSize};
};

std::ostream& operator<<(std::ostream& os, file_order_mode mode);

} // namespace dwarfs::writer
23 changes: 16 additions & 7 deletions include/dwarfs/writer/filesystem_writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include <iosfwd>

#include <dwarfs/block_compressor.h>
#include <dwarfs/options.h>
#include <dwarfs/writer/fragment_category.h>

namespace dwarfs {
Expand All @@ -34,6 +33,8 @@ class thread_pool;

namespace writer {

struct filesystem_writer_options;

class writer_progress;

namespace internal {
Expand All @@ -44,12 +45,20 @@ class filesystem_writer_detail;

class filesystem_writer {
public:
filesystem_writer(
std::ostream& os, logger& lgr, thread_pool& pool, writer_progress& prog,
block_compressor const& schema_bc, block_compressor const& metadata_bc,
block_compressor const& history_bc,
filesystem_writer_options const& options = filesystem_writer_options(),
std::istream* header = nullptr);
filesystem_writer(std::ostream& os, logger& lgr, thread_pool& pool,
writer_progress& prog, block_compressor const& bc);

filesystem_writer(std::ostream& os, logger& lgr, thread_pool& pool,
writer_progress& prog, block_compressor const& schema_bc,
block_compressor const& metadata_bc,
block_compressor const& history_bc);

filesystem_writer(std::ostream& os, logger& lgr, thread_pool& pool,
writer_progress& prog, block_compressor const& schema_bc,
block_compressor const& metadata_bc,
block_compressor const& history_bc,
filesystem_writer_options const& options,
std::istream* header = nullptr);

~filesystem_writer();
filesystem_writer(filesystem_writer&&);
Expand Down
35 changes: 35 additions & 0 deletions include/dwarfs/writer/filesystem_writer_options.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/* vim:set ts=2 sw=2 sts=2 et: */
/**
* \author Marcus Holland-Moritz ([email protected])
* \copyright Copyright (c) Marcus Holland-Moritz
*
* This file is part of dwarfs.
*
* dwarfs is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* dwarfs is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with dwarfs. If not, see <https://www.gnu.org/licenses/>.
*/

#pragma once

#include <cstddef>

namespace dwarfs::writer {

struct filesystem_writer_options {
size_t max_queue_size{64 << 20};
size_t worst_case_block_size{4 << 20};
bool remove_header{false};
bool no_section_index{false};
};

} // namespace dwarfs::writer
2 changes: 1 addition & 1 deletion include/dwarfs/writer/fragment_order_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include <string>
#include <string_view>

#include <dwarfs/options.h>
#include <dwarfs/writer/file_order_options.h>

namespace dwarfs::writer {

Expand Down
43 changes: 43 additions & 0 deletions include/dwarfs/writer/inode_options.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/* vim:set ts=2 sw=2 sts=2 et: */
/**
* \author Marcus Holland-Moritz ([email protected])
* \copyright Copyright (c) Marcus Holland-Moritz
*
* This file is part of dwarfs.
*
* dwarfs is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* dwarfs is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with dwarfs. If not, see <https://www.gnu.org/licenses/>.
*/

#pragma once

#include <cstddef>
#include <memory>
#include <optional>
#include <string>

#include <dwarfs/writer/categorized_option.h>
#include <dwarfs/writer/file_order_options.h>

namespace dwarfs::writer {

class categorizer_manager;

struct inode_options {
std::optional<size_t> max_similarity_scan_size;
std::shared_ptr<writer::categorizer_manager> categorizer_mgr;
writer::categorized_option<file_order_options> fragment_order{
file_order_options()};
};

} // namespace dwarfs::writer
4 changes: 2 additions & 2 deletions include/dwarfs/writer/scanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@

namespace dwarfs {

struct scanner_options;

class file_access;
class filesystem_writer;
class logger;
Expand All @@ -39,6 +37,8 @@ class thread_pool;

namespace writer {

struct scanner_options;

class entry_filter;
class entry_transformer;
class entry_factory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,58 +22,20 @@
#pragma once

#include <cstddef>
#include <cstdint>
#include <functional>
#include <iosfwd>
#include <memory>
#include <optional>
#include <string>
#include <type_traits>
#include <unordered_set>
#include <vector>

#include <dwarfs/file_stat.h>
#include <dwarfs/writer/categorized_option.h>
#include <dwarfs/history_config.h>
#include <dwarfs/writer/inode_options.h>

namespace dwarfs {
namespace dwarfs::writer {

namespace writer {

class categorizer_manager;
class entry_interface;

} // namespace writer

struct history_config {
bool with_timestamps{false};
};

struct filesystem_writer_options {
size_t max_queue_size{64 << 20};
size_t worst_case_block_size{4 << 20};
bool remove_header{false};
bool no_section_index{false};
};

// TODO: rename
enum class file_order_mode { NONE, PATH, REVPATH, SIMILARITY, NILSIMSA };

// TODO: rename
struct file_order_options {
static constexpr int const kDefaultNilsimsaMaxChildren{16384};
static constexpr int const kDefaultNilsimsaMaxClusterSize{16384};

file_order_mode mode{file_order_mode::NONE};
int nilsimsa_max_children{kDefaultNilsimsaMaxChildren};
int nilsimsa_max_cluster_size{kDefaultNilsimsaMaxClusterSize};
};

struct inode_options {
std::optional<size_t> max_similarity_scan_size;
std::shared_ptr<writer::categorizer_manager> categorizer_mgr;
writer::categorized_option<file_order_options> fragment_order{
file_order_options()};
};

struct scanner_options {
std::optional<std::string> file_hash_algorithm{"xxh3-128"};
std::optional<file_stat::uid_type> uid;
Expand Down Expand Up @@ -104,16 +66,4 @@ struct scanner_options {
history_config history;
};

struct rewrite_options {
bool recompress_block{false};
bool recompress_metadata{false};
std::unordered_set<std::string> recompress_categories;
bool recompress_categories_exclude{false};
bool enable_history{true};
std::optional<std::vector<std::string>> command_line_arguments;
history_config history;
};

std::ostream& operator<<(std::ostream& os, file_order_mode mode);

} // namespace dwarfs
} // namespace dwarfs::writer
Loading

0 comments on commit eba567c

Please sign in to comment.