Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitaff6bfe

Browse files
committed
fixes#193 - allow to parse copy commands from a diff
1 parent5cc2cf4 commitaff6bfe

File tree

4 files changed

+68
-0
lines changed

4 files changed

+68
-0
lines changed

‎java-diff-utils/src/main/java/com/github/difflib/unifieddiff/UnifiedDiffFile.java‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ public final class UnifiedDiffFile {
3030
privateStringtoFile;
3131
privateStringrenameFrom;
3232
privateStringrenameTo;
33+
privateStringcopyFrom;
34+
privateStringcopyTo;
3335
privateStringtoTimestamp;
3436
privateStringindex;
3537
privateStringnewFileMode;
@@ -119,6 +121,22 @@ public void setRenameTo(String renameTo) {
119121
this.renameTo =renameTo;
120122
}
121123

124+
publicStringgetCopyFrom() {
125+
returncopyFrom;
126+
}
127+
128+
publicvoidsetCopyFrom(StringcopyFrom) {
129+
this.copyFrom =copyFrom;
130+
}
131+
132+
publicStringgetCopyTo() {
133+
returncopyTo;
134+
}
135+
136+
publicvoidsetCopyTo(StringcopyTo) {
137+
this.copyTo =copyTo;
138+
}
139+
122140
publicstaticUnifiedDiffFilefrom(StringfromFile,StringtoFile,Patch<String>patch) {
123141
UnifiedDiffFilefile =newUnifiedDiffFile();
124142
file.setFromFile(fromFile);

‎java-diff-utils/src/main/java/com/github/difflib/unifieddiff/UnifiedDiffReader.java‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ public final class UnifiedDiffReader {
5151
privatefinalUnifiedDiffLineTO_FILE =newUnifiedDiffLine(true,"^\\+\\+\\+\\s",this::processToFile);
5252
privatefinalUnifiedDiffLineRENAME_FROM =newUnifiedDiffLine(true,"^rename\\sfrom\\s(.+)$",this::processRenameFrom);
5353
privatefinalUnifiedDiffLineRENAME_TO =newUnifiedDiffLine(true,"^rename\\sto\\s(.+)$",this::processRenameTo);
54+
55+
privatefinalUnifiedDiffLineCOPY_FROM =newUnifiedDiffLine(true,"^copy\\sfrom\\s(.+)$",this::processCopyFrom);
56+
privatefinalUnifiedDiffLineCOPY_TO =newUnifiedDiffLine(true,"^copy\\sto\\s(.+)$",this::processCopyTo);
5457

5558
privatefinalUnifiedDiffLineNEW_FILE_MODE =newUnifiedDiffLine(true,"^new\\sfile\\smode\\s(\\d+)",this::processNewFileMode);
5659

@@ -103,6 +106,7 @@ private UnifiedDiff parse() throws IOException, UnifiedDiffParserException {
103106
if (validLine(line,DIFF_COMMAND,SIMILARITY_INDEX,INDEX,
104107
FROM_FILE,TO_FILE,
105108
RENAME_FROM,RENAME_TO,
109+
COPY_FROM,COPY_TO,
106110
NEW_FILE_MODE,DELETED_FILE_MODE,
107111
OLD_MODE,NEW_MODE,
108112
BINARY_ADDED,BINARY_DELETED,
@@ -122,6 +126,7 @@ private UnifiedDiff parse() throws IOException, UnifiedDiffParserException {
122126
if (!processLine(line,DIFF_COMMAND,SIMILARITY_INDEX,INDEX,
123127
FROM_FILE,TO_FILE,
124128
RENAME_FROM,RENAME_TO,
129+
COPY_FROM,COPY_TO,
125130
NEW_FILE_MODE,DELETED_FILE_MODE,
126131
OLD_MODE,NEW_MODE,
127132
BINARY_ADDED ,BINARY_DELETED,
@@ -344,6 +349,14 @@ private void processRenameFrom(MatchResult match, String line) {
344349
privatevoidprocessRenameTo(MatchResultmatch,Stringline) {
345350
actualFile.setRenameTo(match.group(1));
346351
}
352+
353+
privatevoidprocessCopyFrom(MatchResultmatch,Stringline) {
354+
actualFile.setCopyFrom(match.group(1));
355+
}
356+
357+
privatevoidprocessCopyTo(MatchResultmatch,Stringline) {
358+
actualFile.setCopyTo(match.group(1));
359+
}
347360

348361
privatevoidprocessNewFileMode(MatchResultmatch,Stringline) {
349362
//initFileIfNecessary();

‎java-diff-utils/src/test/java/com/github/difflib/unifieddiff/UnifiedDiffReaderTest.java‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,4 +435,15 @@ public void testParseIssue182mode() throws IOException {
435435
assertThat(file1.getOldMode()).isEqualTo("100644");
436436
assertThat(file1.getNewMode()).isEqualTo("100755");
437437
}
438+
439+
@Test
440+
publicvoidtestParseIssue193Copy()throwsIOException {
441+
UnifiedDiffdiff =UnifiedDiffReader.parseUnifiedDiff(
442+
UnifiedDiffReaderTest.class.getResourceAsStream("problem_diff_parsing_issue193.diff"));
443+
444+
UnifiedDiffFilefile1 =diff.getFiles().get(0);
445+
446+
assertThat(file1.getCopyFrom()).isEqualTo("modules/configuration/config/web/pcf/account/AccountContactCV.pcf");
447+
assertThat(file1.getCopyTo()).isEqualTo("modules/configuration/config/web/pcf/account/AccountContactCV.default.pcf");
448+
}
438449
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
diff --git src://modules/configuration/config/web/pcf/account/AccountContactCV.pcf dst://modules/configuration/config/web/pcf/account/AccountContactCV.default.pcf
2+
similarity index 99%
3+
copy from modules/configuration/config/web/pcf/account/AccountContactCV.pcf
4+
copy to modules/configuration/config/web/pcf/account/AccountContactCV.default.pcf
5+
index 13efef5778..1a08b0befc 100644
6+
--- src://modules/configuration/config/web/pcf/account/AccountContactCV.pcf
7+
+++ dst://modules/configuration/config/web/pcf/account/AccountContactCV.default.pcf
8+
@@ -1,16 +1,17 @@
9+
<?xml version="1.0"?>
10+
<PCF
11+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
12+
xsi:noNamespaceSchemaLocation="../../../../../pcf.xsd">
13+
<CardViewPanel
14+
- id="AccountContactCV">
15+
+ id="AccountContactCV"
16+
+ mode="default">
17+
<Require
18+
name="acctContact"
19+
type="AccountContact"/>
20+
<Require
21+
name="showAddressTools"
22+
type="boolean"/>
23+
<Require
24+
name="showRolesTab"
25+
type="boolean"/>
26+
<Variable

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp