Mercurial > hg > mercurial
changeset 861:3f4edc3080db
Don't call hg sparse --refresh if sparse config isn't changed
This command takes several minutes on big repos
author | Dmitry Neverov <dmitry.neverov@jetbrains.com> |
---|---|
date | Mon, 25 Aug 2014 16:28:24 +0200 |
parents | 206021e7175e |
children | 24a6ef9166ae |
files | mercurial-agent/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/ext/impl/SparseCheckoutProvider.java |
diffstat | 1 files changed, 27 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial-agent/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/ext/impl/SparseCheckoutProvider.java Fri Aug 22 20:52:31 2014 +0200 +++ b/mercurial-agent/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/ext/impl/SparseCheckoutProvider.java Mon Aug 25 16:28:24 2014 +0200 @@ -95,21 +95,24 @@ } public void call(@NotNull HgRepo repo, @NotNull String revision) throws VcsException { - writeSparseConfig(repo.getWorkingDir()); + String currentConfig = readSparseContent(repo.getWorkingDir()); + String newConfig = getSparseContentFromRules(); + if (currentConfig.equals(newConfig)) + return; + writeSparseConfig(repo.getWorkingDir(), newConfig); repo.runCommand("sparse", "--refresh"); } - private void writeSparseConfig(@NotNull File workingDir) throws VcsException { - String sparse = getSparseContent(); + private void writeSparseConfig(@NotNull File workingDir, @NotNull String sparseContent) throws VcsException { try { - FileUtil.writeToFile(new File(new File(workingDir, ".hg"), "sparse"), sparse.getBytes("UTF-8"), false); + FileUtil.writeToFile(getSparseConfig(workingDir), sparseContent.getBytes("UTF-8"), false); } catch (IOException e) { Loggers.VCS.warn("Error while writing .hg/sparse, will not do a sparse checkout", e); } } @NotNull - private String getSparseContent() { + private String getSparseContentFromRules() { StringBuilder sparse = new StringBuilder(); sparse.append("[exclude]\n"); for (FileRule rule : myRules.getExcludeRules()) { @@ -117,13 +120,26 @@ } return sparse.toString(); } + + @NotNull + private String readSparseContent(@NotNull File workingDir) { + File sparseConfig = getSparseConfig(workingDir); + if (!sparseConfig.exists()) + return ""; + try { + return FileUtil.readText(sparseConfig); + } catch (IOException e) { + Loggers.VCS.warn("Error while reading .hg/sparse, assume it was empty", e); + return ""; + } + } } private static class UndoSparseCheckout implements BeforeWorkingDirUpdateExtension { public void call(@NotNull HgRepo repo, @NotNull String revision) throws VcsException { File workingDir = repo.getWorkingDir(); - File sparseConfig = new File(new File(workingDir, ".hg"), "sparse"); + File sparseConfig = getSparseConfig(workingDir); if (sparseConfig.exists()) { Loggers.VCS.info("Remove sparse extension config and reset working directory state"); FileUtil.delete(sparseConfig); @@ -131,4 +147,9 @@ } } } + + + private static File getSparseConfig(@NotNull File workingDir) { + return new File(new File(workingDir, ".hg"), "sparse"); + } }