Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 54 additions & 14 deletions rtc2git.cli.extension/src/to/rtc/cli/migrate/git/GitMigrator.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ void addMissing(Collection<String> existing, Collection<String> adding) {
}
}

String getCommitMessage(String workItemText, String comment) {
return String.format(properties.getProperty("commit.message.format", "%1s %2s"), workItemText,
commentTranslator.translate(comment)).trim();
String getCommitMessage(String workItemNumbers, String comment, String workItemTexts) {
return String.format(properties.getProperty("commit.message.format", "%1s %2s"), workItemNumbers,
commentTranslator.translate(comment), workItemTexts).trim();
}

List<String> getGitattributeLines() {
Expand All @@ -128,11 +128,22 @@ WindowCacheConfig getWindowCacheConfig() {
return WindowCacheConfig;
}

String getCommentText(ChangeSet changeSet) {
String comment = changeSet.getComment();
String workItemText = changeSet.getWorkItems().isEmpty() ? "" : changeSet.getWorkItems().get(0).getText();
final boolean substituteWorkItemText = Boolean
.valueOf(properties.getProperty("rtc.changeset.comment.substitute", Boolean.FALSE.toString()));
if (comment.isEmpty() && substituteWorkItemText)
return workItemText;
final String format = properties.getProperty("rtc.changeset.comment.format", "%1s");
return String.format(format, comment, workItemText);
}

String getWorkItemNumbers(List<WorkItem> workItems) {
if (workItems.isEmpty()) {
return "";
}
final String format = properties.getProperty("rtc.workitem.number.format", "%s");
final String format = properties.getProperty("rtc.workitem.number.format", "%1s");
final String delimiter = properties.getProperty("rtc.workitem.number.delimiter", " ");
final StringBuilder sb = new StringBuilder();
boolean isFirst = true;
Expand All @@ -153,6 +164,32 @@ String getWorkItemNumbers(List<WorkItem> workItems) {
return sb.toString();
}

String getWorkItemTexts(List<WorkItem> workItems) {
if (workItems.isEmpty()) {
return "";
}
final String format = properties.getProperty("rtc.workitem.text.format", "%1s %2s");
final String delimiter = properties.getProperty("rtc.workitem.text.delimiter",
System.getProperty("line.separator"));
final StringBuilder sb = new StringBuilder();
boolean isFirst = true;
Formatter formatter = new Formatter(sb);
try {
for (WorkItem workItem : workItems) {
if (isFirst) {
isFirst = false;
} else {
sb.append(delimiter);
}
formatter.format(format, String.valueOf(workItem.getNumber()), workItem.getText());
}

} finally {
formatter.close();
}
return sb.toString();
}

SortedSet<String> getExistingIgnoredFiles() {
try {
TreeSet<String> exstingIgnoredFiles = new TreeSet<String>();
Expand Down Expand Up @@ -346,19 +383,19 @@ long parseConfigValue(String value, long defaultValue) {
void initialize(Properties props) {
properties = props;
commentTranslator = new CommitCommentTranslator(props);
defaultIdent = new PersonIdent(props.getProperty("user.name", "RTC 2 git"), props.getProperty("user.email",
"rtc2git@rtc.to"));
defaultIdent = new PersonIdent(props.getProperty("user.name", "RTC 2 git"),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the actual change here? Please undo those diffs, that do not actually introduce a change.

props.getProperty("user.email", "rtc2git@rtc.to"));
parseElements(props.getProperty("ignore.file.extensions", ""), ignoredFileExtensions);
// update window cache config
WindowCacheConfig cfg = getWindowCacheConfig();
cfg.setPackedGitOpenFiles((int) parseConfigValue(props.getProperty("packedgitopenfiles"),
cfg.getPackedGitOpenFiles()));
cfg.setPackedGitOpenFiles(
(int) parseConfigValue(props.getProperty("packedgitopenfiles"), cfg.getPackedGitOpenFiles()));
cfg.setPackedGitLimit(parseConfigValue(props.getProperty("packedgitlimit"), cfg.getPackedGitLimit()));
cfg.setPackedGitWindowSize((int) parseConfigValue(props.getProperty("packedgitwindowsize"),
cfg.getPackedGitWindowSize()));
cfg.setPackedGitWindowSize(
(int) parseConfigValue(props.getProperty("packedgitwindowsize"), cfg.getPackedGitWindowSize()));
cfg.setPackedGitMMAP(Boolean.parseBoolean(props.getProperty("packedgitmmap")));
cfg.setDeltaBaseCacheLimit((int) parseConfigValue(props.getProperty("deltabasecachelimit"),
cfg.getDeltaBaseCacheLimit()));
cfg.setDeltaBaseCacheLimit(
(int) parseConfigValue(props.getProperty("deltabasecachelimit"), cfg.getDeltaBaseCacheLimit()));
long sft = parseConfigValue(props.getProperty("streamfilethreshold"), cfg.getStreamFileThreshold());
cfg.setStreamFileThreshold(getMaxFileThresholdValue(sft, Runtime.getRuntime().maxMemory()));
}
Expand Down Expand Up @@ -425,8 +462,11 @@ private void runGitGc() {

@Override
public void commitChanges(ChangeSet changeset) {
gitCommit(new PersonIdent(changeset.getCreatorName(), changeset.getEmailAddress(), changeset.getCreationDate(),
0), getCommitMessage(getWorkItemNumbers(changeset.getWorkItems()), changeset.getComment()));
gitCommit(
new PersonIdent(changeset.getCreatorName(), changeset.getEmailAddress(), changeset.getCreationDate(),
0),
getCommitMessage(getWorkItemNumbers(changeset.getWorkItems()), getCommentText(changeset),
getWorkItemTexts(changeset.getWorkItems())));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.*;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -144,7 +141,7 @@ public void testGetCommitMessage() {
props.setProperty("commit.message.replacement.1", "BUG-$1 $2");
migrator.initialize(props);

assertEquals("gugus BUG-1234 gaga", migrator.getCommitMessage("gugus", "B1234: gaga"));
assertEquals("gugus BUG-1234 gaga", migrator.getCommitMessage("gugus", "B1234: gaga", ""));
}

@Test
Expand All @@ -153,7 +150,17 @@ public void testGetCommitMessage_withCustomFormat() {
migrator.init(basedir);
String lf = System.getProperty("line.separator");

assertEquals("gug%us" + lf + lf + "ga%ga", migrator.getCommitMessage("gug%us", "ga%ga"));
assertEquals("gug%us" + lf + lf + "ga%ga", migrator.getCommitMessage("gug%us", "ga%ga", ""));
}

@Test
public void testGetCommitMessage_withCustomFormat1() {
props.setProperty("commit.message.format", "%1s%n%n%2s%n%n%3s");
migrator.init(basedir);
String lf = System.getProperty("line.separator");

assertEquals("gug%us" + lf + lf + "ga%ga" + lf + lf + "gi%gl",
migrator.getCommitMessage("gug%us", "ga%ga", "gi%gl"));
}

@Test
Expand Down