From: Junio C Hamano <gitster@pobox.com>
To: git@vger.kernel.org
Cc: pclouds@gmail.com
Subject: [PATCH 3/4] convert: make it safer to add conversion attributes
Date: Mon, 9 May 2011 15:05:00 -0700 [thread overview]
Message-ID: <1304978701-19310-4-git-send-email-gitster@pobox.com> (raw)
In-Reply-To: <1304978701-19310-1-git-send-email-gitster@pobox.com>
The places that need to pass an array of "struct git_attr_check" needed to
be careful to pass a large enough array and know what index each element
lied. Make it safer and easier to code these.
Besides, the hard-coded sequence of initializing various attributes was
too ugly after we gained more than a few attributes.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
convert.c | 48 ++++++++++++++++++++++--------------------------
1 files changed, 22 insertions(+), 26 deletions(-)
diff --git a/convert.c b/convert.c
index e0ee245..a05820b 100644
--- a/convert.c
+++ b/convert.c
@@ -475,30 +475,6 @@ static int read_convert_config(const char *var, const char *value, void *cb)
return 0;
}
-static void setup_convert_check(struct git_attr_check *check)
-{
- static struct git_attr *attr_text;
- static struct git_attr *attr_crlf;
- static struct git_attr *attr_eol;
- static struct git_attr *attr_ident;
- static struct git_attr *attr_filter;
-
- if (!attr_text) {
- attr_text = git_attr("text");
- attr_crlf = git_attr("crlf");
- attr_eol = git_attr("eol");
- attr_ident = git_attr("ident");
- attr_filter = git_attr("filter");
- user_convert_tail = &user_convert;
- git_config(read_convert_config, NULL);
- }
- check[0].attr = attr_crlf;
- check[1].attr = attr_ident;
- check[2].attr = attr_filter;
- check[3].attr = attr_eol;
- check[4].attr = attr_text;
-}
-
static int count_ident(const char *cp, unsigned long size)
{
/*
@@ -727,10 +703,30 @@ static enum crlf_action input_crlf_action(enum crlf_action text_attr, enum eol e
return text_attr;
}
+static const char *conv_attr_name[] = {
+ "crlf", "ident", "filter", "eol", "text",
+};
+#define NUM_CONV_ATTRS ARRAY_SIZE(conv_attr_name)
+
+static void setup_convert_check(struct git_attr_check *check)
+{
+ int i;
+ static struct git_attr_check ccheck[NUM_CONV_ATTRS];
+
+ if (!ccheck[0].attr) {
+ for (i = 0; i < NUM_CONV_ATTRS; i++)
+ ccheck[i].attr = git_attr(conv_attr_name[i]);
+ user_convert_tail = &user_convert;
+ git_config(read_convert_config, NULL);
+ }
+ for (i = 0; i < NUM_CONV_ATTRS; i++)
+ check[i].attr = ccheck[i].attr;
+}
+
int convert_to_git(const char *path, const char *src, size_t len,
struct strbuf *dst, enum safe_crlf checksafe)
{
- struct git_attr_check check[5];
+ struct git_attr_check check[NUM_CONV_ATTRS];
enum crlf_action crlf_action = CRLF_GUESS;
enum eol eol_attr = EOL_UNSET;
int ident = 0, ret = 0;
@@ -767,7 +763,7 @@ static int convert_to_working_tree_internal(const char *path, const char *src,
size_t len, struct strbuf *dst,
int normalizing)
{
- struct git_attr_check check[5];
+ struct git_attr_check check[NUM_CONV_ATTRS];
enum crlf_action crlf_action = CRLF_GUESS;
enum eol eol_attr = EOL_UNSET;
int ident = 0, ret = 0;
--
1.7.5.1.288.g93ebc
next prev parent reply other threads:[~2011-05-09 22:05 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-05-08 8:47 [PATCH v0 0/3] git add a-Big-file Junio C Hamano
2011-05-08 8:47 ` [PATCH v0 1/3] index_fd(): turn write_object and format_check arguments into one flag Junio C Hamano
2011-05-08 8:47 ` [PATCH v0 2/3] index_fd(): split into two helper functions Junio C Hamano
2011-05-08 8:47 ` [PATCH v0 3/3] Bigfile: teach "git add" to send a large file straight to a pack Junio C Hamano
2011-05-08 10:19 ` Nguyen Thai Ngoc Duy
2011-05-08 17:37 ` Junio C Hamano
2011-05-09 22:04 ` [PATCH 0/4] convert.c clean-up Junio C Hamano
2011-05-09 22:04 ` [PATCH 1/4] convert: rename the "eol" global variable to "core_eol" Junio C Hamano
2011-05-09 22:04 ` [PATCH 2/4] convert: give saner names to crlf/eol variables, types and functions Junio C Hamano
2011-05-09 22:05 ` Junio C Hamano [this message]
2011-05-09 22:05 ` [PATCH 4/4] convert: make it harder to screw up adding a conversion attribute Junio C Hamano
2011-05-10 12:59 ` [PATCH 0/4] convert.c clean-up Nguyen Thai Ngoc Duy
2011-05-10 14:09 ` Junio C Hamano
2011-05-09 14:05 ` [PATCH v0 3/3] Bigfile: teach "git add" to send a large file straight to a pack Shawn Pearce
2011-05-09 15:58 ` Junio C Hamano
2011-05-09 16:14 ` Junio C Hamano
2011-05-29 18:20 ` Ævar Arnfjörð Bjarmason
2011-05-29 20:29 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1304978701-19310-4-git-send-email-gitster@pobox.com \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=pclouds@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).