Module: Diggit::DevelopersActivity::ActivityExtractor::Renames
- Extended by:
- Renames
- Included in:
- Renames
- Defined in:
- lib/diggit/developers_activity/activity_extractor/renames.rb
Overview
Stores file renaming operations. Allows to retrieve the initial path of a file after having performed a diff on the renaming commits.
Instance Method Summary collapse
-
#add(src_path, dest_path) ⇒ Object
Adds a rename operation to the list, if the rename does not create a cycle.
-
#apply(path) ⇒ Object
Apply all renaming operations found on the given path.
- #clear ⇒ Object
- #extract_commit_renames(commit, walk_backwards = true) ⇒ Object
- #extract_renames(walker, walk_backwards = true) ⇒ Object
- #hash ⇒ Object
Instance Method Details
#add(src_path, dest_path) ⇒ Object
Adds a rename operation to the list, if the rename does not create a cycle
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/diggit/developers_activity/activity_extractor/renames.rb', line 24 def add(src_path, dest_path) # check for cycle, ie, if there is a rename path from dest to src path = dest_path while hash.key? path path = hash[path] return false if path == src_path end hash[src_path] = dest_path true end |
#apply(path) ⇒ Object
Apply all renaming operations found on the given path
39 40 41 42 |
# File 'lib/diggit/developers_activity/activity_extractor/renames.rb', line 39 def apply(path) path = hash[path] while hash.key? path path end |
#clear ⇒ Object
17 18 19 |
# File 'lib/diggit/developers_activity/activity_extractor/renames.rb', line 17 def clear @renames_hash = {} end |
#extract_commit_renames(commit, walk_backwards = true) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/diggit/developers_activity/activity_extractor/renames.rb', line 44 def extract_commit_renames(commit, walk_backwards = true) commit.parents.each do |parent| diff = parent.diff(commit, DIFF_OPTIONS) diff.find_similar!(DIFF_RENAME_OPTIONS) diff.each do |patch| next unless patch.delta.renamed? if walk_backwards new_path = patch.delta.new_file[:path] renamed_path = patch.delta.old_file[:path] else renamed_path = patch.delta.new_file[:path] new_path = patch.delta.old_file[:path] end add(renamed_path, new_path) end end end |
#extract_renames(walker, walk_backwards = true) ⇒ Object
62 63 64 |
# File 'lib/diggit/developers_activity/activity_extractor/renames.rb', line 62 def extract_renames(walker, walk_backwards = true) walker.each { |commit| extract_commit_renames(commit, walk_backwards) } end |
#hash ⇒ Object
13 14 15 |
# File 'lib/diggit/developers_activity/activity_extractor/renames.rb', line 13 def hash @renames_hash ||= {} end |