Option to display line endings

Displays Windows EOL/Cr-Lf on patch diff screen. This is
optional and is controlled by a checkbox. A new column
show_line_endings is added in account_diff_preferences.

Display is similar to gitweb i.e. '\r' in dotted-line box

Bug: issue 626

Change-Id: I6128575bd2f0869a3c59e3d2fd409d5ee431ecc5
This commit is contained in:
Pravin Sethia
2012-07-04 16:17:05 +05:30
committed by Sasa Zivkov
parent e6ec46892f
commit 632653c2d0
9 changed files with 120 additions and 25 deletions

View File

@@ -75,6 +75,9 @@ public class PatchScriptSettingsPanel extends Composite implements
@UiField
CheckBox whitespaceErrors;
@UiField
CheckBox showLineEndings;
@UiField
CheckBox showTabs;
@@ -210,6 +213,7 @@ public class PatchScriptSettingsPanel extends Composite implements
colWidth.setIntValue(dp.getLineLength());
intralineDifference.setValue(dp.isIntralineDifference());
whitespaceErrors.setValue(dp.isShowWhitespaceErrors());
showLineEndings.setValue(dp.isShowLineEndings());
showTabs.setValue(dp.isShowTabs());
skipDeleted.setValue(dp.isSkipDeleted());
skipUncommented.setValue(dp.isSkipUncommented());
@@ -242,6 +246,7 @@ public class PatchScriptSettingsPanel extends Composite implements
dp.setSyntaxHighlighting(syntaxHighlighting.getValue());
dp.setIntralineDifference(intralineDifference.getValue());
dp.setShowWhitespaceErrors(whitespaceErrors.getValue());
dp.setShowLineEndings(showLineEndings.getValue());
dp.setShowTabs(showTabs.getValue());
dp.setSkipDeleted(skipDeleted.getValue());
dp.setSkipUncommented(skipUncommented.getValue());

View File

@@ -108,8 +108,8 @@ limitations under the License.
</g:CheckBox>
<br/>
<g:CheckBox
ui:field='showTabs'
text='Show Tabs'
ui:field='showLineEndings'
text='Show Line Endings'
tabIndex='8'>
<ui:attribute name='text'/>
</g:CheckBox>
@@ -117,15 +117,15 @@ limitations under the License.
<td rowspan='2'>
<g:CheckBox
ui:field='expandAllComments'
text='Expand All Comments'
ui:field='showTabs'
text='Show Tabs'
tabIndex='9'>
<ui:attribute name='text'/>
</g:CheckBox>
<br/>
<g:CheckBox
ui:field='retainHeader'
text='Retain Header On File Switch'
ui:field='expandAllComments'
text='Expand All Comments'
tabIndex='10'>
<ui:attribute name='text'/>
</g:CheckBox>
@@ -133,25 +133,32 @@ limitations under the License.
<td rowspan='2'>
<g:CheckBox
ui:field='skipUncommented'
text='Skip Uncommented Files'
ui:field='retainHeader'
text='Retain Header On File Switch'
tabIndex='11'>
<ui:attribute name='text'/>
</g:CheckBox>
<br/>
<g:CheckBox
ui:field='skipDeleted'
text='Skip Deleted Files'
ui:field='skipUncommented'
text='Skip Uncommented Files'
tabIndex='12'>
<ui:attribute name='text'/>
</g:CheckBox>
</td>
<td valign='bottom' rowspan='2'>
<g:CheckBox
ui:field='skipDeleted'
text='Skip Deleted Files'
tabIndex='13'>
<ui:attribute name='text'/>
</g:CheckBox>
<br/>
<g:CheckBox
ui:field='manualReview'
text='Manual Review'
tabIndex='13'>
tabIndex='14'>
<ui:attribute name='text'/>
</g:CheckBox>
</td>
@@ -162,14 +169,14 @@ limitations under the License.
ui:field='update'
text='Update'
styleName='{style.updateButton}'
tabIndex='14'>
tabIndex='15'>
<ui:attribute name='text'/>
</g:Button>
<g:Button
ui:field='save'
text='Save'
styleName='{style.updateButton}'
tabIndex='15'>
tabIndex='16'>
<ui:attribute name='text'/>
</g:Button>
</td>

View File

@@ -23,4 +23,5 @@ public interface PrettifyConstants extends Constants {
String wseTabAfterSpace();
String wseTrailingSpace();
String wseBareCR();
String leCR();
}

View File

@@ -1,3 +1,4 @@
wseTabAfterSpace=Whitespace error: Tab after space
wseTrailingSpace=Whitespace error: Trailing space at end of line
wseBareCR=Whitespace error: CR without LF
wseBareCR=CR without LF
leCR=Carriage Return

View File

@@ -335,6 +335,10 @@ public abstract class PrettyFormatter implements SparseHtmlFile {
html = showTrailingWhitespace(html);
}
if (diffPrefs.isShowLineEndings()){
html = showLineEndings(html);
}
if (diffPrefs.isShowTabs()) {
String t = 1 < diffPrefs.getTabSize() ? "\t" : "";
html = html.replaceAll("\t", "<span class=\"vt\">\u00BB</span>" + t);
@@ -449,12 +453,11 @@ public abstract class PrettyFormatter implements SparseHtmlFile {
} else if (end) {
if (cr == src.length() - 1) {
buf.append(src.substring(0, cr));
buf.append(src.substring(0, cr + 1));
return;
}
} else if (cr == src.length() - 2 && src.charAt(cr + 1) == '\n') {
buf.append(src.substring(0, cr));
buf.append('\n');
buf.append(src);
return;
}
@@ -499,6 +502,14 @@ public abstract class PrettyFormatter implements SparseHtmlFile {
return src;
}
private SafeHtml showLineEndings(SafeHtml src) {
final String r = "<span class=\"lecr\""
+ " title=\"" + PrettifyConstants.C.leCR() + "\"" //
+ ">\\\\r</span>";
src = src.replaceAll("\r", r);
return src;
}
private String expandTabs(String html) {
StringBuilder tmp = new StringBuilder();
int i = 0;

View File

@@ -14,6 +14,7 @@
*/
@external .wse;
@external .lecr;
@external .vt;
@external .wdd;
@external .wdi;
@@ -35,6 +36,19 @@
cursor: pointer;
}
.lecr {
border-bottom: #aaaaaa 1px dashed;
border-left: #aaaaaa 1px dashed;
padding-bottom: 0px;
margin: 0px 2px;
padding-left: 2px;
padding-right: 2px;
border-top: #aaaaaa 1px dashed;
border-right: #aaaaaa 1px dashed;
padding-top: 0px;
cursor: pointer;
}
.vt,
.vt .str,
.vt .kwd,

View File

@@ -62,6 +62,7 @@ public class AccountDiffPreference {
p.setLineLength(100);
p.setSyntaxHighlighting(true);
p.setShowWhitespaceErrors(true);
p.setShowLineEndings(true);
p.setIntralineDifference(true);
p.setShowTabs(true);
p.setContext(DEFAULT_CONTEXT);
@@ -88,28 +89,31 @@ public class AccountDiffPreference {
protected boolean showWhitespaceErrors;
@Column(id = 7)
protected boolean intralineDifference;
protected boolean showLineEndings;
@Column(id = 8)
protected boolean intralineDifference;
@Column(id = 9)
protected boolean showTabs;
/** Number of lines of context when viewing a patch. */
@Column(id = 9)
@Column(id = 10)
protected short context;
@Column(id = 10)
@Column(id = 11)
protected boolean skipDeleted;
@Column(id = 11)
@Column(id = 12)
protected boolean skipUncommented;
@Column(id = 12)
@Column(id = 13)
protected boolean expandAllComments;
@Column(id = 13)
@Column(id = 14)
protected boolean retainHeader;
@Column(id = 14)
@Column(id = 15)
protected boolean manualReview;
protected AccountDiffPreference() {
@@ -126,6 +130,7 @@ public class AccountDiffPreference {
this.lineLength = p.lineLength;
this.syntaxHighlighting = p.syntaxHighlighting;
this.showWhitespaceErrors = p.showWhitespaceErrors;
this.showLineEndings = p.showLineEndings;
this.intralineDifference = p.intralineDifference;
this.showTabs = p.showTabs;
this.skipDeleted = p.skipDeleted;
@@ -180,6 +185,14 @@ public class AccountDiffPreference {
this.showWhitespaceErrors = showWhitespaceErrors;
}
public boolean isShowLineEndings() {
return showLineEndings;
}
public void setShowLineEndings(boolean showLineEndings) {
this.showLineEndings = showLineEndings;
}
public boolean isIntralineDifference() {
return intralineDifference;
}

View File

@@ -32,7 +32,7 @@ import java.util.List;
/** A version of the database schema. */
public abstract class SchemaVersion {
/** The current schema version. */
public static final Class<Schema_70> C = Schema_70.class;
public static final Class<Schema_71> C = Schema_71.class;
public static class Module extends AbstractModule {
@Override

View File

@@ -0,0 +1,43 @@
// Copyright (C) 2012 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.gerrit.server.schema;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gwtorm.jdbc.JdbcSchema;
import com.google.inject.Inject;
import com.google.inject.Provider;
import java.sql.SQLException;
import java.sql.Statement;
public class Schema_71 extends SchemaVersion {
@Inject
Schema_71(Provider<Schema_70> prior) {
super(prior);
}
@Override
protected void migrateData(final ReviewDb db, final UpdateUI ui)
throws SQLException {
final Statement stmt = ((JdbcSchema) db).getConnection().createStatement();
try {
stmt.executeUpdate("UPDATE account_diff_preferences SET show_line_endings='Y'");
}
finally {
stmt.close();
}
}
}