SHARE
TWEET

Untitled

a guest Jun 15th, 2019 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. use git2::{Repository, StatusOptions, StatusShow};
  2. use std::{collections::HashMap, env};
  3.  
  4. fn main() {
  5.     let path = env::current_dir().unwrap();
  6.     let repo = Repository::discover(path).unwrap();
  7.     let mut status_opt = StatusOptions::new();
  8.     status_opt
  9.         .show(StatusShow::IndexAndWorkdir)
  10.         .include_untracked(true)
  11.         .include_unmodified(false)
  12.         .no_refresh(false);
  13.     let status_result = repo.statuses(Some(&mut status_opt)).unwrap();
  14.  
  15.     let mut map: HashMap<git2::Status, u32> = HashMap::new();
  16.  
  17.     for status_entry in status_result.iter() {
  18.         *map.entry(status_entry.status()).or_insert(0) += 1;
  19.     }
  20.     println!("{:?}", map);
  21. }
  22.      
  23. M  file_a
  24. AM file_b
  25. A  file_c
  26. ?? file_e
  27. ?? file_f
  28.      
  29. $ git status --porcelain | awk -v ORS=", " 'NR>0{arr[$1]++}END{for (a in arr) print a, arr[a]}'
  30. A 1, ?? 2, M 1, AM 1,
  31.      
  32. {INDEX_NEW: 1, WT_NEW: 2, INDEX_NEW | WT_MODIFIED: 1, INDEX_MODIFIED: 1}
  33.      
  34. INDEX_NEW                -> A
  35. INDEX_NEW | WT_MODIFIED  -> AM
  36. INDEX_MODIFIED           -> M
  37. WT_NEW                   -> ??
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top