Signed-off-by: Johannes Schindelin <[email protected]>
---
 convert.c | 29 +++++++++++++++++++++++++++++
 convert.h |  2 ++
 2 files changed, 31 insertions(+)

diff --git a/convert.c b/convert.c
index 814e814..b458734 100644
--- a/convert.c
+++ b/convert.c
@@ -758,6 +758,35 @@ static void convert_attrs(struct conv_attrs *ca, const 
char *path)
        }
 }
 
+enum eol eol_for_path(const char *path, const char *src, size_t len)
+{
+       struct conv_attrs ca;
+       struct text_stat stats;
+
+       if (!path) {
+               memset(&ca, 0, sizeof(ca));
+               ca.crlf_action = CRLF_AUTO;
+               ca.eol_attr = EOL_UNSET;
+       } else {
+               convert_attrs(&ca, path);
+               if (ca.eol_attr == EOL_UNSET)
+                       ca.eol_attr = output_eol(ca.crlf_action);
+               if (ca.eol_attr != EOL_UNSET)
+                       return ca.eol_attr;
+       }
+       if (!len || (ca.crlf_action != CRLF_AUTO &&
+                               ca.crlf_action != CRLF_GUESS))
+               return core_eol;
+       ca.crlf_action = input_crlf_action(ca.crlf_action, ca.eol_attr);
+       gather_stats(src, len, &stats);
+       if (ca.crlf_action == CRLF_GUESS && stats.cr > stats.crlf)
+               return core_eol;
+       else if (stats.crlf)
+               return EOL_CRLF;
+       else
+               return EOL_LF;
+}
+
 int would_convert_to_git_filter_fd(const char *path)
 {
        struct conv_attrs ca;
diff --git a/convert.h b/convert.h
index d9d853c..1892867 100644
--- a/convert.h
+++ b/convert.h
@@ -33,6 +33,8 @@ enum eol {
 
 extern enum eol core_eol;
 
+extern enum eol eol_for_path(const char *path, const char *src, size_t len);
+
 /* returns 1 if *dst was used */
 extern int convert_to_git(const char *path, const char *src, size_t len,
                          struct strbuf *dst, enum safe_crlf checksafe);
-- 
2.7.0.windows.1.7.g55a05c8


--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to