Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
git2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
git2
Commits
450b40ca
Commit
450b40ca
authored
Feb 28, 2012
by
Vicent Martí
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
filter: Load attributes for file
parent
eb8f90e5
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
129 additions
and
0 deletions
+129
-0
src/filter.c
+88
-0
src/filter.h
+36
-0
src/repository.h
+5
-0
No files found.
src/filter.c
View file @
450b40ca
...
...
@@ -10,6 +10,8 @@
#include "hash.h"
#include "filter.h"
#include "git2/attr.h"
/* Fresh from Core Git. I wonder what we could use this for... */
void
git_text__stat
(
git_text_stats
*
stats
,
git_buf
*
text
)
{
...
...
@@ -130,3 +132,89 @@ int git_filter__apply(git_buf *dest, git_buf *source, git_vector *filters, const
return
GIT_SUCCESS
;
}
static
int
check_crlf
(
const
char
*
value
)
{
if
(
value
==
git_attr__true
)
return
GIT_CRLF_TEXT
;
if
(
value
==
git_attr__false
)
return
GIT_CRLF_BINARY
;
if
(
value
==
NULL
)
return
GIT_CRLF_GUESS
;
if
(
strcmp
(
value
,
"input"
)
==
0
)
return
GIT_CRLF_INPUT
;
if
(
strcmp
(
value
,
"auto"
)
==
0
)
return
GIT_CRLF_AUTO
;
return
GIT_CRLF_GUESS
;
}
static
int
check_eol
(
const
char
*
value
)
{
if
(
value
==
NULL
)
return
GIT_EOL_UNSET
;
if
(
strcmp
(
value
,
"lf"
)
==
0
)
return
GIT_EOL_LF
;
if
(
strcmp
(
value
,
"crlf"
)
==
0
)
return
GIT_EOL_CRLF
;
return
GIT_EOL_UNSET
;
}
static
int
check_ident
(
const
char
*
value
)
{
return
(
value
==
git_attr__true
);
}
#if 0
static int input_crlf_action(enum crlf_action text_attr, enum eol eol_attr)
{
if (text_attr == CRLF_BINARY)
return CRLF_BINARY;
if (eol_attr == EOL_LF)
return CRLF_INPUT;
if (eol_attr == EOL_CRLF)
return CRLF_CRLF;
return text_attr;
}
#endif
int
git_filter__load_attrs
(
git_conv_attrs
*
ca
,
git_repository
*
repo
,
const
char
*
path
)
{
#define NUM_CONV_ATTRS 5
static
const
char
*
attr_names
[
NUM_CONV_ATTRS
]
=
{
"crlf"
,
"ident"
,
"filter"
,
"eol"
,
"text"
,
};
const
char
*
attr_vals
[
NUM_CONV_ATTRS
];
int
error
;
error
=
git_attr_get_many
(
repo
,
path
,
NUM_CONV_ATTRS
,
attr_names
,
attr_vals
);
if
(
error
==
GIT_ENOTFOUND
)
{
ca
->
crlf_action
=
GIT_CRLF_GUESS
;
ca
->
eol_attr
=
GIT_EOL_UNSET
;
ca
->
ident
=
0
;
return
0
;
}
if
(
error
==
GIT_SUCCESS
)
{
ca
->
crlf_action
=
check_crlf
(
attr_vals
[
4
]);
/* text */
if
(
ca
->
crlf_action
==
GIT_CRLF_GUESS
)
ca
->
crlf_action
=
check_crlf
(
attr_vals
[
0
]);
/* clrf */
ca
->
ident
=
check_ident
(
attr_vals
[
1
]);
/* ident */
ca
->
eol_attr
=
check_eol
(
attr_vals
[
3
]);
/* eol */
return
0
;
}
return
error
;
}
src/filter.h
View file @
450b40ca
...
...
@@ -19,6 +19,41 @@ typedef enum {
GIT_FILTER_TO_ODB
}
git_filter_mode
;
typedef
enum
{
GIT_CRLF_GUESS
=
-
1
,
GIT_CRLF_BINARY
=
0
,
GIT_CRLF_TEXT
,
GIT_CRLF_INPUT
,
GIT_CRLF_CRLF
,
GIT_CRLF_AUTO
,
GIT_SAFE_CRLF_FALSE
=
0
,
GIT_SAFE_CRLF_FAIL
=
1
,
GIT_SAFE_CRLF_WARN
=
2
,
GIT_AUTO_CRLF_FALSE
=
0
,
GIT_AUTO_CRLF_TRUE
=
1
,
GIT_AUTO_CRLF_INPUT
=
-
1
,
}
git_crlf_t
;
typedef
enum
{
GIT_EOL_UNSET
,
GIT_EOL_CRLF
,
GIT_EOL_LF
,
#ifdef GIT_WIN32
GIT_EOL_NATIVE
=
GIT_EOL_CRLF
#else
GIT_EOL_NATIVE
=
GIT_EOL_LF
#endif
}
git_eol_t
;
typedef
struct
{
int
crlf_action
;
int
eol_attr
;
int
ident
;
}
git_conv_attrs
;
typedef
struct
{
/* NUL, CR, LF and CRLF counts */
unsigned
int
nul
,
cr
,
lf
,
crlf
;
...
...
@@ -28,6 +63,7 @@ typedef struct {
}
git_text_stats
;
extern
int
git_filter__load_for_file
(
git_vector
*
filters
,
git_repository
*
repo
,
const
char
*
full_path
,
int
mode
);
extern
int
git_filter__load_attrs
(
git_conv_attrs
*
ca
,
git_repository
*
repo
,
const
char
*
path
);
extern
int
git_filter__apply
(
git_buf
*
dest
,
git_buf
*
source
,
git_vector
*
filters
,
const
char
*
filename
);
/* Gather stats for a piece of text */
...
...
src/repository.h
View file @
450b40ca
...
...
@@ -46,6 +46,11 @@ struct git_repository {
unsigned
is_bare
:
1
;
unsigned
int
lru_counter
;
struct
{
int
core_eol
;
int
auto_crlf
;
}
filter_options
;
};
/* fully free the object; internal method, do not
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment