-
Notifications
You must be signed in to change notification settings - Fork 283
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
metalog: add refencode methods for ease-of-use
Summary: Add application-specific concepts so the callsite does not have to use low-level APIs. Reviewed By: muirdm Differential Revision: D54201003 fbshipit-source-id: 3d713bfc4c56be041f724ae56c6a91922dd08bf0
- Loading branch information
1 parent
b367ed4
commit d8cff2e
Showing
2 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This software may be used and distributed according to the terms of the | ||
* GNU General Public License version 2. | ||
*/ | ||
|
||
//! Extended APIs for application-specific metalog. | ||
use std::collections::BTreeMap; | ||
|
||
use anyhow::Result; | ||
use types::HgId; | ||
|
||
use crate::MetaLog; | ||
|
||
impl MetaLog { | ||
/// Decode bookmarks. | ||
pub fn get_bookmarks(&self) -> Result<BTreeMap<String, HgId>> { | ||
let decoded = match self.get("bookmarks")? { | ||
Some(data) => refencode::decode_bookmarks(&data)?, | ||
None => Default::default(), | ||
}; | ||
Ok(decoded) | ||
} | ||
|
||
/// Decode remotenames. | ||
pub fn get_remotenames(&self) -> Result<BTreeMap<String, HgId>> { | ||
let decoded = match self.get("remotenames")? { | ||
Some(data) => refencode::decode_remotenames(&data)?, | ||
None => Default::default(), | ||
}; | ||
Ok(decoded) | ||
} | ||
|
||
/// Decode visibleheads. | ||
pub fn get_visibleheads(&self) -> Result<Vec<HgId>> { | ||
let decoded = match self.get("visibleheads")? { | ||
Some(data) => refencode::decode_visibleheads(&data)?, | ||
None => Default::default(), | ||
}; | ||
Ok(decoded) | ||
} | ||
|
||
/// Update bookmarks. This does not write to disk until `commit`. | ||
pub fn set_bookmarks(&mut self, value: &BTreeMap<String, HgId>) -> Result<()> { | ||
let encoded = refencode::encode_bookmarks(value); | ||
self.set("bookmarks", &encoded)?; | ||
Ok(()) | ||
} | ||
|
||
/// Update remotenames. This does not write to disk until `commit`. | ||
pub fn set_remotenames(&mut self, value: &BTreeMap<String, HgId>) -> Result<()> { | ||
let encoded = refencode::encode_remotenames(value); | ||
self.set("remotenames", &encoded)?; | ||
Ok(()) | ||
} | ||
|
||
/// Update visibleheads. This does not write to disk until `commit`. | ||
pub fn set_visibleheads(&mut self, value: &[HgId]) -> Result<()> { | ||
let encoded = refencode::encode_visibleheads(value); | ||
self.set("visibleheads", &encoded)?; | ||
Ok(()) | ||
} | ||
} |