Skip to content

Commit f448adb

Browse files
committed
setFileContent() using VCSChangeListNode
1 parent 7eee07a commit f448adb

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

src/main/java/org/scm4j/vcs/svn/SVNVCS.java

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -253,37 +253,38 @@ private String getBranchName(String branchName) {
253253
}
254254

255255
@Override
256-
public VCSCommit setFilesContent(String branchName, List<String> filePathes, List<String> contents, String commitMessage) {
257-
if (filePathes.isEmpty()) {
256+
public VCSCommit setFileContent(String branchName, List<VCSChangeListNode> vcsChangeList) {
257+
if (vcsChangeList.isEmpty()) {
258258
return null;
259259
}
260260
try (IVCSLockedWorkingCopy wc = repo.getVCSLockedWorkingCopy()) {
261261
checkout(getBranchUrl(branchName), wc.getFolder(), null);
262-
int contentId = 0;
263-
for (int filePathId = 0; filePathId < filePathes.size(); filePathId++) {
264-
String filePath = filePathes.get(filePathId);
262+
StringBuilder commitMessageSB = new StringBuilder();
263+
for (VCSChangeListNode vcsChangeListNode : vcsChangeList) {
264+
String filePath = vcsChangeListNode.getFilePath();
265265
File file = new File(wc.getFolder(), filePath);
266266
Boolean needToAdd = !file.exists();
267267
if (needToAdd) {
268268
FileUtils.forceMkdir(file.getParentFile());
269269
file.createNewFile();
270270
}
271271

272-
String content = contents.get(contentId);
273-
FileWriter writer = new FileWriter(file);
274-
writer.write(content);
275-
writer.close();
276-
contentId++;
277-
272+
try (FileWriter writer = new FileWriter(file)) {
273+
writer.write(vcsChangeListNode.getContent());
274+
}
275+
278276
if (needToAdd) {
279277
clientManager
280278
.getWCClient()
281279
.doAdd(file,
282280
true /* force, avoiding "file is already under version control" exception */,
283281
false, false, SVNDepth.EMPTY, false, true);
284282
}
283+
commitMessageSB.append(vcsChangeListNode.getLogMessage() + VCSChangeListNode.COMMIT_MESSAGES_SEPARATOR);
285284
}
286285

286+
commitMessageSB.setLength(commitMessageSB.length() - VCSChangeListNode.COMMIT_MESSAGES_SEPARATOR.length());
287+
String commitMessage = commitMessageSB.toString();
287288
try {
288289
SVNCommitInfo newCommit = clientManager
289290
.getCommitClient()
@@ -304,7 +305,7 @@ public VCSCommit setFilesContent(String branchName, List<String> filePathes, Lis
304305

305306
@Override
306307
public VCSCommit setFileContent(String branchName, String filePath, String content, String commitMessage) {
307-
return setFilesContent(branchName, Collections.singletonList(filePath), Collections.singletonList(content), commitMessage);
308+
return setFileContent(branchName, Collections.singletonList(new VCSChangeListNode(filePath, content, commitMessage)));
308309
}
309310

310311
@Override

0 commit comments

Comments
 (0)