>
> I think that it would be better to separate format detection,
> unidiff/git-style patch application, and xpatch application into different
> API methods. Let me provide you with declaration of such functions, that
> I've just wrote and explained with the corresponding docstrings:
>
> [[[
> /* Describes the patch format. */
> typedef enum svn_client_patch_format_t
> {
> /* Unrecognized or unknown format.
> *
> * ### Do we actually need this?
> */
> unknown = -1,
>
> /* Either unidiff or git style patch */
> unidiff = 0,
>
> /* Extended Subversion patch -- xpatch
> *
> * ### Better description?
> */
> xpatch,
> };
>
> /**
> * Apply an xpatch, described in readable @a xpatch_file stream, onto a
> * working at @a target_wcpath.
> *
> * Use @a pool for any temporary allocation.
> */
> svn_error_t *
> svn_client_xpatch_apply(svn_stream_t *xpatch_file,
> const char *target_wcpath,
> /* TODO: other arguments from the
> * svn_client__apply_processor_create() function */
> svn_client_ctx_t *ctx,
> apr_pool_t *pool);
>
> /**
> * Detect the format of @a patch_file, setting @a format with the detected
> * format.
> */
> svn_error_t *
> svn_client_detect_patch_format(apr_file_t *patch_file,
> svn_client_patch_format_t *format);
> ]]]
>
Hi again,
I have an alternative suggestion for the format-detection API:
Instead of svn_client_detect_patch_format(), a function that checks whether
it's xpatch or not. I mean that we won't provide a function for detecting
the exact format, but we'll have a function like
svn_client_patch_is_xpatch(), returning a boolean value (probably as an
output argument, since the filesystem API may throw an exception). The
drafted declaration can be accessed below:
[[[
/**
* Detect whether the format of @a patch_file is xpatch or not. The result
* should be available at @a is_xpatch.
*
* Use @a scratch_pool for any temporary allocation.
*/
svn_error_t *
svn_client_patch_is_xpatch(apr_file_t *patch_file,
svn_boolean_t *is_xpatch,
apr_pool_t *scratch_pool);
]]]
Additionally, I'd like to add that a single function for applying unidiff
patches and xpatches would not deal with a switch for forcing the format
that we wanted to add to the command-line (I mean something like `svn patch
--format xpatch`). That's because it's a bit incorrect to add such an
argument to the svn_client API. It's svn-exe's responsibility, to handle
this switch, over the format detected automatically. Let's not
overcomplicate our life!
--
Timofei Zhakov