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.

Since:

  • 0.0.1

Instance Method Summary collapse

Instance Method Details

#add(src_path, dest_path) ⇒ Object

Adds a rename operation to the list, if the rename does not create a cycle

Returns:

  • true if the rename was added, false otherwise

Since:

  • 0.0.1



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/diggit/developers_activity/activity_extractor/renames.rb', line 26

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

Returns:

  • the path of the file at the S0 snapshot

Since:

  • 0.0.1



41
42
43
44
# File 'lib/diggit/developers_activity/activity_extractor/renames.rb', line 41

def apply(path)
  path = hash[path] while hash.key? path
  path
end

#clearObject

Since:

  • 0.0.1



19
20
21
# File 'lib/diggit/developers_activity/activity_extractor/renames.rb', line 19

def clear
  @renames_hash = {}
end

#extract_commit_renames(commit, walk_backwards = true) ⇒ Object

Since:

  • 0.0.1



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/diggit/developers_activity/activity_extractor/renames.rb', line 46

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
        renamed_path = patch.delta.new_file[:path]
        new_path = patch.delta.old_file[:path]
      else
        new_path = patch.delta.new_file[:path]
        renamed_path = patch.delta.old_file[:path]
      end
      add(renamed_path, new_path)
    end
  end
end

#extract_renames(walker, walk_backwards = true) ⇒ Object

Since:

  • 0.0.1



64
65
66
# File 'lib/diggit/developers_activity/activity_extractor/renames.rb', line 64

def extract_renames(walker, walk_backwards = true)
  walker.each { |commit| extract_commit_renames(commit, walk_backwards) }
end

#hashObject

Since:

  • 0.0.1



15
16
17
# File 'lib/diggit/developers_activity/activity_extractor/renames.rb', line 15

def hash
  @renames_hash ||= {}
end