convert.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /*
  2. * Copyright (c) 2011, Google Inc.
  3. */
  4. #ifndef CONVERT_H
  5. #define CONVERT_H
  6. #include "hash.h"
  7. #include "string-list.h"
  8. struct index_state;
  9. struct strbuf;
  10. #define CONV_EOL_RNDTRP_DIE (1<<0) /* Die if CRLF to LF to CRLF is different */
  11. #define CONV_EOL_RNDTRP_WARN (1<<1) /* Warn if CRLF to LF to CRLF is different */
  12. #define CONV_EOL_RENORMALIZE (1<<2) /* Convert CRLF to LF */
  13. #define CONV_EOL_KEEP_CRLF (1<<3) /* Keep CRLF line endings as is */
  14. #define CONV_WRITE_OBJECT (1<<4) /* Content is written to the index */
  15. extern int global_conv_flags_eol;
  16. enum auto_crlf {
  17. AUTO_CRLF_FALSE = 0,
  18. AUTO_CRLF_TRUE = 1,
  19. AUTO_CRLF_INPUT = -1
  20. };
  21. extern enum auto_crlf auto_crlf;
  22. enum eol {
  23. EOL_UNSET,
  24. EOL_CRLF,
  25. EOL_LF,
  26. #ifdef NATIVE_CRLF
  27. EOL_NATIVE = EOL_CRLF
  28. #else
  29. EOL_NATIVE = EOL_LF
  30. #endif
  31. };
  32. enum ce_delay_state {
  33. CE_NO_DELAY = 0,
  34. CE_CAN_DELAY = 1,
  35. CE_RETRY = 2
  36. };
  37. struct delayed_checkout {
  38. /*
  39. * State of the currently processed cache entry. If the state is
  40. * CE_CAN_DELAY, then the filter can delay the current cache entry.
  41. * If the state is CE_RETRY, then this signals the filter that the
  42. * cache entry was requested before.
  43. */
  44. enum ce_delay_state state;
  45. /* List of filter drivers that signaled delayed blobs. */
  46. struct string_list filters;
  47. /* List of delayed blobs identified by their path. */
  48. struct string_list paths;
  49. };
  50. struct checkout_metadata {
  51. const char *refname;
  52. struct object_id treeish;
  53. struct object_id blob;
  54. };
  55. extern enum eol core_eol;
  56. extern char *check_roundtrip_encoding;
  57. const char *get_cached_convert_stats_ascii(const struct index_state *istate,
  58. const char *path);
  59. const char *get_wt_convert_stats_ascii(const char *path);
  60. const char *get_convert_attr_ascii(const struct index_state *istate,
  61. const char *path);
  62. /* returns 1 if *dst was used */
  63. int convert_to_git(const struct index_state *istate,
  64. const char *path, const char *src, size_t len,
  65. struct strbuf *dst, int conv_flags);
  66. int convert_to_working_tree(const struct index_state *istate,
  67. const char *path, const char *src,
  68. size_t len, struct strbuf *dst,
  69. const struct checkout_metadata *meta);
  70. int async_convert_to_working_tree(const struct index_state *istate,
  71. const char *path, const char *src,
  72. size_t len, struct strbuf *dst,
  73. const struct checkout_metadata *meta,
  74. void *dco);
  75. int async_query_available_blobs(const char *cmd,
  76. struct string_list *available_paths);
  77. int renormalize_buffer(const struct index_state *istate,
  78. const char *path, const char *src, size_t len,
  79. struct strbuf *dst);
  80. static inline int would_convert_to_git(const struct index_state *istate,
  81. const char *path)
  82. {
  83. return convert_to_git(istate, path, NULL, 0, NULL, 0);
  84. }
  85. /* Precondition: would_convert_to_git_filter_fd(path) == true */
  86. void convert_to_git_filter_fd(const struct index_state *istate,
  87. const char *path, int fd,
  88. struct strbuf *dst,
  89. int conv_flags);
  90. int would_convert_to_git_filter_fd(const struct index_state *istate,
  91. const char *path);
  92. /*
  93. * Initialize the checkout metadata with the given values. Any argument may be
  94. * NULL if it is not applicable. The treeish should be a commit if that is
  95. * available, and a tree otherwise.
  96. *
  97. * The refname is not copied and must be valid for the lifetime of the struct.
  98. * THe object IDs are copied.
  99. */
  100. void init_checkout_metadata(struct checkout_metadata *meta, const char *refname,
  101. const struct object_id *treeish,
  102. const struct object_id *blob);
  103. /* Copy the metadata from src to dst, updating the blob. */
  104. void clone_checkout_metadata(struct checkout_metadata *dst,
  105. const struct checkout_metadata *src,
  106. const struct object_id *blob);
  107. /*
  108. * Reset the internal list of attributes used by convert_to_git and
  109. * convert_to_working_tree.
  110. */
  111. void reset_parsed_attributes(void);
  112. /*****************************************************************
  113. *
  114. * Streaming conversion support
  115. *
  116. *****************************************************************/
  117. struct stream_filter; /* opaque */
  118. struct stream_filter *get_stream_filter(const struct index_state *istate,
  119. const char *path,
  120. const struct object_id *);
  121. void free_stream_filter(struct stream_filter *);
  122. int is_null_stream_filter(struct stream_filter *);
  123. /*
  124. * Use as much input up to *isize_p and fill output up to *osize_p;
  125. * update isize_p and osize_p to indicate how much buffer space was
  126. * consumed and filled. Return 0 on success, non-zero on error.
  127. *
  128. * Some filters may need to buffer the input and look-ahead inside it
  129. * to decide what to output, and they may consume more than zero bytes
  130. * of input and still not produce any output. After feeding all the
  131. * input, pass NULL as input and keep calling this function, to let
  132. * such filters know there is no more input coming and it is time for
  133. * them to produce the remaining output based on the buffered input.
  134. */
  135. int stream_filter(struct stream_filter *,
  136. const char *input, size_t *isize_p,
  137. char *output, size_t *osize_p);
  138. #endif /* CONVERT_H */