Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(477)

Delta Between Two Patch Sets: Tools/Google.Apis.Release/Repositories/Hg.cs

Issue 12767046: Issue 377: New build for releasing a new version (Closed) Base URL: https://google-api-dotnet-client.googlecode.com/hg/
Left Patch Set: minor Created 10 years, 6 months ago
Right Patch Set: david comments Created 10 years, 6 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
LEFTRIGHT
1 /* 1 /*
2 Copyright 2011 Google Inc 2 Copyright 2011 Google Inc
3 3
4 Licensed under the Apache License, Version 2.0 (the "License"); 4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License. 5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at 6 You may obtain a copy of the License at
7 7
8 http://www.apache.org/licenses/LICENSE-2.0 8 http://www.apache.org/licenses/LICENSE-2.0
9 9
10 Unless required by applicable law or agreed to in writing, software 10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS, 11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and 13 See the License for the specific language governing permissions and
14 limitations under the License. 14 limitations under the License.
15 */ 15 */
16 16
17 using System; 17 using System;
18 using System.Collections.Generic; 18 using System.Collections.Generic;
19 using System.Diagnostics; 19 using System.Diagnostics;
20 using System.IO; 20 using System.IO;
21 using System.Linq; 21 using System.Linq;
22 using System.Runtime.InteropServices; 22 using System.Runtime.InteropServices;
23 using System.Text.RegularExpressions; 23 using System.Text.RegularExpressions;
24 24
25 using Google.Apis.Utils; 25 using Google.Apis.Utils;
26 using Google.Apis.Utils.Trace;
26 27
27 namespace Google.Apis.Release.Repositories 28 namespace Google.Apis.Release.Repositories
28 { 29 {
29 /// <summary>Mercurial repository interface class.</summary> 30 /// <summary>Mercurial repository interface class.</summary>
30 public sealed class Hg : IDisposable 31 public sealed class Hg : IDisposable
31 { 32 {
32 static readonly TraceSource TraceSource = new TraceSource("Google.Apis") ; 33 static readonly TraceSource TraceSource = new TraceSource("Google.Apis") ;
33 34
34 /// <summary>Gets the name of the repository.summary> 35 /// <summary>Gets the name of the repository.summary>
35 public string Name { get; private set; } 36 public string Name { get; private set; }
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 // the executable "hg outgoing" returns 1 if there where no changes. 84 // the executable "hg outgoing" returns 1 if there where no changes.
84 // So treat ExternalException as no changes. 85 // So treat ExternalException as no changes.
85 return false; 86 return false;
86 } 87 }
87 } 88 }
88 } 89 }
89 90
90 /// <summary> 91 /// <summary>
91 /// Constructs a new repository. It creates a new repository if the fold er doesn't exists, otherwise it gets 92 /// Constructs a new repository. It creates a new repository if the fold er doesn't exists, otherwise it gets
92 /// the current status of the repository. 93 /// the current status of the repository.
93 /// </summary> 94 /// </summary>
peleyal 2013/09/14 21:15:14 remove </summary>
peleyal 2013/09/16 12:33:54 Done.
94 /// </summary>········
95 /// <param name="repositoryUri">The URI of this repository</param> 95 /// <param name="repositoryUri">The URI of this repository</param>
96 /// <param name="localDir">The local directory which contains the reposi tory files</param> 96 /// <param name="localDir">The local directory which contains the reposi tory files</param>
97 public Hg(Uri repositoryUri, string localDir) 97 public Hg(Uri repositoryUri, string localDir)
98 { 98 {
99 RepositoryUri = repositoryUri; 99 RepositoryUri = repositoryUri;
100 WorkingDirectory = Path.GetFullPath(localDir); 100 WorkingDirectory = Path.GetFullPath(localDir);
101 Name = repositoryUri.Segments.Last(); 101 Name = repositoryUri.Segments.Last();
102 102
103 if (!Directory.Exists(WorkingDirectory)) 103 if (!Directory.Exists(WorkingDirectory))
104 { 104 {
(...skipping 21 matching lines...) Expand all
126 RunHg("status -m -a -r"); 126 RunHg("status -m -a -r");
127 127
128 TraceSource.TraceEvent(TraceEventType.Information, "[{0}] Committing changes", Name); 128 TraceSource.TraceEvent(TraceEventType.Information, "[{0}] Committing changes", Name);
129 RunHg(string.Format("commit -m \"{0}\"", message)); 129 RunHg(string.Format("commit -m \"{0}\"", message));
130 return true; 130 return true;
131 } 131 }
132 132
133 /// <summary>Adds a tag to the last revision.</summary> 133 /// <summary>Adds a tag to the last revision.</summary>
134 /// <param name="tagName">The tag to add.</param> 134 /// <param name="tagName">The tag to add.</param>
135 /// <param name="force"> 135 /// <param name="force">
136 /// If set to true will overwrite existing labels of this name see "hg h elp tag" and its 136 /// If set to true will overwrite existing labels of this name see "hg h elp tag" and its --force parameter.
137 /// --force parameter.
138 /// </param> 137 /// </param>
139 public void Tag(string tagName, bool force = false) 138 public void Tag(string tagName, bool force = false)
140 { 139 {
141 TraceSource.TraceEvent(TraceEventType.Information, "[{0}] Tagging wi th {1}", Name, tagName); 140 TraceSource.TraceEvent(TraceEventType.Information, "[{0}] Tagging wi th {1}", Name, tagName);
142 string options = (force ? "-f " : ""); 141 string options = (force ? "-f " : "");
143 RunHg(string.Format("tag {0}\"{1}\"", options, tagName)); 142 RunHg(string.Format("tag {0}\"{1}\"", options, tagName));
144 } 143 }
145 144
146 /// <summary>Adds all un-versioned files and remove all versioned files. </summary> 145 /// <summary>Adds all unversioned files and remove all versioned files.< /summary>
147 public void AddRemoveFiles() 146 public void AddRemoveFiles()
148 { 147 {
149 RunHg("addremove"); 148 RunHg("addremove");
150 } 149 }
151 150
152 /// <summary>Pushes all committed changes to the server.</summary> 151 /// <summary>Pushes all committed changes to the server.</summary>
153 public void Push() 152 public void Push()
154 { 153 {
155 if (!HasUnpushedChanges) 154 if (!HasUnpushedChanges)
156 { 155 {
157 return; 156 return;
158 } 157 }
159 158
160 TraceSource.TraceEvent(TraceEventType.Information, "Pushing {0}", Na me); 159 TraceSource.TraceEvent(TraceEventType.Information, "Pushing {0}", Na me);
161 RunHg("push"); 160 RunHg("push");
162 } 161 }
163 162
164 /// <summary>Updates the repository by the branch name.</summary> 163 /// <summary>Updates the repository by the branch name.</summary>
165 public void Update(string branchName) 164 public void Update(string branchName)
166 { 165 {
167 TraceSource.TraceEvent(TraceEventType.Information, "[{0}] Updating b ranch to {1}", Name, branchName); 166 TraceSource.TraceEvent(TraceEventType.Information, "[{0}] Updating b ranch to {1}", Name, branchName);
168 RunHg("update " + branchName); 167 RunHg("update " + branchName);
169 }
170
171 /// <summary>Outputs the diff to the default output stream.</summary>
172 public void ShowDiff()
173 {
174 RunHg("diff");
175 } 168 }
176 169
177 /// <summary>Creates the combined path of the specified directories.</su mmary> 170 /// <summary>Creates the combined path of the specified directories.</su mmary>
178 public string Combine(params string[] dirs) 171 public string Combine(params string[] dirs)
179 { 172 {
180 return dirs.Aggregate(WorkingDirectory, Path.Combine); 173 return dirs.Aggregate(WorkingDirectory, Path.Combine);
181 } 174 }
182 175
183 /// <summary>Creates a change list by listing all changes made since the last release.</summary> 176 /// <summary>Creates a change list by listing all changes made since the last release.</summary>
184 public IEnumerable<string> CreateChangelist() 177 public IEnumerable<string> CreateChangelist()
185 { 178 {
186 Regex tagRegex = new Regex("Added tag [0-9A-Za-z.-]+ for changeset [ ^b]+", RegexOptions.Compiled); 179 Regex tagRegex = new Regex("Added tag [0-9A-Za-z.-]+ for changeset [ ^b]+", RegexOptions.Compiled);
187 string branch = RunListeningHg("branch").Single(); 180 string branch = RunListeningHg("branch").Single();
188 return RunListeningHg(string.Format("log --template \"{{rev}}: {{des c}}\\r\\n\" -b {0}", branch)) 181 return RunListeningHg(string.Format("log --template \"{{rev}}: {{des c}}\\r\\n\" -b {0}", branch))
189 .TakeWhile(line => !tagRegex.IsMatch(line)); 182 .TakeWhile(line => !tagRegex.IsMatch(line));
190 } 183 }
191 184
192 /// <summary>Runs a HG command. In addition it prints error and message to trace.</summary> 185 /// <summary>Runs a HG command. In addition it prints errors and message s to trace.</summary>
peleyal 2013/09/14 21:15:14 errors and messages
peleyal 2013/09/16 12:33:54 Done.
193 private void RunHg(string command) 186 private void RunHg(string command)
194 { 187 {
195 RunHg(command, 188 RunHg(command,
196 error => 189 error =>
197 { 190 {
198 if (!string.IsNullOrEmpty(error)) 191 if (!string.IsNullOrEmpty(error))
199 { 192 {
200 TraceSource.TraceEvent(TraceEventType.Error, "[{0}] {1}" , Name, error); 193 TraceSource.TraceEvent(TraceEventType.Error, "[{0}] {1}" , Name, error);
201 } 194 }
202 }, 195 },
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 return msgs.ToArray(); 261 return msgs.ToArray();
269 } 262 }
270 263
271 public void Dispose() 264 public void Dispose()
272 { 265 {
273 TraceSource.TraceEvent(TraceEventType.Information, "[{0}] Cleaning u p", Name); 266 TraceSource.TraceEvent(TraceEventType.Information, "[{0}] Cleaning u p", Name);
274 Directory.Delete(WorkingDirectory, true); 267 Directory.Delete(WorkingDirectory, true);
275 } 268 }
276 } 269 }
277 } 270 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b