Author: julianfoad Date: Tue Nov 20 16:17:09 2012 New Revision: 1411723 URL: http://svn.apache.org/viewvc?rev=1411723&view=rev Log: Improve handling of "\ No newline at end of file" lines in diff and patch.
Since this feature of unified diff is not well standardized, go for maximum portability by not localizing this message when we generate it (which we were doing in some cases) and not requiring any particular text other than the initial '\' when we read a patch file. Found by: brane * subversion/libsvn_client/diff.c, subversion/svnlook/main.c (display_prop_diffs): Tweak a comment for white-space correctness. Ugh -- why is this code duplicated? * subversion/libsvn_diff/diff_file.c (output_unified_line): Stop localizing the "No newline" string. Make this code exactly the same as in diff_memory.c. Ugh -- why is this code duplicated? * subversion/libsvn_diff/diff_memory.c (output_unified_token_range): Tweak a comment about interoperability. * subversion/libsvn_diff/parse-diff.c (parse_next_hunk): For recognizing no-newline-at-end, don't require the exact message '\ No newline ...', but just an initial '\'. Modified: subversion/trunk/subversion/libsvn_client/diff.c subversion/trunk/subversion/libsvn_diff/diff_file.c subversion/trunk/subversion/libsvn_diff/diff_memory.c subversion/trunk/subversion/libsvn_diff/parse-diff.c subversion/trunk/subversion/svnlook/main.c Modified: subversion/trunk/subversion/libsvn_client/diff.c URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_client/diff.c?rev=1411723&r1=1411722&r2=1411723&view=diff ============================================================================== --- subversion/trunk/subversion/libsvn_client/diff.c (original) +++ subversion/trunk/subversion/libsvn_client/diff.c Tue Nov 20 16:17:09 2012 @@ -678,8 +678,8 @@ display_prop_diffs(const apr_array_heade /* The last character in a property is often not a newline. An eol character is appended to prevent the diff API to add a - ' \ No newline at end of file' line. We add - ' \ No newline at end of property' manually if needed. */ + '\ No newline at end of file' line. We add + '\ No newline at end of property' manually if needed. */ tmp = original_value ? original_value : svn_string_create_empty(iterpool); orig = maybe_append_eol(tmp, NULL, iterpool); Modified: subversion/trunk/subversion/libsvn_diff/diff_file.c URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_diff/diff_file.c?rev=1411723&r1=1411722&r2=1411723&view=diff ============================================================================== --- subversion/trunk/subversion/libsvn_diff/diff_file.c (original) +++ subversion/trunk/subversion/libsvn_diff/diff_file.c Tue Nov 20 16:17:09 2012 @@ -1492,12 +1492,12 @@ output_unified_line(svn_diff__file_outpu && ! had_cr) { const char *out_str; - SVN_ERR(svn_utf_cstring_from_utf8_ex2 - (&out_str, - apr_psprintf(baton->pool, - APR_EOL_STR "\\ %s" APR_EOL_STR, - _("No newline at end of file")), - baton->header_encoding, baton->pool)); + SVN_ERR(svn_utf_cstring_from_utf8_ex2( + &out_str, + /* The string below is intentionally not marked for translation, + for wider interoperability with patch(1) programs. */ + APR_EOL_STR "\\ No newline at end of file" APR_EOL_STR, + baton->header_encoding, baton->pool)); svn_stringbuf_appendcstr(baton->hunk, out_str); } Modified: subversion/trunk/subversion/libsvn_diff/diff_memory.c URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_diff/diff_memory.c?rev=1411723&r1=1411722&r2=1411723&view=diff ============================================================================== --- subversion/trunk/subversion/libsvn_diff/diff_memory.c (original) +++ subversion/trunk/subversion/libsvn_diff/diff_memory.c Tue Nov 20 16:17:09 2012 @@ -420,9 +420,8 @@ output_unified_token_range(output_baton_ const char *out_str; SVN_ERR(svn_utf_cstring_from_utf8_ex2 (&out_str, - /* The string below is intentionally not marked for translation: - it's vital to correct operation of the diff(1)/patch(1) - program pair. */ + /* The string below is intentionally not marked for translation, + for wider interoperability with patch(1) programs. */ APR_EOL_STR "\\ No newline at end of file" APR_EOL_STR, btn->header_encoding, btn->pool)); svn_stringbuf_appendcstr(btn->hunk, out_str); Modified: subversion/trunk/subversion/libsvn_diff/parse-diff.c URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_diff/parse-diff.c?rev=1411723&r1=1411722&r2=1411723&view=diff ============================================================================== --- subversion/trunk/subversion/libsvn_diff/parse-diff.c (original) +++ subversion/trunk/subversion/libsvn_diff/parse-diff.c Tue Nov 20 16:17:09 2012 @@ -555,15 +555,11 @@ parse_next_hunk(svn_diff_hunk_t **hunk, pos = 0; SVN_ERR(svn_io_file_seek(apr_file, APR_CUR, &pos, iterpool)); - /* Lines starting with a backslash are comments, such as - * "\ No newline at end of file". */ + /* Lines starting with a backslash indicate a missing EOL: + * "\ No newline at end of file" or "end of property". */ if (line->data[0] == '\\') { - if (in_hunk && - ((!*is_property && - strcmp(line->data, "\\ No newline at end of file") == 0) || - (*is_property && - strcmp(line->data, "\\ No newline at end of property") == 0))) + if (in_hunk) { char eolbuf[2]; apr_size_t len; Modified: subversion/trunk/subversion/svnlook/main.c URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/svnlook/main.c?rev=1411723&r1=1411722&r2=1411723&view=diff ============================================================================== --- subversion/trunk/subversion/svnlook/main.c (original) +++ subversion/trunk/subversion/svnlook/main.c Tue Nov 20 16:17:09 2012 @@ -887,8 +887,8 @@ display_prop_diffs(const apr_array_heade /* The last character in a property is often not a newline. An eol character is appended to prevent the diff API to add a - ' \ No newline at end of file' line. We add - ' \ No newline at end of property' manually if needed. */ + '\ No newline at end of file' line. We add + '\ No newline at end of property' manually if needed. */ tmp = orig_value ? orig_value : svn_string_create_empty(pool); orig = maybe_append_eol(tmp, NULL, pool);