Jelajahi Sumber

Add dedicated flags for displaying sub-directory git repo info, -—git-repos and -—git-repos-no-status
The latter skips git status lookup and thereby faster

alpn 3 tahun lalu
induk
melakukan
77035605ce
6 mengubah file dengan 30 tambahan dan 12 penghapusan
  1. 4 1
      src/fs/feature/git.rs
  2. 3 2
      src/fs/fields.rs
  3. 6 4
      src/options/flags.rs
  4. 3 2
      src/options/view.rs
  5. 1 0
      src/output/render/git.rs
  6. 13 3
      src/output/table.rs

+ 4 - 1
src/fs/feature/git.rs

@@ -358,13 +358,16 @@ fn current_branch(repo: &git2::Repository) -> Option<String>{
 }
 
 impl f::SubdirGitRepo{
-    pub fn from_path(dir : &Path) -> Self{
+    pub fn from_path(dir : &Path, status : bool) -> Self{
 
         let path = &reorient(&dir);
         let g = git2::Repository::open(path);
         if let Ok(repo) = g{
 
             let branch = current_branch(&repo);
+            if !status{
+                return Self{status : f::SubdirGitRepoStatus::GitUnknown, branch};
+            }
             match repo.statuses(None) {
                 Ok(es) => {
                     if es.iter().filter(|s| s.status() != git2::Status::IGNORED).any(|_| true){

+ 3 - 2
src/fs/fields.rs

@@ -251,7 +251,8 @@ impl Default for Git {
 pub enum SubdirGitRepoStatus{
     NoRepo,
     GitClean,
-    GitDirty
+    GitDirty,
+    GitUnknown
 }
 
 #[derive(Clone)]
@@ -267,4 +268,4 @@ impl Default for SubdirGitRepo{
             branch : None
         }
     }
-}
+}

+ 6 - 4
src/options/flags.rs

@@ -62,9 +62,11 @@ pub static NO_TIME: Arg = Arg { short: None, long: "no-time", takes_value: Takes
 pub static NO_ICONS: Arg = Arg { short: None, long: "no-icons", takes_value: TakesValue::Forbidden };
 
 // optional feature options
-pub static GIT:       Arg = Arg { short: None,       long: "git",               takes_value: TakesValue::Forbidden };
-pub static EXTENDED:  Arg = Arg { short: Some(b'@'), long: "extended",          takes_value: TakesValue::Forbidden };
-pub static OCTAL:     Arg = Arg { short: None,       long: "octal-permissions", takes_value: TakesValue::Forbidden };
+pub static GIT:               Arg = Arg { short: None,       long: "git",                  takes_value: TakesValue::Forbidden };
+pub static GIT_REPOS:         Arg = Arg { short: None,       long: "git-repos",            takes_value: TakesValue::Forbidden };
+pub static GIT_REPOS_NO_STAT: Arg = Arg { short: None,       long: "git-repos-no-status",  takes_value: TakesValue::Forbidden };
+pub static EXTENDED:          Arg = Arg { short: Some(b'@'), long: "extended",             takes_value: TakesValue::Forbidden };
+pub static OCTAL:             Arg = Arg { short: None,       long: "octal-permissions",    takes_value: TakesValue::Forbidden };
 
 
 pub static ALL_ARGS: Args = Args(&[
@@ -80,5 +82,5 @@ pub static ALL_ARGS: Args = Args(&[
     &BLOCKS, &TIME, &ACCESSED, &CREATED, &TIME_STYLE,
     &NO_PERMISSIONS, &NO_FILESIZE, &NO_USER, &NO_TIME, &NO_ICONS,
 
-    &GIT, &EXTENDED, &OCTAL
+    &GIT, &GIT_REPOS, &GIT_REPOS_NO_STAT, &EXTENDED, &OCTAL
 ]);

+ 3 - 2
src/options/view.rs

@@ -201,7 +201,8 @@ impl Columns {
         let time_types = TimeTypes::deduce(matches)?;
 
         let git = matches.has(&flags::GIT)?;
-        let subdir_git_repos = git;
+        let subdir_git_repos = matches.has(&flags::GIT_REPOS)?;
+        let subdir_git_repos_no_stat = !subdir_git_repos && matches.has(&flags::GIT_REPOS_NO_STAT)?;
 
         let blocks = matches.has(&flags::BLOCKS)?;
         let group  = matches.has(&flags::GROUP)?;
@@ -213,7 +214,7 @@ impl Columns {
         let filesize =    ! matches.has(&flags::NO_FILESIZE)?;
         let user =        ! matches.has(&flags::NO_USER)?;
 
-        Ok(Self { time_types, inode, links, blocks, group, git, subdir_git_repos, octal, permissions, filesize, user })
+        Ok(Self { time_types, inode, links, blocks, group, git, subdir_git_repos, subdir_git_repos_no_stat,octal, permissions, filesize, user })
     }
 }
 

+ 1 - 0
src/output/render/git.rs

@@ -32,6 +32,7 @@ impl f::SubdirGitRepo {
             f::SubdirGitRepoStatus::NoRepo => style.paint("- "),
             f::SubdirGitRepoStatus::GitClean => style.fg(Color::Green).paint("| "),
             f::SubdirGitRepoStatus::GitDirty => style.bold().fg(Color::Red).paint("- "),
+            f::SubdirGitRepoStatus::GitUnknown => style.paint("- "),
         };
 
         TextCell {

+ 13 - 3
src/output/table.rs

@@ -42,6 +42,7 @@ pub struct Columns {
     pub group: bool,
     pub git: bool,
     pub subdir_git_repos: bool,
+    pub subdir_git_repos_no_stat: bool,
     pub octal: bool,
 
     // Defaults to true:
@@ -110,6 +111,10 @@ impl Columns {
             columns.push(Column::SubdirGitRepoStatus);
         }
 
+        if self.subdir_git_repos_no_stat {
+            columns.push(Column::SubdirGitRepoNoStatus);
+        }
+
         columns
     }
 }
@@ -128,6 +133,7 @@ pub enum Column {
     Inode,
     GitStatus,
     SubdirGitRepoStatus,
+    SubdirGitRepoNoStatus,
     Octal,
 }
 
@@ -167,6 +173,7 @@ impl Column {
             Self::Inode         => "inode",
             Self::GitStatus     => "Git",
             Self::SubdirGitRepoStatus => "Repo",
+            Self::SubdirGitRepoNoStatus => "Repo",
             Self::Octal         => "Octal",
         }
     }
@@ -433,7 +440,10 @@ impl<'a, 'f> Table<'a> {
                 self.git_status(file).render(self.theme)
             }
             Column::SubdirGitRepoStatus => {
-                self.subdir_git_repo_status(file).render()
+                self.subdir_git_repo(file, true).render()
+            }
+            Column::SubdirGitRepoNoStatus => {
+                self.subdir_git_repo(file, false).render()
             }
             Column::Octal => {
                 self.octal_permissions(file).render(self.theme.ui.octal)
@@ -462,11 +472,11 @@ impl<'a, 'f> Table<'a> {
             .unwrap_or_default()
     }
 
-    fn subdir_git_repo_status(&self, file: &File<'_>) -> f::SubdirGitRepo {
+    fn subdir_git_repo(&self, file: &File<'_>, status : bool) -> f::SubdirGitRepo {
         debug!("Getting subdir repo status for path {:?}", file.path);
 
         if file.is_directory(){
-            return f::SubdirGitRepo::from_path(&file.path);
+            return f::SubdirGitRepo::from_path(&file.path, status);
         }
         f::SubdirGitRepo::default()
     }