144
unsigned int old_mode, new_mode;
145
int is_new, is_delete; /* -1 = unknown, 0 = false, 1 = true */
146
int rejected;
147
+ unsigned ws_rule;
148
unsigned long deflate_origlen;
149
int lines_added, lines_deleted;
150
int score;
899
return -1;
900
}
901
901
-static void check_whitespace(const char *line, int len)
902
+static void check_whitespace(const char *line, int len, unsigned ws_rule)
903
{
904
const char *err = "Adds trailing whitespace";
905
int seen_space = 0;
911
* this function. That is, an addition of an empty line would
912
* check the '+' here. Sneaky...
913
*/
913
- if ((whitespace_rule & WS_TRAILING_SPACE) && isspace(line[len-2]))
914
+ if ((ws_rule & WS_TRAILING_SPACE) && isspace(line[len-2]))
915
goto error;
916
917
/*
918
* Make sure that there is no space followed by a tab in
919
* indentation.
920
*/
920
- if (whitespace_rule & WS_SPACE_BEFORE_TAB) {
921
+ if (ws_rule & WS_SPACE_BEFORE_TAB) {
922
err = "Space in indent is followed by a tab";
923
for (i = 1; i < len; i++) {
924
if (line[i] == '\t') {
936
* Make sure that the indentation does not contain more than
937
* 8 spaces.
938
*/
938
- if ((whitespace_rule & WS_INDENT_WITH_NON_TAB) &&
939
+ if ((ws_rule & WS_INDENT_WITH_NON_TAB) &&
940
(8 < len) && !strncmp("+ ", line, 9)) {
941
err = "Indent more than 8 places with spaces";
942
goto error;
1002
case '-':
1003
if (apply_in_reverse &&
1004
ws_error_action != nowarn_ws_error)
1004
- check_whitespace(line, len);
1005
+ check_whitespace(line, len, patch->ws_rule);
1006
deleted++;
1007
oldlines--;
1008
trailing = 0;
1010
case '+':
1011
if (!apply_in_reverse &&
1012
ws_error_action != nowarn_ws_error)
1012
- check_whitespace(line, len);
1013
+ check_whitespace(line, len, patch->ws_rule);
1014
added++;
1015
newlines--;
1016
trailing = 0;
1319
if (offset < 0)
1320
return offset;
1321
1322
+ patch->ws_rule = whitespace_rule(patch->new_name
1323
+ ? patch->new_name
1324
+ : patch->old_name);
1325
+
1326
patchsize = parse_single_patch(buffer + offset + hdrsize,
1327
size - offset - hdrsize, patch);
1328
1573
*rsize = offset + 1;
1574
}
1575
1571
-static int apply_line(char *output, const char *patch, int plen)
1576
+static int apply_line(char *output, const char *patch, int plen,
1577
+ unsigned ws_rule)
1578
{
1579
/*
1580
* plen is number of bytes to be copied from patch,
1599
/*
1600
* Strip trailing whitespace
1601
*/
1596
- if ((whitespace_rule & WS_TRAILING_SPACE) &&
1602
+ if ((ws_rule & WS_TRAILING_SPACE) &&
1603
(1 < plen && isspace(patch[plen-1]))) {
1604
if (patch[plen] == '\n')
1605
add_nl_to_tail = 1;
1616
char ch = patch[i];
1617
if (ch == '\t') {
1618
last_tab_in_indent = i;
1613
- if ((whitespace_rule & WS_SPACE_BEFORE_TAB) &&
1619
+ if ((ws_rule & WS_SPACE_BEFORE_TAB) &&
1620
0 <= last_space_in_indent)
1621
need_fix_leading_space = 1;
1622
} else if (ch == ' ') {
1623
last_space_in_indent = i;
1618
- if ((whitespace_rule & WS_INDENT_WITH_NON_TAB) &&
1624
+ if ((ws_rule & WS_INDENT_WITH_NON_TAB) &&
1625
last_tab_in_indent < 0 &&
1626
8 <= i)
1627
need_fix_leading_space = 1;
1635
int consecutive_spaces = 0;
1636
int last = last_tab_in_indent + 1;
1637
1632
- if (whitespace_rule & WS_INDENT_WITH_NON_TAB) {
1638
+ if (ws_rule & WS_INDENT_WITH_NON_TAB) {
1639
/* have "last" point at one past the indent */
1640
if (last_tab_in_indent < last_space_in_indent)
1641
last = last_space_in_indent + 1;
1677
}
1678
1679
static int apply_one_fragment(struct strbuf *buf, struct fragment *frag,
1674
- int inaccurate_eof)
1680
+ int inaccurate_eof, unsigned ws_rule)
1681
{
1682
int match_beginning, match_end;
1683
const char *patch = frag->patch;
1736
case '+':
1737
if (first != '+' || !no_add) {
1738
int added = apply_line(new + newsize, patch,
1733
- plen);
1739
+ plen, ws_rule);
1740
newsize += added;
1741
if (first == '+' &&
1742
added == 1 && new[newsize-1] == '\n')
1959
{
1960
struct fragment *frag = patch->fragments;
1961
const char *name = patch->old_name ? patch->old_name : patch->new_name;
1962
+ unsigned ws_rule = patch->ws_rule;
1963
+ unsigned inaccurate_eof = patch->inaccurate_eof;
1964
1965
if (patch->is_binary)
1966
return apply_binary(buf, patch);
1967
1968
while (frag) {
1961
- if (apply_one_fragment(buf, frag, patch->inaccurate_eof)) {
1969
+ if (apply_one_fragment(buf, frag, inaccurate_eof, ws_rule)) {
1970
error("patch failed: %s:%ld", name, frag->oldpos);
1971
if (!apply_with_reject)
1972
return -1;