esr-rim 1.4.0 → 1.4.8

Sign up to get free protection for your applications and to get access to all the features.
data/lib/rim/rim_info.rb CHANGED
@@ -87,6 +87,8 @@ class RimInfo
87
87
  if attrs[:subdir] == ""
88
88
  attrs[:subdir] = nil
89
89
  end
90
+ else
91
+ return true
90
92
  end
91
93
  AttrsDef.each do |a|
92
94
  send("#{a}=".to_sym, attrs[a])
@@ -1,150 +1,150 @@
1
- require 'rim/command_helper'
2
- require 'rim/sync_module_helper'
3
- require 'rim/status_builder'
4
- require 'tempfile'
5
- require 'fileutils'
6
-
7
- module RIM
8
-
9
- class SyncHelper < CommandHelper
10
-
11
- def initialize(workspace_root, logger, module_infos = nil)
12
- @module_infos = []
13
- super(workspace_root, logger, module_infos)
14
- end
15
-
16
- # called to add a module info
17
- def add_module_info(module_info)
18
- @module_infos.push(module_info)
19
- end
20
-
21
- # sync all module changes into rim branch
22
- def sync(message = nil, rebase = nil, split = true)
23
- # get the name of the current workspace branch
24
- RIM::git_session(@ws_root) do |s|
25
- branch = s.current_branch || ''
26
- rim_branch = "rim/" + branch
27
- branch_sha1 = nil
28
- changed_modules = nil
29
- if branch.empty?
30
- raise RimException.new("Not on a git branch.")
31
- elsif branch.start_with?("rim/")
32
- raise RimException.new("The current git branch '#{branch}' is a rim integration branch. Please switch to a non rim branch to proceed.")
33
- else
34
- branch = "refs/heads/#{branch}"
35
- branch_sha1 = s.rev_sha1(rim_branch)
36
- remote_rev = get_latest_remote_revision(s, branch)
37
- rev = get_latest_clean_path_revision(s, branch, remote_rev)
38
- if !s.has_branch?(rim_branch) || has_ancestor?(s, branch, s.rev_sha1(rim_branch)) || !has_ancestor?(s, rim_branch, remote_rev)
39
- s.execute("git branch -f #{rim_branch} #{rev}")
40
- branch_sha1 = s.rev_sha1(rim_branch)
41
- end
42
- remote_url = "file://" + @ws_root
43
- @logger.debug("Folder for temporary git repositories: #{@rim_path}")
44
- tmpdir = clone_or_fetch_repository(remote_url, module_tmp_git_path(".ws"), "Cloning workspace git...")
45
- RIM::git_session(tmpdir) do |tmp_session|
46
- tmp_session.execute("git reset --hard")
47
- tmp_session.execute("git clean -xdf")
48
- # use -f here to prevent git checkout from checking for untracked files which might be overwritten.
49
- # this is safe since we removed any untracked files before.
50
- # this is a workaround for a name case problem on windows:
51
- # if a file's name changes case between the current head and the checkout target,
52
- # git checkout will report the file with the new name as untracked and will fail
53
- tmp_session.execute("git checkout -B #{rim_branch} -f remotes/origin/#{rim_branch}")
54
- changed_modules = sync_modules(tmp_session, message)
55
- if !split
56
- tmp_session.execute("git reset --soft #{branch_sha1}")
57
- commit(tmp_session, message ? message : get_commit_message(changed_modules)) if tmp_session.uncommited_changes?
58
- end
59
- tmp_session.execute("git push #{remote_url} #{rim_branch}:#{rim_branch}")
60
- end
61
- end
62
- if !changed_modules.empty?
63
- if rebase
64
- s.execute("git rebase #{rim_branch}")
65
- @logger.info("Changes have been commited to branch #{rim_branch} and workspace has been rebased successfully.")
66
- else
67
- @logger.info("Changes have been commited to branch #{rim_branch}. Rebase to apply changes to workspace.")
68
- end
69
- else
70
- @logger.info("No changes.")
71
- end
72
- end
73
- end
74
-
75
- private
76
- # sync all modules
77
- def sync_modules(session, message)
78
- module_helpers = []
79
- @module_infos.each do |module_info|
80
- module_helpers.push(SyncModuleHelper.new(session.execute_dir, @ws_root, module_info, @logger))
81
- end
82
- changed_modules = []
83
- module_helpers.each do |m|
84
- @logger.info("Synchronizing #{m.module_info.local_path}...")
85
- if m.sync(message)
86
- changed_modules << m.module_info
87
- end
88
- end
89
- changed_modules
90
- end
91
-
92
- # get latest revision from which all parent revisions are clean
93
- def get_latest_clean_path_revision(session, rev, remote_rev)
94
- # make sure we deal only with sha1s
95
- rev = session.rev_sha1(rev)
96
- # get history status (up to last remote revision)
97
- status = StatusBuilder.new().rev_history_status(session, rev, :fast => true)
98
- clean_rev = rev;
99
- while status
100
- dirty = status.dirty?
101
- status = !status.parents.empty? ? status.parents[0] : nil
102
- clean_rev = status ? status.git_rev : remote_rev if dirty
103
- end
104
- clean_rev
105
- end
106
-
107
- # get latest remote revision
108
- def get_latest_remote_revision(session, rev)
109
- # remote revs are where we stop traversal
110
- non_remote_revs = {}
111
- session.all_reachable_non_remote_revs(rev).each do |r|
112
- non_remote_revs[r] = true
113
- end
114
- # make sure we deal only with sha1s
115
- rev = session.rev_sha1(rev)
116
- start_rev = rev;
117
- while rev && non_remote_revs[rev]
118
- rev = get_parent(session, rev)
119
- end
120
- rev
121
- end
122
-
123
- # check whether revision has a given ancestor
124
- def has_ancestor?(session, rev, ancestor)
125
- # make sure we deal only with sha1s
126
- rev = session.rev_sha1(rev)
127
- return rev == ancestor || session.is_ancestor?(ancestor, rev)
128
- end
129
-
130
- # get first parent node
131
- def get_parent(session, rev)
132
- parents = session.parent_revs(rev)
133
- !parents.empty? ? parents.first : nil
134
- end
135
-
136
- #create default commit message from array of changed modules
137
- def get_commit_message(changed_modules)
138
- StringIO.open do |s|
139
- s.puts "rim sync."
140
- s.puts
141
- changed_modules.each do |m|
142
- s.puts m.local_path
143
- end
144
- s.string
145
- end
146
- end
147
-
148
- end
149
-
150
- end
1
+ require 'rim/command_helper'
2
+ require 'rim/sync_module_helper'
3
+ require 'rim/status_builder'
4
+ require 'tempfile'
5
+ require 'fileutils'
6
+
7
+ module RIM
8
+
9
+ class SyncHelper < CommandHelper
10
+
11
+ def initialize(workspace_root, logger, module_infos = nil)
12
+ @module_infos = []
13
+ super(workspace_root, logger, module_infos)
14
+ end
15
+
16
+ # called to add a module info
17
+ def add_module_info(module_info)
18
+ @module_infos.push(module_info)
19
+ end
20
+
21
+ # sync all module changes into rim branch
22
+ def sync(message = nil, rebase = nil, split = true)
23
+ # get the name of the current workspace branch
24
+ RIM::git_session(@ws_root) do |s|
25
+ branch = s.current_branch || ''
26
+ rim_branch = "rim/" + branch
27
+ branch_sha1 = nil
28
+ changed_modules = nil
29
+ if branch.empty?
30
+ raise RimException.new("Not on a git branch.")
31
+ elsif branch.start_with?("rim/")
32
+ raise RimException.new("The current git branch '#{branch}' is a rim integration branch. Please switch to a non rim branch to proceed.")
33
+ else
34
+ branch = "refs/heads/#{branch}"
35
+ branch_sha1 = s.rev_sha1(rim_branch)
36
+ remote_rev = get_latest_remote_revision(s, branch)
37
+ rev = get_latest_clean_path_revision(s, branch, remote_rev)
38
+ if !s.has_branch?(rim_branch) || has_ancestor?(s, branch, s.rev_sha1(rim_branch)) || !has_ancestor?(s, rim_branch, remote_rev)
39
+ s.execute("git branch -f #{rim_branch} #{rev}")
40
+ branch_sha1 = s.rev_sha1(rim_branch)
41
+ end
42
+ remote_url = "file://" + @ws_root
43
+ @logger.debug("Folder for temporary git repositories: #{@rim_path}")
44
+ tmpdir = clone_or_fetch_repository(remote_url, module_tmp_git_path(".ws"), "Cloning workspace git...")
45
+ RIM::git_session(tmpdir) do |tmp_session|
46
+ tmp_session.execute("git reset --hard")
47
+ tmp_session.execute("git clean -xdf")
48
+ # use -f here to prevent git checkout from checking for untracked files which might be overwritten.
49
+ # this is safe since we removed any untracked files before.
50
+ # this is a workaround for a name case problem on windows:
51
+ # if a file's name changes case between the current head and the checkout target,
52
+ # git checkout will report the file with the new name as untracked and will fail
53
+ tmp_session.execute("git checkout -B #{rim_branch} -f remotes/origin/#{rim_branch}")
54
+ changed_modules = sync_modules(tmp_session, message)
55
+ if !split
56
+ tmp_session.execute("git reset --soft #{branch_sha1}")
57
+ commit(tmp_session, message ? message : get_commit_message(changed_modules)) if tmp_session.uncommited_changes?
58
+ end
59
+ tmp_session.execute("git push #{remote_url} #{rim_branch}:#{rim_branch}")
60
+ end
61
+ end
62
+ if !changed_modules.empty?
63
+ if rebase
64
+ s.execute("git rebase #{rim_branch}")
65
+ @logger.info("Changes have been commited to branch #{rim_branch} and workspace has been rebased successfully.")
66
+ else
67
+ @logger.info("Changes have been commited to branch #{rim_branch}. Rebase to apply changes to workspace.")
68
+ end
69
+ else
70
+ @logger.info("No changes.")
71
+ end
72
+ end
73
+ end
74
+
75
+ private
76
+ # sync all modules
77
+ def sync_modules(session, message)
78
+ module_helpers = []
79
+ @module_infos.each do |module_info|
80
+ module_helpers.push(SyncModuleHelper.new(session.execute_dir, @ws_root, module_info, @logger))
81
+ end
82
+ changed_modules = []
83
+ module_helpers.each do |m|
84
+ @logger.info("Synchronizing #{m.module_info.local_path}...")
85
+ if m.sync(message)
86
+ changed_modules << m.module_info
87
+ end
88
+ end
89
+ changed_modules
90
+ end
91
+
92
+ # get latest revision from which all parent revisions are clean
93
+ def get_latest_clean_path_revision(session, rev, remote_rev)
94
+ # make sure we deal only with sha1s
95
+ rev = session.rev_sha1(rev)
96
+ # get history status (up to last remote revision)
97
+ status = StatusBuilder.new().rev_history_status(session, rev, :fast => true)
98
+ clean_rev = rev;
99
+ while status
100
+ dirty = status.dirty?
101
+ status = !status.parents.empty? ? status.parents[0] : nil
102
+ clean_rev = status ? status.git_rev : remote_rev if dirty
103
+ end
104
+ clean_rev
105
+ end
106
+
107
+ # get latest remote revision
108
+ def get_latest_remote_revision(session, rev)
109
+ # remote revs are where we stop traversal
110
+ non_remote_revs = {}
111
+ session.all_reachable_non_remote_revs(rev).each do |r|
112
+ non_remote_revs[r] = true
113
+ end
114
+ # make sure we deal only with sha1s
115
+ rev = session.rev_sha1(rev)
116
+ start_rev = rev;
117
+ while rev && non_remote_revs[rev]
118
+ rev = get_parent(session, rev)
119
+ end
120
+ rev
121
+ end
122
+
123
+ # check whether revision has a given ancestor
124
+ def has_ancestor?(session, rev, ancestor)
125
+ # make sure we deal only with sha1s
126
+ rev = session.rev_sha1(rev)
127
+ return rev == ancestor || session.is_ancestor?(ancestor, rev)
128
+ end
129
+
130
+ # get first parent node
131
+ def get_parent(session, rev)
132
+ parents = session.parent_revs(rev)
133
+ !parents.empty? ? parents.first : nil
134
+ end
135
+
136
+ #create default commit message from array of changed modules
137
+ def get_commit_message(changed_modules)
138
+ StringIO.open do |s|
139
+ s.puts "rim sync."
140
+ s.puts
141
+ changed_modules.each do |m|
142
+ s.puts m.local_path
143
+ end
144
+ s.string
145
+ end
146
+ end
147
+
148
+ end
149
+
150
+ end
@@ -1,107 +1,107 @@
1
- require 'rim/module_helper'
2
- require 'rim/rim_info'
3
- require 'rim/file_helper'
4
- require 'rim/dirty_check'
5
- require 'tempfile'
6
- require 'pathname'
7
-
8
- module RIM
9
- class SyncModuleHelper < ModuleHelper
10
- def initialize(dest_root, workspace_root, module_info, logger)
11
- super(workspace_root, module_info, logger)
12
- @dest_root = dest_root
13
- end
14
-
15
- # do the local sync without committing
16
- def sync(message = nil)
17
- fetch_module
18
- export_module(message)
19
- end
20
-
21
- private
22
-
23
- # export +revision+ of +mod+ into working copy
24
- # BEWARE: any changes to the working copy target dir will be lost!
25
- def export_module(message)
26
- changes = false
27
- RIM::git_session(@dest_root) do |d|
28
- start_sha1 = d.rev_sha1("HEAD")
29
- git_path = module_git_path(@remote_path)
30
- RIM::git_session(git_path) do |s|
31
- if !s.rev_sha1(@module_info.target_revision)
32
- raise RimException.new("Unknown target revision '#{@module_info.target_revision}' for module '#{@module_info.local_path}'.")
33
- end
34
- local_path = File.join(@dest_root, @module_info.local_path)
35
- prepare_empty_folder(local_path, @module_info.ignores)
36
- temp_commit(d, "clear directory") if d.uncommited_changes?
37
- strip = ""
38
- if @module_info.subdir
39
- depth = Pathname(@module_info.subdir).each_filename.count()
40
- strip = "--strip-components=#{depth}"
41
- end
42
- s.execute("git archive --format tar #{@module_info.target_revision} #{@module_info.subdir} | tar #{strip} -x -C #{local_path}")
43
- sha1 = s.execute("git rev-parse #{@module_info.target_revision}").strip
44
- @rim_info = RimInfo.new
45
- @rim_info.remote_url = @module_info.remote_url
46
- @rim_info.target_revision = @module_info.target_revision
47
- @rim_info.revision_sha1 = sha1
48
- @rim_info.ignores = @module_info.ignores.join(",")
49
- @rim_info.subdir = @module_info.subdir
50
- @rim_info.infos = s.rev_infos(@module_info.target_revision, RimInfo.git_infos)
51
- @rim_info.to_dir(local_path)
52
- DirtyCheck.mark_clean(local_path)
53
- end
54
- temp_commit(d, "commit changes") if needs_commit?(d)
55
- d.execute("git reset --soft #{start_sha1}")
56
- changes = d.uncommited_changes?
57
- commit(d, message || "rim sync: module #{@module_info.local_path}") if changes
58
- end
59
- changes
60
- end
61
-
62
- def needs_commit?(session)
63
- # do we need to commit something?
64
- stat = session.status(@module_info.local_path)
65
- # no files should be ignored due to --force option. Anyway we will check for ignored files
66
- ignored = []
67
- session.execute("git add --all --force #{@module_info.local_path}") do |out, e|
68
- ignored = parse_ignored_files(session, out, e)
69
- end
70
- if ignored.empty?
71
- stat = session.status(@module_info.local_path)
72
- ignored = stat.lines.select{ |l| l.ignored? }
73
- end
74
- if !ignored.empty?
75
- messages = ["Sync failed due to files/dirs of #{@module_info.local_path} which are ignored by workspace's .gitignore:"]
76
- ignored.each do |l|
77
- messages.push(l.file)
78
- end
79
- raise RimException.new(messages)
80
- end
81
- stat.lines.any?
82
- end
83
-
84
- def temp_commit(session, message)
85
- session.execute("git add --all")
86
- session.execute("git commit -m \"#{message}\" --")
87
- end
88
-
89
- def parse_ignored_files(session, out, e)
90
- first_line = true
91
- ignored = []
92
- out.gsub(/warning:.*will be replaced.*\r?\n.*\r?\n/, '').split(/\r?\n/).each do |l|
93
- raise e || RimException.new("Cannot parse ignored files after git add:\n#{out}") if first_line && !l.include?(".gitignore")
94
- if File.exist?(File.expand_path(l, session.execute_dir))
95
- ignored_line = GitSession::Status::Line.new
96
- ignored_line.file = l
97
- ignored_line.istat = "!"
98
- ignored.push(ignored_line)
99
- end
100
- first_line = false
101
- end
102
- ignored
103
- end
104
-
105
- end
106
-
107
- end
1
+ require 'rim/module_helper'
2
+ require 'rim/rim_info'
3
+ require 'rim/file_helper'
4
+ require 'rim/dirty_check'
5
+ require 'tempfile'
6
+ require 'pathname'
7
+
8
+ module RIM
9
+ class SyncModuleHelper < ModuleHelper
10
+ def initialize(dest_root, workspace_root, module_info, logger)
11
+ super(workspace_root, module_info, logger)
12
+ @dest_root = dest_root
13
+ end
14
+
15
+ # do the local sync without committing
16
+ def sync(message = nil)
17
+ fetch_module
18
+ export_module(message)
19
+ end
20
+
21
+ private
22
+
23
+ # export +revision+ of +mod+ into working copy
24
+ # BEWARE: any changes to the working copy target dir will be lost!
25
+ def export_module(message)
26
+ changes = false
27
+ RIM::git_session(@dest_root) do |d|
28
+ start_sha1 = d.rev_sha1("HEAD")
29
+ git_path = module_git_path(@remote_path)
30
+ RIM::git_session(git_path) do |s|
31
+ if !s.rev_sha1(@module_info.target_revision)
32
+ raise RimException.new("Unknown target revision '#{@module_info.target_revision}' for module '#{@module_info.local_path}'.")
33
+ end
34
+ local_path = File.join(@dest_root, @module_info.local_path)
35
+ prepare_empty_folder(local_path, [*@module_info.ignores, ".git/**/*"])
36
+ temp_commit(d, "clear directory") if d.uncommited_changes?
37
+ strip = ""
38
+ if @module_info.subdir
39
+ depth = Pathname(@module_info.subdir).each_filename.count()
40
+ strip = "--strip-components=#{depth}"
41
+ end
42
+ s.execute("git archive --format tar #{@module_info.target_revision} #{@module_info.subdir} | tar #{strip} -C #{local_path} -xf -")
43
+ sha1 = s.execute("git rev-parse #{@module_info.target_revision}").strip
44
+ @rim_info = RimInfo.new
45
+ @rim_info.remote_url = @module_info.remote_url
46
+ @rim_info.target_revision = @module_info.target_revision
47
+ @rim_info.revision_sha1 = sha1
48
+ @rim_info.ignores = @module_info.ignores.join(",")
49
+ @rim_info.subdir = @module_info.subdir
50
+ @rim_info.infos = s.rev_infos(@module_info.target_revision, RimInfo.git_infos)
51
+ @rim_info.to_dir(local_path)
52
+ DirtyCheck.mark_clean(local_path)
53
+ end
54
+ temp_commit(d, "commit changes") if needs_commit?(d)
55
+ d.execute("git reset --soft #{start_sha1}")
56
+ changes = d.uncommited_changes?
57
+ commit(d, message || "rim sync: module #{@module_info.local_path}") if changes
58
+ end
59
+ changes
60
+ end
61
+
62
+ def needs_commit?(session)
63
+ # do we need to commit something?
64
+ stat = session.status(@module_info.local_path)
65
+ # no files should be ignored due to --force option. Anyway we will check for ignored files
66
+ ignored = []
67
+ session.execute("git add --all --force #{@module_info.local_path}") do |out, e|
68
+ ignored = parse_ignored_files(session, out, e)
69
+ end
70
+ if ignored.empty?
71
+ stat = session.status(@module_info.local_path)
72
+ ignored = stat.lines.select{ |l| l.ignored? }
73
+ end
74
+ if !ignored.empty?
75
+ messages = ["Sync failed due to files/dirs of #{@module_info.local_path} which are ignored by workspace's .gitignore:"]
76
+ ignored.each do |l|
77
+ messages.push(l.file)
78
+ end
79
+ raise RimException.new(messages)
80
+ end
81
+ stat.lines.any?
82
+ end
83
+
84
+ def temp_commit(session, message)
85
+ session.execute("git add --all")
86
+ session.execute("git commit -m \"#{message}\" --")
87
+ end
88
+
89
+ def parse_ignored_files(session, out, e)
90
+ first_line = true
91
+ ignored = []
92
+ out.gsub(/warning:.*will be replaced.*\r?\n.*\r?\n/, '').split(/\r?\n/).each do |l|
93
+ raise e || RimException.new("Cannot parse ignored files after git add:\n#{out}") if first_line && !l.include?(".gitignore")
94
+ if File.exist?(File.expand_path(l, session.execute_dir))
95
+ ignored_line = GitSession::Status::Line.new
96
+ ignored_line.file = l
97
+ ignored_line.istat = "!"
98
+ ignored.push(ignored_line)
99
+ end
100
+ first_line = false
101
+ end
102
+ ignored
103
+ end
104
+
105
+ end
106
+
107
+ end