Skip to content

Commit 89de047

Browse files
committed
refactor: Use pub(crate) fn instead of pub fn
StGit does not want to be mistaken for a library.
1 parent 9bd4433 commit 89de047

File tree

4 files changed

+22
-22
lines changed

4 files changed

+22
-22
lines changed

src/cmd/completion/shstream.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub(crate) struct ShStream {
1616

1717
impl ShStream {
1818
/// Create a new [`ShStream`] instance.
19-
pub fn new() -> Self {
19+
pub(crate) fn new() -> Self {
2020
Self {
2121
buffer: String::new(),
2222
indent_level: 0,
@@ -25,28 +25,28 @@ impl ShStream {
2525
}
2626

2727
/// Insert a raw string into the stream.
28-
pub fn raw(&mut self, s: &str) {
28+
pub(crate) fn raw(&mut self, s: &str) {
2929
if !self.is_bol() {
3030
self.buffer.push('\n');
3131
}
3232
self.buffer.push_str(s);
3333
}
3434

3535
/// Increase the indentation level used for subsequent lines.
36-
pub fn indent(&mut self) {
36+
pub(crate) fn indent(&mut self) {
3737
self.indent_level += 1;
3838
}
3939

4040
/// Decrease the indentation level used for subsequent lines.
41-
pub fn dedent(&mut self) {
41+
pub(crate) fn dedent(&mut self) {
4242
assert!(self.indent_level > 0);
4343
self.indent_level -= 1;
4444
}
4545

4646
/// Insert a line into the stream.
4747
///
4848
/// The line is prefixed with indentation and suffixed with a newline character.
49-
pub fn line(&mut self, line: &str) {
49+
pub(crate) fn line(&mut self, line: &str) {
5050
if !self.is_bol() {
5151
self.buffer.push('\n');
5252
}
@@ -58,7 +58,7 @@ impl ShStream {
5858
}
5959

6060
/// Ensure a blank line precedes subsequent lines.
61-
pub fn ensure_blank_line(&mut self) {
61+
pub(crate) fn ensure_blank_line(&mut self) {
6262
if !self.buffer.is_empty() && !self.buffer.ends_with("\n\n") {
6363
if self.buffer.ends_with('\n') {
6464
self.buffer.push('\n');
@@ -68,7 +68,7 @@ impl ShStream {
6868
}
6969
}
7070

71-
pub fn end_line(&mut self) {
71+
pub(crate) fn end_line(&mut self) {
7272
if !self.is_bol() {
7373
self.buffer.push('\n');
7474
}
@@ -77,7 +77,7 @@ impl ShStream {
7777
/// Insert slice of lines into the stream.
7878
///
7979
/// Each line is prefixed with the current indentation level.
80-
pub fn lines(&mut self, lines: &[&str]) {
80+
pub(crate) fn lines(&mut self, lines: &[&str]) {
8181
for line in lines {
8282
self.line(line);
8383
}
@@ -88,7 +88,7 @@ impl ShStream {
8888
/// If the word starts a line, it will be indented to the current indentation level.
8989
/// Otherwise, a single space will be used to separate this word from any preceding
9090
/// word.
91-
pub fn word(&mut self, word: &str) {
91+
pub(crate) fn word(&mut self, word: &str) {
9292
if self.is_bol() {
9393
self.push_indent();
9494
} else if !self.buffer.ends_with(self.word_sep) {
@@ -98,12 +98,12 @@ impl ShStream {
9898
}
9999

100100
/// Set the inter-word separator character.
101-
pub fn word_sep(&mut self, separator: char) {
101+
pub(crate) fn word_sep(&mut self, separator: char) {
102102
self.word_sep = separator;
103103
}
104104

105105
/// Return byte slice of the stream's contents.
106-
pub fn as_bytes(&self) -> &[u8] {
106+
pub(crate) fn as_bytes(&self) -> &[u8] {
107107
self.buffer.as_bytes()
108108
}
109109

src/stack/stack.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ impl<'repo> Stack<'repo> {
9696
/// The current branch is used if the optional branch name is not provided.
9797
///
9898
/// An error will be returned if there is no StGit stack associated with the branch.
99-
pub fn from_branch(repo: &'repo git2::Repository, branch_name: Option<&str>) -> Result<Self> {
99+
pub(crate) fn from_branch(repo: &'repo git2::Repository, branch_name: Option<&str>) -> Result<Self> {
100100
let branch = repo.get_branch(branch_name)?;
101101
let branch_name = get_branch_name(&branch)?;
102102
let branch_head = branch.get().peel_to_commit()?;
@@ -127,14 +127,14 @@ impl<'repo> Stack<'repo> {
127127
}
128128

129129
/// Check whether the stack is marked as protected in the config.
130-
pub fn is_protected(&self, config: &git2::Config) -> bool {
130+
pub(crate) fn is_protected(&self, config: &git2::Config) -> bool {
131131
let name = &self.branch_name;
132132
let key = format!("branch.{name}.stgit.protect");
133133
config.get_bool(&key).unwrap_or(false)
134134
}
135135

136136
/// Set the stack's protected state in the config.
137-
pub fn set_protected(&self, config: &mut git2::Config, protect: bool) -> Result<()> {
137+
pub(crate) fn set_protected(&self, config: &mut git2::Config, protect: bool) -> Result<()> {
138138
let name = &self.branch_name;
139139
let key = format!("branch.{name}.stgit.protect");
140140
if protect {
@@ -155,12 +155,12 @@ impl<'repo> Stack<'repo> {
155155
}
156156

157157
/// Check whether the stack's recorded head matches the branch's head.
158-
pub fn is_head_top(&self) -> bool {
158+
pub(crate) fn is_head_top(&self) -> bool {
159159
self.state.head.id() == self.branch_head.id()
160160
}
161161

162162
/// Return an error if the stack's recorded head differs from the branch's head.
163-
pub fn check_head_top_mismatch(&self) -> Result<()> {
163+
pub(crate) fn check_head_top_mismatch(&self) -> Result<()> {
164164
if self.state.applied.is_empty() || self.is_head_top() {
165165
Ok(())
166166
} else {
@@ -173,7 +173,7 @@ impl<'repo> Stack<'repo> {
173173
}
174174

175175
/// Re-commit stack state with updated branch head.
176-
pub fn log_external_mods(self, message: Option<&str>) -> Result<Self> {
176+
pub(crate) fn log_external_mods(self, message: Option<&str>) -> Result<Self> {
177177
let state_ref = self.repo.find_reference(&self.refname)?;
178178
let prev_state_commit = state_ref.peel_to_commit()?;
179179
let prev_state_commit_id = prev_state_commit.id();

src/stack/state.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,12 @@ impl<'repo> StackState<'repo> {
157157
}
158158

159159
/// Iterator over all patches.
160-
pub fn all_patches(&self) -> AllPatches<'_> {
160+
pub(crate) fn all_patches(&self) -> AllPatches<'_> {
161161
AllPatches::new(&self.applied, &self.unapplied, &self.hidden)
162162
}
163163

164164
/// Return commit of topmost patch, or stack base if no patches applied.
165-
pub fn top(&self) -> &git2::Commit<'repo> {
165+
pub(crate) fn top(&self) -> &git2::Commit<'repo> {
166166
if let Some(patchname) = self.applied.last() {
167167
&self.patches[patchname].commit
168168
} else {
@@ -171,7 +171,7 @@ impl<'repo> StackState<'repo> {
171171
}
172172

173173
/// Create updated state with new head and prev commits.
174-
pub fn advance_head(
174+
pub(crate) fn advance_head(
175175
self,
176176
new_head: git2::Commit<'repo>,
177177
prev_state: git2::Commit<'repo>,
@@ -190,7 +190,7 @@ impl<'repo> StackState<'repo> {
190190
/// are not subject to garbage collection, stack state commit objects have parent
191191
/// commits with tree content of the associated branch in addition to a "regular"
192192
/// parent commit from the stack state branch.
193-
pub fn commit(
193+
pub(crate) fn commit(
194194
&self,
195195
repo: &'repo git2::Repository,
196196
update_ref: Option<&str>,

src/stack/upgrade.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use super::serde::{RawPatchState, RawStackState};
1515
use crate::{patchname::PatchName, stack::state::StackState};
1616

1717
/// Upgrade stack state metadata to most recent version.
18-
pub fn stack_upgrade(repo: &git2::Repository, branch_name: &str) -> Result<()> {
18+
pub(crate) fn stack_upgrade(repo: &git2::Repository, branch_name: &str) -> Result<()> {
1919
let refname_v4 = state_refname_from_branch_name_v4(branch_name);
2020

2121
if let Ok(mut stack_ref_v4) = repo.find_reference(&refname_v4) {

0 commit comments

Comments
 (0)