navid/veins / commit
639918f360ca
Navid M <navidmomtahen@gmail.com> · 2026-11-28
parents: 411f167e3756
Browse files at this commit · Download source
--- a/xveins/src/auth/auth.h+++ b/xveins/src/auth/auth.h@@ -14,10 +14,6 @@ constexpr std::uint8_t ROLE_READ = 1; constexpr std::uint8_t ROLE_WRITE = 2; constexpr std::uint8_t ROLE_UNKNOWN = 255;--// ----------------------------------------------------------------------------// Client keys-// --------------------------------------------------------------------------- struct Key { std::string name;--- a/xveins/src/cli/cli.cpp+++ b/xveins/src/cli/cli.cpp@@ -1868,10 +1868,6 @@ return 0; } -// ----------------------------------------------------------------------------// inf-// ---------------------------------------------------------------------------- struct ExtStat { std::string ext; std::uint64_t files = 0;--- a/xveins/src/cli/net_commands.cpp+++ b/xveins/src/cli/net_commands.cpp@@ -301,6 +301,29 @@ progress(++done); } return std::move(walker.object_out);+}++/**+ * Ask the server which objects it already has, so a push only transfers the difference.+ * If a query fails, send everything to preserve correctness.+ */+std::vector<Id> missing_objects(proto::Client& client, const std::vector<Id>& objects) {+ constexpr std::size_t BATCH = 100000;+ std::vector<Id> missing;+ missing.reserve(objects.size());+ for (std::size_t offset = 0; offset < objects.size(); offset += BATCH) {+ const std::size_t end = std::min(offset + BATCH, objects.size());+ std::vector<Id> batch(objects.begin() + static_cast<std::ptrdiff_t>(offset),+ objects.begin() + static_cast<std::ptrdiff_t>(end));+ std::vector<std::uint8_t> bits;+ if (!client.have_query(batch, bits))+ return objects;+ for (std::size_t i = 0; i < batch.size(); ++i) {+ if (i >= bits.size() || bits[i] == 0)+ missing.push_back(batch[i]);+ }+ }+ return missing; } bool send_chunks(proto::Client& client, const fs::path& root, const std::vector<Id>& chunks) {@@ -400,10 +423,6 @@ } } // namespace--// ----------------------------------------------------------------------------// remote-// --------------------------------------------------------------------------- int remote_run(const std::vector<std::string>& args) { const std::string sub = arg_at(args, 2);@@ -955,11 +974,16 @@ } bool pushed = false; if (!objects.empty()) {- Progress progress("pushing objects", objects.size());- pushed =- client->push_objects(root, objects, [&](std::size_t done) { progress.update(done); });- if (pushed)- progress.finish();+ const std::vector<Id> missing = missing_objects(*client, objects);+ if (missing.empty()) {+ pushed = true;+ } else {+ Progress progress("pushing objects", missing.size());+ pushed = client->push_objects(root, missing,+ [&](std::size_t done) { progress.update(done); });+ if (pushed)+ progress.finish();+ } } else { pushed = client->push_objects(root, objects); }--- a/xveins/src/merge/merge.cpp+++ b/xveins/src/merge/merge.cpp@@ -731,10 +731,6 @@ return map; } -// ----------------------------------------------------------------------------// Tree merge-// ---------------------------------------------------------------------------- struct TreeTerm { bool positive = true; bool present = false;--- a/xveins/src/store/store.h+++ b/xveins/src/store/store.h@@ -13,14 +13,12 @@ namespace vn { -// Called when a promised chunk is missing. Returns true when the object was-// fetched and written to a pack.+/**+ * Called when a promised chunk is missing. Returns true when the object was+ * fetched and written to a pack.+ */ using PromisorFetcher = std::function<bool(const fs::path&, const Id&)>; void set_promisor_fetcher(PromisorFetcher fetcher);--// ----------------------------------------------------------------------------// Repository layout-// --------------------------------------------------------------------------- fs::path veins_dir(const fs::path& root); fs::path packs_dir(const fs::path& root);@@ -36,10 +34,6 @@ std::optional<fs::path> discover_repo(const fs::path& start); Result<fs::path> init_repo(const fs::path& path);--// ----------------------------------------------------------------------------// Pack and index files-// --------------------------------------------------------------------------- struct PackRecord { Id id{};@@ -95,10 +89,6 @@ int write_pack(const fs::path& root, const std::vector<RawObject>& objects, std::uint64_t limit, int level = 3); int repack_repository(const fs::path& root, int level, bool verbose);--// ----------------------------------------------------------------------------// Store-// --------------------------------------------------------------------------- struct Loc { std::size_t pack_index = 0;@@ -167,10 +157,6 @@ std::vector<StoreHandle> handles_; std::map<Id, bool> tree_conflict_cache_; };--// ----------------------------------------------------------------------------// Writer and transactions-// --------------------------------------------------------------------------- class Writer { public:@@ -279,10 +265,6 @@ bool mark_native(const fs::path& root, const Id& id); std::vector<Id> load_native(const fs::path& root); bool is_native(const std::vector<Id>& native, const Id& id);--// ----------------------------------------------------------------------------// fsck-// --------------------------------------------------------------------------- int fsck_repository(const fs::path& root, bool verbose); --- a/xveins/src/worktree/worktree.cpp+++ b/xveins/src/worktree/worktree.cpp@@ -129,9 +129,8 @@ const auto target = r.id(); if (!size || !mtime || !inode || !kind || !executable || !target) break;- cache.entries.push_back(- CacheEntry{std::move(*path), *size, *mtime, *inode, *kind, *executable != 0, *target,- trusted});+ cache.entries.push_back(CacheEntry{std::move(*path), *size, *mtime, *inode, *kind,+ *executable != 0, *target, trusted}); } std::stable_sort(cache.entries.begin(), cache.entries.end(), [](const CacheEntry& a, const CacheEntry& b) {@@ -411,8 +410,8 @@ entries.push_back(TreeEntry{plan.name, KIND_CONFLICT, *plan.target}); break; case PlanKind::Directory: {- auto child = build_dir(txn, root, plan.rel, plan.child_old, local, attributes, cache_valid,- cache, new_cache, now_ms, state, depth + 1);+ auto child = build_dir(txn, root, plan.rel, plan.child_old, local, attributes,+ cache_valid, cache, new_cache, now_ms, state, depth + 1); if (state.failed) return std::nullopt; if (child)@@ -439,9 +438,8 @@ new_cache.push_back(CacheEntry{plan.rel, plan.info.size, plan.info.mtime_ns, plan.info.inode, plan.info.kind, plan.executable, *plan.target, plan.trusted});- entries.push_back(TreeEntry{plan.name,- plan.executable ? KIND_EXECUTABLE : KIND_FILE,- *plan.target});+ entries.push_back(+ TreeEntry{plan.name, plan.executable ? KIND_EXECUTABLE : KIND_FILE, *plan.target}); break; } }@@ -456,10 +454,6 @@ } return txn.add_object(TYPE_TREE, std::move(*body)); }--// ----------------------------------------------------------------------------// Checkout helpers-// --------------------------------------------------------------------------- struct WalkEntry { std::string path;@@ -758,14 +752,13 @@ cache.reserve(entries.size()); const std::int64_t now_ms = unix_now_millis(); for (const auto& entry : entries) {- if (entry.kind != KIND_FILE && entry.kind != KIND_EXECUTABLE &&- entry.kind != KIND_SYMLINK)+ if (entry.kind != KIND_FILE && entry.kind != KIND_EXECUTABLE && entry.kind != KIND_SYMLINK) continue; const auto info = stat_path(root / path_from_bytes(entry.path)); if (!info) continue;- cache.push_back(CacheEntry{entry.path, info->size, info->mtime_ns, info->inode,- info->kind, info->executable, entry.target, true});+ cache.push_back(CacheEntry{entry.path, info->size, info->mtime_ns, info->inode, info->kind,+ info->executable, entry.target, true}); } std::stable_sort(cache.begin(), cache.end(), [](const CacheEntry& a, const CacheEntry& b) { return compare(bytes_of(a.path), bytes_of(b.path)) < 0;@@ -918,10 +911,6 @@ } } // namespace--// ----------------------------------------------------------------------------// Snapshot-// --------------------------------------------------------------------------- int snapshot_run(const fs::path& root) { Store store = Store::open_all(root);@@ -977,8 +966,8 @@ std::vector<CacheEntry> new_cache; const std::int64_t now_ms = unix_now_millis(); BuildState state;- auto built = build_dir(*tx, root, "", old_tree, rules, attributes, cache_valid, cache, new_cache,- now_ms, state, 0);+ auto built = build_dir(*tx, root, "", old_tree, rules, attributes, cache_valid, cache,+ new_cache, now_ms, state, 0); std::optional<Id> new_root; if (!state.failed && built) {@@ -1071,10 +1060,6 @@ (void)save_cache(root, sorted, now_ms); return 0; }--// ----------------------------------------------------------------------------// Checkout-// --------------------------------------------------------------------------- int checkout_materialize_commit(const fs::path& root, Store& store, std::optional<Id> old_root, const Id& new_root, Progress* progress) {