Skip to content

Commit

Permalink
Improve performance of Update before deploying.
Browse files Browse the repository at this point in the history
  • Loading branch information
davidfowl committed Jan 31, 2012
1 parent 0c9a41e commit 6940c04
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 29 deletions.
9 changes: 8 additions & 1 deletion Kudu.Client/SourceControl/RemoteRepository.cs
Expand Up @@ -107,6 +107,13 @@ public void Update(string id)
_client.PostAsync("update", HttpClientHelper.CreateJsonContent(new KeyValuePair<string, string>("id", id)))
.Result
.EnsureSuccessful();
}
}

public void Update()
{
_client.PostAsync("update", new StringContent(String.Empty))
.Result
.EnsureSuccessful();
}
}
}
1 change: 1 addition & 0 deletions Kudu.Contracts/SourceControl/IRepository.cs
Expand Up @@ -18,6 +18,7 @@ public interface IRepository
void RevertFile(string path);
ChangeSet Commit(string authorName, string message);
void Update(string id);
void Update();
void Push();
}
}
36 changes: 10 additions & 26 deletions Kudu.Core/Deployment/DeploymentManager.cs
Expand Up @@ -127,7 +127,7 @@ public IEnumerable<LogEntry> GetLogEntryDetails(string id, string entryId)
{
throw new InvalidOperationException(String.Format("No log found for '{0}'.", id));
}

return new XmlLogger(_fileSystem, path).GetLogEntryDetails(entryId).ToList();
}
}
Expand Down Expand Up @@ -186,7 +186,7 @@ public void Deploy(string id)
}

}

public void Deploy()
{
IRepository repository = _repositoryManager.GetRepository();
Expand All @@ -202,35 +202,19 @@ public void Deploy()
try
{
deployStep = profiler.Step("Deploy");
string id = repository.CurrentId;

// Store the current head
string id = repository.CurrentId;

using (profiler.Step("Update to specific changeset"))
{
if (String.IsNullOrEmpty(id))
{
id = repository.GetChanges(0, 1).Single().Id;
repository.Update(id);
}

Branch activeBranch = (from b in repository.GetBranches()
let change = repository.GetDetails(b.Id)
orderby change.ChangeSet.Timestamp descending
select b).FirstOrDefault();
// Update to the default branch
repository.Update();

if (activeBranch != null)
{
// Only deploy if the active branch is the master branch
if (!activeBranch.IsMaster)
{
return;
}

repository.Update(activeBranch.Name);
id = activeBranch.Id;
}
else
// The default branch wasn't pushed then noop
if (id != repository.CurrentId)
{
repository.Update(id);
return;
}
}

Expand Down
7 changes: 6 additions & 1 deletion Kudu.Core/SourceControl/Git/GitExeRepository.cs
Expand Up @@ -154,6 +154,11 @@ public void Update(string id)
_gitExe.Execute("checkout {0} --force", id);
}

public void Update()
{
Update("master");
}

public ChangeSetDetail GetDetails(string id)
{
string show = _gitExe.Execute("show {0} -m -p --numstat --shortstat", id);
Expand Down Expand Up @@ -721,6 +726,6 @@ public static DiffRange Parse(IStringReader reader)
reader.Skip("@@");
return range;
}
}
}
}
}
8 changes: 7 additions & 1 deletion Kudu.Core/SourceControl/Git/HybridGitRepository.cs
Expand Up @@ -101,12 +101,18 @@ public void Update(string id)
_exeRepository.Update(id);
}

public void Update()
{
_exeRepository.Update();
}

public void Dispose()
{
if (_libgitRepository != null)
{
_libgitRepository.Dispose();
}
}
}

}
}
5 changes: 5 additions & 0 deletions Kudu.Core/SourceControl/Git/LibGitRepository.cs
Expand Up @@ -82,6 +82,11 @@ public void Update(string id)
throw new NotImplementedException();
}

public void Update()
{
throw new NotImplementedException();
}

public IEnumerable<ChangeSet> GetChanges()
{
return Repository.Commits.Select(CreateChangeSet);
Expand Down
5 changes: 5 additions & 0 deletions Kudu.Core/SourceControl/Hg/HgRepository.cs
Expand Up @@ -157,6 +157,11 @@ public void Update(string id)
_repository.Update(id);
}

public void Update()
{
Update("default");
}

public IEnumerable<Branch> GetBranches()
{
// Need to work around a bug in Mercurial.net where it fails to parse the output of
Expand Down
6 changes: 6 additions & 0 deletions Kudu.Core/SourceControl/NullRepository.cs
Expand Up @@ -88,5 +88,11 @@ public ChangeSet GetChangeSet(string id)
{
return null;
}


public void Update()
{

}
}
}
7 changes: 7 additions & 0 deletions Kudu.Services/SourceControl/SourceControlService.cs
Expand Up @@ -106,6 +106,13 @@ public void Update(JsonObject input)
_repository.Update((string)input["id"]);
}

[Description("Updates the repository to the default changeset.")]
[WebInvoke(UriTemplate = "update")]
public void Update()
{
_repository.Update();
}

[Description("Pushes all commited changes to the remote repository.")]
[WebInvoke(UriTemplate = "push")]
public void Push()
Expand Down

0 comments on commit 6940c04

Please sign in to comment.