-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Labels
refactorRefactoring a method or structureRefactoring a method or structure
Milestone
Description
What's your idea?
위치가 이동된 파일을 찾기 위해 현재 커밋 하나하나 일일이 찾고 있다.
queensac/src/git/file_tracker.rs
Lines 13 to 41 in 11386b9
| pub fn find_last_commit_id<'a>( | |
| target_file: &str, | |
| repo: &'a Repository, | |
| ) -> Result<Commit<'a>, git2::Error> { | |
| let mut revwalk = repo.revwalk()?; | |
| revwalk.push_head()?; | |
| for commit_id in revwalk { | |
| let commit_id = commit_id?; | |
| let commit = repo.find_commit(commit_id)?; | |
| // Ignore merge commits(2+ Parents) because that's what 'git whatchenged' does. | |
| // Ignore commit with 0 parent (initial commit) because there's nothing to diff against. | |
| if commit.parent_count() == 1 { | |
| let prev_commit = commit.parent(0)?; | |
| let tree = commit.tree()?; | |
| let prev_tree = prev_commit.tree()?; | |
| let diff = repo.diff_tree_to_tree(Some(&prev_tree), Some(&tree), None)?; | |
| for delta in diff.deltas() { | |
| if let Some(file_path) = delta.new_file().path() | |
| && let Some(file_path_str) = file_path.to_str() | |
| && file_path_str == target_file | |
| { | |
| return Ok(commit); | |
| } | |
| } | |
| } | |
| } |
알고리즘 배워서 어따 써먹겠나 여기에 이분탐색 발라 먹자.
reddevilmidzy
Metadata
Metadata
Assignees
Labels
refactorRefactoring a method or structureRefactoring a method or structure
Projects
Status
Opening