Class: RIM::StatusBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/rim/status_builder.rb

Instance Method Summary collapse

Instance Method Details

#fs_status(dir) ⇒ Object

status object for the current file system content of dir this can by any directory even outside of any git working copy



86
87
88
89
90
91
# File 'lib/rim/status_builder.rb', line 86

def fs_status(dir)
  RevStatus.new(
    fs_rim_dirs(dir).collect { |d|
      build_module_status(dir, d) 
    })
end

#rev_history_status(git_session, rev, options = {}) ⇒ Object

status object tree for revision rev returns the root status object which points to any parent status objects note that merge commits mean that the status tree branches at the point were the merged branch branched off, the status tree joins i.e. the parent status objects are the same at this point

stops traversing a specific branch when a commit is found which is an ancestor of :stop_rev or any remote branch if :stop_rev is not provided;

with the :gerrit option, stops traversing on any ancestor of any known commit; this is necessary since on gerrit there are no “remote” commits; at the same time, gerrit doesn’t “know” commits pushed in the ref-update hook yet so the status will be built for the new commits pushed in the ref-update hook

the leafs of the tree are the stop commits or commits which have no parents

with the :fast option set to true, the leafs in the tree will not be checked but instead all modules present in those commits will assumed to be clean; be aware that this assumption might be wrong! if the leaves of the tree are remote commits, the fast check basically tells if any of the local commits is dirty or not



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/rim/status_builder.rb', line 31

def rev_history_status(git_session, rev, options={})
  stop_rev = options[:stop_rev]
  relevant_revs = {}
  if stop_rev
    git_session.execute("git rev-list #{rev} \"^#{stop_rev}\"").split("\n").each do |r|
      relevant_revs[r] = true
    end
  elsif options[:gerrit]
    # in gerrit mode, stop on all known commits

    git_session.execute("git rev-list #{rev} --not --all --").split("\n").each do |r|
      relevant_revs[r] = true
    end
  else
    # remote revs are where we stop traversal

    git_session.all_reachable_non_remote_revs(rev).each do |r| 
      relevant_revs[r] = true
    end
  end
  # make sure we deal only with sha1s

  rev = git_session.rev_sha1(rev)
  build_rev_history_status(git_session, rev, relevant_revs, {}, :fast => options[:fast])
end

#rev_module_status(git_session, rev, local_path) ⇒ Object

status object for a single module at local_path in revision rev returns nil if there is no such module in this revision



74
75
76
77
78
79
80
81
82
# File 'lib/rim/status_builder.rb', line 74

def rev_module_status(git_session, rev, local_path)
  mod_stat = nil
  if git_session.execute("git ls-tree -r --name-only #{rev}").split("\n").include?(File.join(local_path, ".riminfo"))
    git_session.within_exported_rev(rev, [local_path]) do |d|
      mod_stat = build_module_status(d, File.join(d, local_path))
    end
  end
  mod_stat
end

#rev_status(git_session, rev) ⇒ Object

status object for single revision rev without status of ancestors



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/rim/status_builder.rb', line 55

def rev_status(git_session, rev)
  mod_dirs = module_dirs(git_session, rev)
  mod_stats = []
  # export all relevant modules at once

  # this makes status calculation significantly faster compared

  # to exporting each module separately 

  # (e.g. 1.0s instead of 1.5s on linux for a commit with 20 modules)

  git_session.within_exported_rev(rev, mod_dirs) do |d|
    mod_dirs.each do |rel_path|
      mod_stats << build_module_status(d, d+"/"+rel_path)
    end
  end
  stat = RevStatus.new(mod_stats)
  stat.git_rev = git_session.rev_sha1(rev)
  stat
end