What happen if show_http_message fails to reencode?

2015-04-19 Thread Yi, EungJun
I'm trying to make my git server sends http messages in non-ASCII
encoding. And I have a question.

At 206-218 in remote-curl.c:

> static int show_http_message(struct strbuf *type, struct strbuf *charset,
>  struct strbuf *msg)
> {
> const char *p, *eol;
>
> /*
>  * We only show text/plain parts, as other types are likely
>  * to be ugly to look at on the user's terminal.
>  */
> if (strcmp(type->buf, "text/plain"))
> return -1;
> if (charset->len)
> strbuf_reencode(msg, charset->buf, get_log_output_encoding());

What happen if the message has a character which cannot be encoded by
the encoding defined by i18n.logoutputencoding? Drops only the
character or brakes the whole message?

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


Re: Git + SFC Status Update

2015-04-16 Thread Yi EungJun
>  - Written policy: https://git-scm.com/trademark

My browser shows an "Untrusted Connection" page when click the link.

Does git-scm have no TLS certificate?



--
View this message in context: 
http://git.661346.n2.nabble.com/Git-SFC-Status-Update-tp7628669p7628850.html
Sent from the git mailing list archive at Nabble.com.
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: How to send a warning message from git hosting server?

2015-04-12 Thread Yi, EungJun
On Wed, Apr 8, 2015 at 8:08 PM, Tony Finch  wrote:
> Yi, EungJun  wrote:
>>
>> I want a way to response a remote message when a client send any kind
>> of request. Is it possible?
>
> Yes, though you need a wrapper around git. Recent versions of gitolite
> have a "motd" message of the day feature.

It sounds nice. Is the wrapper for git client or git server?
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


How to send a warning message from git hosting server?

2015-04-05 Thread Yi, EungJun
Hello. I am serving a git hosting service for my company.

Sometimes I want to send a warning message to users who use my
service; e.g. the service will be shutdown tomorrow for a while
temporary.

I know it is possible to a remote message by hooks or HTTP body if an
error occured. But it seems that there is no hooks for git-fetch and
git does not print HTTP body if there is no error.

I want a way to response a remote message when a client send any kind
of request. Is it possible?

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


Feature request: Update remote url if it is redirected.

2015-04-05 Thread Yi, EungJun
Some git hosting services, like Github, a url to a git repository can
be changed by changing the name of the repository by the owner. If
someone tries to get the repository with the old url, usually the
hosting service serves the request with the repository indiciated by
the new url. It is very helpful for the users who don't know the url
has been changed.

In such case, I think it is recommended to update the user's remote
url with the new one because the old url possibily does not work if
the hosting service does not keep the old url anymore, or worse, works
incorrectly if someone makes a repository with the old url.

To fix the potential problem, it would be nice if Git client asks the
user, while fetching objects from a remote url, to update the url if
it is changed. If the client and the server is talking in HTTP, it is
easy to know the url is changed if the server responses with 301 Moved
Permantely or 308 Permanet Redirect.
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v3] diff-highlight: do not split multibyte characters

2015-04-04 Thread Yi, EungJun
On Fri, Apr 3, 2015 at 10:24 AM, Jeff King  wrote:
>
> EungJun, does this version meet your needs?
>
> -Peff

Yes, this patch is enough to meet my needs because it works well on
UTF-8, the only encoding I use. And this patch looks better than my
one because it is smaller, doesn't depend on String::Multibyte and
seems to have no side-effect.

I hope someone who use another multibyte encoding will send a patch to
support the encoding in future... :)

On Sat, Apr 4, 2015 at 11:09 PM, Jeff King  wrote:
> On Fri, Apr 03, 2015 at 03:15:14PM -0700, Kyle J. McKay wrote:
>
>> When the input is UTF-8 and Perl is operating on bytes instead of
>> characters, a diff that changes one multibyte character to another
>> that shares an initial byte sequence will result in a broken diff
>> display as the common byte sequence prefix will be separated from
>> the rest of the bytes in the multibyte character.
>>
>> For example, if a single line contains only the unicode character
>> U+C9C4 (encoded as UTF-8 0xEC, 0xA7, 0x84) and that line is then
>> changed to the unicode character U+C9C0 (encoded as UTF-8 0xEC,
>> 0xA7, 0x80), when operating on bytes diff-highlight will show only
>> the single byte change from 0x84 to 0x80 thus creating invalid UTF-8
>> and a broken diff display.
>>
>> Fix this by putting Perl into character mode when splitting the line
>> and then back into byte mode after the split is finished.
>>
>> The utf8::xxx functions require Perl 5.8 so we require that as well.
>>
>> Also, since we are mucking with code in the split_line function, we
>> change a '*' quantifier to a '+' quantifier when matching the $COLOR
>> expression which has the side effect of speeding everything up while
>> eliminating useless '' elements in the returned array.
>>
>> Reported-by: Yi EungJun 
>> Signed-off-by: Kyle J. McKay 
>
> This version looks good to me. I looked over the diff of running "git
> log -p --color" on git.git through diff-highlight before and after this
> patch, and everything looks like an improvement.
>
>   Acked-by: Jeff King 
>
> Thanks both of you for working on this.
>
> -Peff
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] diff-highlight: Fix broken multibyte string

2015-04-02 Thread Yi, EungJun
> I timed this one versus the existing diff-highlight. It's about 7%
> slower. That's not great, but is acceptable to me. The String::Multibyte
> version was a lot faster, which was nice (but I'm still unclear on
> _why_).

I think the reason is here:

> sub split_line {
>local $_ = shift;
>return map { /$COLOR/ ? $_ : ($mbcs ? $mbcs->strsplit('', $_) : split //) }
>   split /($COLOR)/;
> }

I removed "*" from "split /($COLOR*)/". Actually I don't know why "*"
was required but I need to remove it to make my patch works correctly.


On Fri, Apr 3, 2015 at 10:24 AM, Jeff King  wrote:
> On Thu, Apr 02, 2015 at 05:49:24PM -0700, Kyle J. McKay wrote:
>
>> Subject: [PATCH v2] diff-highlight: do not split multibyte characters
>>
>> When the input is UTF-8 and Perl is operating on bytes instead
>> of characters, a diff that changes one multibyte character to
>> another that shares an initial byte sequence will result in a
>> broken diff display as the common byte sequence prefix will be
>> separated from the rest of the bytes in the multibyte character.
>
> Thanks, I had a feeling we should be able to do something with perl's
> builtin utf8 support.  This doesn't help people with other encodings,
> but I'm not sure the original was all that helpful either (in that we
> don't actually _know_ the file encodings in the first place).
>
> I briefly confirmed that this seems to do the right thing on po/bg.po,
> which has a couple of sheared characters when viewed with the existing
> code.
>
> I timed this one versus the existing diff-highlight. It's about 7%
> slower. That's not great, but is acceptable to me. The String::Multibyte
> version was a lot faster, which was nice (but I'm still unclear on
> _why_).
>
>> Fix this by putting Perl into character mode when splitting the
>> line and then back into byte mode after the split is finished.
>
> I also wondered if we could simply put stdin into utf8 mode. But it
> looks like it will barf whenever it gets invalid utf8. Checking for
> valid utf8 and only doing the multi-byte split in that case (as you do
> here) is a lot more robust.
>
>> While the utf8::xxx functions are built-in and do not require
>> any 'use' statement, the utf8::is_utf8 function did not appear
>> until Perl 5.8.1, but is identical to the Encode::is_utf8
>> function which is available in 5.8 so we use that instead of
>> utf8::is_utf8.
>
> Makes sense. I'm happy enough listing perl 5.8 as a dependency.
>
> EungJun, does this version meet your needs?
>
> -Peff
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] diff-highlight: Fix broken multibyte string

2015-03-30 Thread Yi EungJun
From: Yi EungJun 

Highlighted string might be broken if the common subsequence is a proper subset
of a multibyte character. For example, if the old string is "진" and the new
string is "지", then we expect the diff is rendered as follows:

-진
+지

but actually it was rendered as follows:

-<84>
+<80>

This fixes the bug by splitting the string by multibyte characters.
---
 contrib/diff-highlight/diff-highlight | 25 +++--
 1 file changed, 23 insertions(+), 2 deletions(-)

diff --git a/contrib/diff-highlight/diff-highlight 
b/contrib/diff-highlight/diff-highlight
index 08c88bb..2662c1a 100755
--- a/contrib/diff-highlight/diff-highlight
+++ b/contrib/diff-highlight/diff-highlight
@@ -2,6 +2,9 @@
 
 use warnings FATAL => 'all';
 use strict;
+use File::Basename;
+use File::Spec::Functions qw( catdir );
+use String::Multibyte;
 
 # Highlight by reversing foreground and background. You could do
 # other things like bold or underline if you prefer.
@@ -24,6 +27,8 @@ my @removed;
 my @added;
 my $in_hunk;
 
+my $mbcs = get_mbcs();
+
 # Some scripts may not realize that SIGPIPE is being ignored when launching the
 # pager--for instance scripts written in Python.
 $SIG{PIPE} = 'DEFAULT';
@@ -164,8 +169,8 @@ sub highlight_pair {
 
 sub split_line {
local $_ = shift;
-   return map { /$COLOR/ ? $_ : (split //) }
-  split /($COLOR*)/;
+   return map { /$COLOR/ ? $_ : ($mbcs ? $mbcs->strsplit('', $_) : split 
//) }
+  split /($COLOR)/;
 }
 
 sub highlight_line {
@@ -211,3 +216,19 @@ sub is_pair_interesting {
   $suffix_a !~ /^$BORING*$/ ||
   $suffix_b !~ /^$BORING*$/;
 }
+
+# Returns an instance of String::Multibyte based on the charset defined by
+# i18n.commitencoding or UTF-8, or undef if String::Multibyte doesn't support
+# the charset.
+sub get_mbcs {
+   my $dir = catdir(dirname($INC{'String/Multibyte.pm'}), 'Multibyte');
+   opendir my $dh, $dir or return;
+   my @mbcs_charsets = grep s/[.]pm\z//, readdir $dh;
+   close $dh;
+   my $expected_charset = `git config i18n.commitencoding` || "UTF-8";
+   $expected_charset =~ s/-//g;
+   my @matches = grep {/^$expected_charset$/i} @mbcs_charsets;
+   my $charset = shift @matches;
+
+   return eval 'String::Multibyte->new($charset)';
+}
-- 
2.3.2.209.gd67f9d5.dirty

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


Re: [ANNOUNCE] Git Merge, April 8-9, Paris

2015-02-20 Thread Yi EungJun
I heard Git Contributors Summit is scheduled on April 8th at Git Merge 2015.

Does anyone know the agenda of the summit? I am considering to attend the
summit.



--
View this message in context: 
http://git.661346.n2.nabble.com/ANNOUNCE-Git-Merge-April-8-9-Paris-tp7624561p7625750.html
Sent from the git mailing list archive at Nabble.com.
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v9 0/1] http: Add Accept-Language header if possible

2015-01-30 Thread Yi, EungJun
I'm very glad to hear that. Thanks to all reviewers!

On Thu, Jan 29, 2015 at 3:19 PM, Junio C Hamano  wrote:
> Thanks; queued.  Let's run with this and try to make it graduate
> early next cycle.
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v9 0/1] http: Add Accept-Language header if possible

2015-01-28 Thread Yi EungJun
From: Yi EungJun 

Change since v8

Apply Junio's patch: Use an array of char* instead of strbuf for language_tags.

Yi EungJun (1):
  http: Add Accept-Language header if possible

 http.c | 147 +
 remote-curl.c  |   2 +
 t/t5550-http-fetch-dumb.sh |  42 +
 3 files changed, 191 insertions(+)

-- 
2.3.0.rc1.32.g7a36c04

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


Re: [PATCH] http: Add Accept-Language header if possible

2015-01-28 Thread Yi, EungJun
I agree that a list of char* is enough for language_tags.

Thanks for your review and patch. I'll apply your patch and send v9.

On Wed, Jan 28, 2015 at 3:15 PM, Junio C Hamano  wrote:
> On Tue, Jan 27, 2015 at 3:34 PM, Junio C Hamano  wrote:
>> Yi EungJun  writes:
>>
>>> +
>>> + sprintf(q_format, ";q=0.%%0%dd", decimal_places);
>>> +
>>> + strbuf_addstr(buf, "Accept-Language: ");
>>> +
>>> + for(i = 0; i < num_langs; i++) {
>>> + if (i > 0)
>>> + strbuf_addstr(buf, ", ");
>>> +
>>> + strbuf_addstr(buf, strbuf_detach(&language_tags[i], 
>>> NULL));
>>
>> This is not wrong per-se, but it looks somewhat convoluted to me.
>> ...
>
> Actually, this is wrong, isn't it?
>
> strbuf_detach() removes the language_tags[i].buf from the strbuf,
> and the caller now owns that piece of memory. Then strbuf_addstr()
> appends a copy of that string to buf, and the piece of memory
> that was originally held by language_tags[i].buf is now lost forever.
>
> This is leaking.
>
>>> + /* free language tags */
>>> + for(i = 0; i < num_langs; i++) {
>>> + strbuf_release(&language_tags[i]);
>>> + }
>
> ... because this loop does not free memory for earlier parts of 
> language_tags[].
>
>> I am wondering if using strbuf for each of the language_tags[] is
>> even necessary.  How about doing it this way instead?
>
> And I think my counter-proposal does not leak (as it does not us strbuf for
> language_tags[] anymore).
>
>>
>>  http.c | 22 +-
>>  1 file changed, 9 insertions(+), 13 deletions(-)
>>
>> diff --git a/http.c b/http.c
>> index 6111c6a..db591b3 100644
>> --- a/http.c
>> +++ b/http.c
>> @@ -1027,7 +1027,7 @@ static void write_accept_language(struct strbuf *buf)
>> const int MAX_DECIMAL_PLACES = 3;
>> const int MAX_LANGUAGE_TAGS = 1000;
>> const int MAX_ACCEPT_LANGUAGE_HEADER_SIZE = 4000;
>> -   struct strbuf *language_tags = NULL;
>> +   char **language_tags = NULL;
>> int num_langs = 0;
>> const char *s = get_preferred_languages();
>> int i;
>> @@ -1053,9 +1053,7 @@ static void write_accept_language(struct strbuf *buf)
>> if (tag.len) {
>> num_langs++;
>> REALLOC_ARRAY(language_tags, num_langs);
>> -   strbuf_init(&language_tags[num_langs - 1], 0);
>> -   strbuf_swap(&tag, &language_tags[num_langs - 1]);
>> -
>> +   language_tags[num_langs - 1] = strbuf_detach(&tag, 
>> NULL);
>> if (num_langs >= MAX_LANGUAGE_TAGS - 1) /* -1 for 
>> '*' */
>> break;
>> }
>> @@ -1070,13 +1068,12 @@ static void write_accept_language(struct strbuf *buf)
>>
>> /* add '*' */
>> REALLOC_ARRAY(language_tags, num_langs + 1);
>> -   strbuf_init(&language_tags[num_langs], 0);
>> -   strbuf_addstr(&language_tags[num_langs++], "*");
>> +   language_tags[num_langs++] = "*"; /* it's OK; this won't be 
>> freed */
>>
>> /* compute decimal_places */
>> for (max_q = 1, decimal_places = 0;
>> -   max_q < num_langs && decimal_places <= 
>> MAX_DECIMAL_PLACES;
>> -   decimal_places++, max_q *= 10)
>> +max_q < num_langs && decimal_places <= 
>> MAX_DECIMAL_PLACES;
>> +decimal_places++, max_q *= 10)
>> ;
>>
>> sprintf(q_format, ";q=0.%%0%dd", decimal_places);
>> @@ -1087,7 +1084,7 @@ static void write_accept_language(struct strbuf *buf)
>> if (i > 0)
>> strbuf_addstr(buf, ", ");
>>
>> -   strbuf_addstr(buf, strbuf_detach(&language_tags[i], 
>> NULL));
>> +   strbuf_addstr(buf, language_tags[i]);
>>
>> if (i > 0)
>> strbuf_addf(buf, q_format, max_q - i);
>> @@ -1101,10 +1098,9 @@ static void write_accept_language(struct strbuf *buf)
>> }
>> }
>>
>> -   /* free language tags */
>> -   for(i = 0; i < num_langs; i++) {
>> -   strbuf_release(&language_tags[i]);
>> -   }
>> +   /* free language tags -- last one is a static '*' */
>> +   for(i = 0; i < num_langs - 1; i++)
>> +   free(language_tags[i]);
>> free(language_tags);
>>  }
>>
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v9 1/1] http: Add Accept-Language header if possible

2015-01-28 Thread Yi EungJun
From: Yi EungJun 

Add an Accept-Language header which indicates the user's preferred
languages defined by $LANGUAGE, $LC_ALL, $LC_MESSAGES and $LANG.

Examples:
  LANGUAGE= -> ""
  LANGUAGE=ko:en -> "Accept-Language: ko, en;q=0.9, *;q=0.1"
  LANGUAGE=ko LANG=en_US.UTF-8 -> "Accept-Language: ko, *;q=0.1"
  LANGUAGE= LANG=en_US.UTF-8 -> "Accept-Language: en-US, *;q=0.1"

This gives git servers a chance to display remote error messages in
the user's preferred language.

Limit the number of languages to 1,000 because q-value must not be
smaller than 0.001, and limit the length of Accept-Language header to
4,000 bytes for some HTTP servers which cannot accept such long header.

Signed-off-by: Yi EungJun 
---
 http.c | 147 +
 remote-curl.c  |   2 +
 t/t5550-http-fetch-dumb.sh |  42 +
 3 files changed, 191 insertions(+)

diff --git a/http.c b/http.c
index 040f362..b2ad2a8 100644
--- a/http.c
+++ b/http.c
@@ -68,6 +68,8 @@ static struct curl_slist *no_pragma_header;
 
 static struct active_request_slot *active_queue_head;
 
+static char *cached_accept_language;
+
 size_t fread_buffer(char *ptr, size_t eltsize, size_t nmemb, void *buffer_)
 {
size_t size = eltsize * nmemb;
@@ -515,6 +517,9 @@ void http_cleanup(void)
cert_auth.password = NULL;
}
ssl_cert_password_required = 0;
+
+   free(cached_accept_language);
+   cached_accept_language = NULL;
 }
 
 struct active_request_slot *get_active_slot(void)
@@ -986,6 +991,142 @@ static void extract_content_type(struct strbuf *raw, 
struct strbuf *type,
strbuf_addstr(charset, "ISO-8859-1");
 }
 
+/*
+ * Guess the user's preferred languages from the value in LANGUAGE environment
+ * variable and LC_MESSAGES locale category if NO_GETTEXT is not defined.
+ *
+ * The result can be a colon-separated list like "ko:ja:en".
+ */
+static const char *get_preferred_languages(void)
+{
+   const char *retval;
+
+   retval = getenv("LANGUAGE");
+   if (retval && *retval)
+   return retval;
+
+#ifndef NO_GETTEXT
+   retval = setlocale(LC_MESSAGES, NULL);
+   if (retval && *retval &&
+   strcmp(retval, "C") &&
+   strcmp(retval, "POSIX"))
+   return retval;
+#endif
+
+   return NULL;
+}
+
+static void write_accept_language(struct strbuf *buf)
+{
+   /*
+* MAX_DECIMAL_PLACES must not be larger than 3. If it is larger than
+* that, q-value will be smaller than 0.001, the minimum q-value the
+* HTTP specification allows. See
+* http://tools.ietf.org/html/rfc7231#section-5.3.1 for q-value.
+*/
+   const int MAX_DECIMAL_PLACES = 3;
+   const int MAX_LANGUAGE_TAGS = 1000;
+   const int MAX_ACCEPT_LANGUAGE_HEADER_SIZE = 4000;
+   char **language_tags = NULL;
+   int num_langs = 0;
+   const char *s = get_preferred_languages();
+   int i;
+   struct strbuf tag = STRBUF_INIT;
+
+   /* Don't add Accept-Language header if no language is preferred. */
+   if (!s)
+   return;
+
+   /*
+* Split the colon-separated string of preferred languages into
+* language_tags array.
+*/
+   do {
+   /* collect language tag */
+   for (; *s && (isalnum(*s) || *s == '_'); s++)
+   strbuf_addch(&tag, *s == '_' ? '-' : *s);
+
+   /* skip .codeset, @modifier and any other unnecessary parts */
+   while (*s && *s != ':')
+   s++;
+
+   if (tag.len) {
+   num_langs++;
+   REALLOC_ARRAY(language_tags, num_langs);
+   language_tags[num_langs - 1] = strbuf_detach(&tag, 
NULL);
+   if (num_langs >= MAX_LANGUAGE_TAGS - 1) /* -1 for '*' */
+   break;
+   }
+   } while (*s++);
+
+   /* write Accept-Language header into buf */
+   if (num_langs) {
+   int last_buf_len = 0;
+   int max_q;
+   int decimal_places;
+   char q_format[32];
+
+   /* add '*' */
+   REALLOC_ARRAY(language_tags, num_langs + 1);
+   language_tags[num_langs++] = "*"; /* it's OK; this won't be 
freed */
+
+   /* compute decimal_places */
+   for (max_q = 1, decimal_places = 0;
+max_q < num_langs && decimal_places <= MAX_DECIMAL_PLACES;
+decimal_places++, max_q *= 10)
+   ;
+
+   sprintf(q_format, ";q=0.%%0%dd&qu

[PATCH] http: Add Accept-Language header if possible

2015-01-27 Thread Yi EungJun
From: Yi EungJun 

Add an Accept-Language header which indicates the user's preferred
languages defined by $LANGUAGE, $LC_ALL, $LC_MESSAGES and $LANG.

Examples:
  LANGUAGE= -> ""
  LANGUAGE=ko:en -> "Accept-Language: ko, en;q=0.9, *;q=0.1"
  LANGUAGE=ko LANG=en_US.UTF-8 -> "Accept-Language: ko, *;q=0.1"
  LANGUAGE= LANG=en_US.UTF-8 -> "Accept-Language: en-US, *;q=0.1"

This gives git servers a chance to display remote error messages in
the user's preferred language.

Limit the number of languages to 1,000 because q-value must not be
smaller than 0.001, and limit the length of Accept-Language header to
4,000 bytes for some HTTP servers which cannot accept such long header.

Signed-off-by: Yi EungJun 
---
 http.c | 151 +
 remote-curl.c  |   2 +
 t/t5550-http-fetch-dumb.sh |  42 +
 3 files changed, 195 insertions(+)

diff --git a/http.c b/http.c
index 040f362..6111c6a 100644
--- a/http.c
+++ b/http.c
@@ -68,6 +68,8 @@ static struct curl_slist *no_pragma_header;
 
 static struct active_request_slot *active_queue_head;
 
+static char *cached_accept_language;
+
 size_t fread_buffer(char *ptr, size_t eltsize, size_t nmemb, void *buffer_)
 {
size_t size = eltsize * nmemb;
@@ -515,6 +517,9 @@ void http_cleanup(void)
cert_auth.password = NULL;
}
ssl_cert_password_required = 0;
+
+   free(cached_accept_language);
+   cached_accept_language = NULL;
 }
 
 struct active_request_slot *get_active_slot(void)
@@ -986,6 +991,146 @@ static void extract_content_type(struct strbuf *raw, 
struct strbuf *type,
strbuf_addstr(charset, "ISO-8859-1");
 }
 
+/*
+ * Guess the user's preferred languages from the value in LANGUAGE environment
+ * variable and LC_MESSAGES locale category if NO_GETTEXT is not defined.
+ *
+ * The result can be a colon-separated list like "ko:ja:en".
+ */
+static const char *get_preferred_languages(void)
+{
+   const char *retval;
+
+   retval = getenv("LANGUAGE");
+   if (retval && *retval)
+   return retval;
+
+#ifndef NO_GETTEXT
+   retval = setlocale(LC_MESSAGES, NULL);
+   if (retval && *retval &&
+   strcmp(retval, "C") &&
+   strcmp(retval, "POSIX"))
+   return retval;
+#endif
+
+   return NULL;
+}
+
+static void write_accept_language(struct strbuf *buf)
+{
+   /*
+* MAX_DECIMAL_PLACES must not be larger than 3. If it is larger than
+* that, q-value will be smaller than 0.001, the minimum q-value the
+* HTTP specification allows. See
+* http://tools.ietf.org/html/rfc7231#section-5.3.1 for q-value.
+*/
+   const int MAX_DECIMAL_PLACES = 3;
+   const int MAX_LANGUAGE_TAGS = 1000;
+   const int MAX_ACCEPT_LANGUAGE_HEADER_SIZE = 4000;
+   struct strbuf *language_tags = NULL;
+   int num_langs = 0;
+   const char *s = get_preferred_languages();
+   int i;
+   struct strbuf tag = STRBUF_INIT;
+
+   /* Don't add Accept-Language header if no language is preferred. */
+   if (!s)
+   return;
+
+   /*
+* Split the colon-separated string of preferred languages into
+* language_tags array.
+*/
+   do {
+   /* collect language tag */
+   for (; *s && (isalnum(*s) || *s == '_'); s++)
+   strbuf_addch(&tag, *s == '_' ? '-' : *s);
+
+   /* skip .codeset, @modifier and any other unnecessary parts */
+   while (*s && *s != ':')
+   s++;
+
+   if (tag.len) {
+   num_langs++;
+   REALLOC_ARRAY(language_tags, num_langs);
+   strbuf_init(&language_tags[num_langs - 1], 0);
+   strbuf_swap(&tag, &language_tags[num_langs - 1]);
+
+   if (num_langs >= MAX_LANGUAGE_TAGS - 1) /* -1 for '*' */
+   break;
+   }
+   } while (*s++);
+
+   /* write Accept-Language header into buf */
+   if (num_langs >= 1) {
+   int last_buf_len = 0;
+   int max_q;
+   int decimal_places;
+   char q_format[32];
+
+   /* add '*' */
+   REALLOC_ARRAY(language_tags, num_langs + 1);
+   strbuf_init(&language_tags[num_langs], 0);
+   strbuf_addstr(&language_tags[num_langs++], "*");
+
+   /* compute decimal_places */
+   for (max_q = 1, decimal_places = 0;
+   max_q < num_langs && decimal_places <= 
MAX_DECIMAL_PLACES;
+   

[PATCH v8 0/1] http: Add Accept-Language header if possible

2015-01-27 Thread Yi EungJun
From: Yi EungJun 

Change since v7

>From Torsten Bögershausen's review:

* remove unnecessary if-statement

>From Eric Sunshine's review:

* fix memory leaks and uninitialized variables
* remove unnecessary if-statement

>From Junio C Hamano's review:

* fix uninitialized variables

Yi EungJun (1):
  http: Add Accept-Language header if possible

 http.c | 151 +
 remote-curl.c  |   2 +
 t/t5550-http-fetch-dumb.sh |  42 +
 3 files changed, 195 insertions(+)

-- 
2.3.0.rc1.32.ga3df1c7

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


[PATCH v7 1/1] http: Add Accept-Language header if possible

2015-01-18 Thread Yi EungJun
From: Yi EungJun 

Add an Accept-Language header which indicates the user's preferred
languages defined by $LANGUAGE, $LC_ALL, $LC_MESSAGES and $LANG.

Examples:
  LANGUAGE= -> ""
  LANGUAGE=ko:en -> "Accept-Language: ko, en;q=0.9, *;q=0.1"
  LANGUAGE=ko LANG=en_US.UTF-8 -> "Accept-Language: ko, *;q=0.1"
  LANGUAGE= LANG=en_US.UTF-8 -> "Accept-Language: en-US, *;q=0.1"

This gives git servers a chance to display remote error messages in
the user's preferred language.

Limit the number of languages to 1,000 because q-value must not be
smaller than 0.001, and limit the length of Accept-Language header to
4,000 bytes for some HTTP servers which cannot accept such long header.

Signed-off-by: Yi EungJun 
---
 http.c | 152 +
 remote-curl.c  |   2 +
 t/t5550-http-fetch-dumb.sh |  42 +
 3 files changed, 196 insertions(+)

diff --git a/http.c b/http.c
index 040f362..349b033 100644
--- a/http.c
+++ b/http.c
@@ -68,6 +68,8 @@ static struct curl_slist *no_pragma_header;
 
 static struct active_request_slot *active_queue_head;
 
+static char *cached_accept_language;
+
 size_t fread_buffer(char *ptr, size_t eltsize, size_t nmemb, void *buffer_)
 {
size_t size = eltsize * nmemb;
@@ -515,6 +517,11 @@ void http_cleanup(void)
cert_auth.password = NULL;
}
ssl_cert_password_required = 0;
+
+   if (cached_accept_language) {
+   free(cached_accept_language);
+   cached_accept_language = NULL;
+   }
 }
 
 struct active_request_slot *get_active_slot(void)
@@ -986,6 +993,145 @@ static void extract_content_type(struct strbuf *raw, 
struct strbuf *type,
strbuf_addstr(charset, "ISO-8859-1");
 }
 
+/*
+ * Guess the user's preferred languages from the value in LANGUAGE environment
+ * variable and LC_MESSAGES locale category if NO_GETTEXT is not defined.
+ *
+ * The result can be a colon-separated list like "ko:ja:en".
+ */
+static const char *get_preferred_languages(void)
+{
+   const char *retval;
+
+   retval = getenv("LANGUAGE");
+   if (retval && *retval)
+   return retval;
+
+#ifndef NO_GETTEXT
+   retval = setlocale(LC_MESSAGES, NULL);
+   if (retval && *retval &&
+   strcmp(retval, "C") &&
+   strcmp(retval, "POSIX"))
+   return retval;
+#endif
+
+   return NULL;
+}
+
+static void write_accept_language(struct strbuf *buf)
+{
+   /*
+* MAX_DECIMAL_PLACES must not be larger than 3. If it is larger than
+* that, q-value will be smaller than 0.001, the minimum q-value the
+* HTTP specification allows. See
+* http://tools.ietf.org/html/rfc7231#section-5.3.1 for q-value.
+*/
+   const int MAX_DECIMAL_PLACES = 3;
+   const int MAX_LANGUAGE_TAGS = 1000;
+   const int MAX_ACCEPT_LANGUAGE_HEADER_SIZE = 4000;
+   struct strbuf *language_tags = NULL;
+   int num_langs;
+   const char *s = get_preferred_languages();
+
+   /* Don't add Accept-Language header if no language is preferred. */
+   if (!s)
+   return;
+
+   /*
+* Split the colon-separated string of preferred languages into
+* language_tags array.
+*/
+   do {
+   /* increase language_tags array to add new language tag */
+   REALLOC_ARRAY(language_tags, num_langs + 1);
+   strbuf_init(&language_tags[num_langs], 0);
+
+   /* collect language tag */
+   for (; *s && (isalnum(*s) || *s == '_'); s++)
+   strbuf_addch(&language_tags[num_langs], *s == '_' ? '-' 
: *s);
+
+   /* skip .codeset, @modifier and any other unnecessary parts */
+   while (*s && *s != ':')
+   s++;
+
+   if (language_tags[num_langs].len > 0) {
+   num_langs++;
+   if (num_langs >= MAX_LANGUAGE_TAGS - 1) /* -1 for '*' */
+   break;
+   }
+   } while (*s++);
+
+   /* write Accept-Language header into buf */
+   if (num_langs >= 1) {
+   int i;
+   int last_buf_len;
+   int max_q;
+   int decimal_places;
+   char q_format[32];
+
+   /* add '*' */
+   REALLOC_ARRAY(language_tags, num_langs + 1);
+   strbuf_init(&language_tags[num_langs], 0);
+   strbuf_addstr(&language_tags[num_langs++], "*");
+
+   /* compute decimal_places */
+   for (max_q = 1, decimal_places = 0;
+   max_q < num_langs && decimal_p

[PATCH v7 0/1] http: Add Accept-Language header if possible

2015-01-18 Thread Yi EungJun
From: Yi EungJun 

Changes since v6

>From Junio C Hamano's review:

* Fix check_language() in t5550-http-fetch-dumb.sh as his suggestion.

>From Eric Sunshine's review:

* Rewrite the parser without state.

Yi EungJun (1):
  http: Add Accept-Language header if possible

 http.c | 152 +
 remote-curl.c  |   2 +
 t/t5550-http-fetch-dumb.sh |  42 +
 3 files changed, 196 insertions(+)

-- 
2.2.0.44.g37b3e56.dirty

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


[ANN] SVNGit - Checkout Git repository by SVN Client

2015-01-08 Thread Yi, EungJun
Hello, all.

I just have started to develop SVNGit, the servlet library in pure
Java for SVN Client to checkout Git repository. The project is hosted
at https://github.com/naver/svngit.

Since the project is at very early stage, SVNGit unstably supports
only a few SVN commands: checkout, update and log.

SVNGit is based on SVNKit to accept HTTP(DAV) requests from SVN client
and uses JGit to access Git repository.

If you have interest in my project, please download it and test with
your Git repositories. I will be very happy if you give me a comment,
a bug report and/or a pullrequest.

Thank you for reading.
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v6 1/1] http: Add Accept-Language header if possible

2014-12-22 Thread Yi EungJun
From: Yi EungJun 

Add an Accept-Language header which indicates the user's preferred
languages defined by $LANGUAGE, $LC_ALL, $LC_MESSAGES and $LANG.

Examples:
  LANGUAGE= -> ""
  LANGUAGE=ko:en -> "Accept-Language: ko, en;q=0.9, *;q=0.1"
  LANGUAGE=ko LANG=en_US.UTF-8 -> "Accept-Language: ko, *;q=0.1"
  LANGUAGE= LANG=en_US.UTF-8 -> "Accept-Language: en-US, *;q=0.1"

This gives git servers a chance to display remote error messages in
the user's preferred language.

Limit the number of languages to 1,000 because q-value must not be
smaller than 0.001, and limit the length of Accept-Language header to
4,000 bytes for some HTTP servers which cannot accept such long header.

Signed-off-by: Yi EungJun 
---
 http.c | 173 +
 remote-curl.c  |   2 +
 t/t5550-http-fetch-dumb.sh |  32 +
 3 files changed, 207 insertions(+)

diff --git a/http.c b/http.c
index 040f362..7a77708 100644
--- a/http.c
+++ b/http.c
@@ -68,6 +68,8 @@ static struct curl_slist *no_pragma_header;
 
 static struct active_request_slot *active_queue_head;
 
+static char *cached_accept_language;
+
 size_t fread_buffer(char *ptr, size_t eltsize, size_t nmemb, void *buffer_)
 {
size_t size = eltsize * nmemb;
@@ -515,6 +517,11 @@ void http_cleanup(void)
cert_auth.password = NULL;
}
ssl_cert_password_required = 0;
+
+   if (cached_accept_language) {
+   free(cached_accept_language);
+   cached_accept_language = NULL;
+   }
 }
 
 struct active_request_slot *get_active_slot(void)
@@ -986,6 +993,166 @@ static void extract_content_type(struct strbuf *raw, 
struct strbuf *type,
strbuf_addstr(charset, "ISO-8859-1");
 }
 
+/*
+ * Guess the user's preferred languages from the value in LANGUAGE environment
+ * variable and LC_MESSAGES locale category if NO_GETTEXT is not defined.
+ *
+ * The result can be a colon-separated list like "ko:ja:en".
+ */
+static const char *get_preferred_languages(void)
+{
+   const char *retval;
+
+   retval = getenv("LANGUAGE");
+   if (retval && *retval)
+   return retval;
+
+#ifndef NO_GETTEXT
+   retval = setlocale(LC_MESSAGES, NULL);
+   if (retval && *retval &&
+   strcmp(retval, "C") &&
+   strcmp(retval, "POSIX"))
+   return retval;
+#endif
+
+   return NULL;
+}
+
+static void write_accept_language(struct strbuf *buf)
+{
+   const char *lang_begin, *pos;
+   int q, max_q;
+   int num_langs;
+   int decimal_places;
+   const int CODESET_OR_MODIFIER = 1;
+   const int LANGUAGE_TAG = 2;
+   const int SEPARATOR = 3;
+   int is_q_factor_required = 0;
+   int parse_state = 0;
+   char q_format[32];
+   /*
+* MAX_LANGS must not be larger than 1,000. If it is larger than that,
+* q-value will be smaller than 0.001, the minimum q-value the HTTP
+* specification allows [1].
+*
+* [1]: http://tools.ietf.org/html/rfc7231#section-5.3.1
+*/
+   const int MAX_LANGS = 1000;
+   const int MAX_SIZE_OF_HEADER = 4000;
+   const int MAX_SIZE_OF_ASTERISK_ELEMENT = 11; /* for ", *;q=0.001" */
+   int last_size = 0;
+
+   lang_begin = get_preferred_languages();
+
+   /* Don't add Accept-Language header if no language is preferred. */
+   if (!lang_begin)
+   return;
+
+   /* Count number of preferred lang_begin to decide precision of 
q-factor. */
+   for (num_langs = 1, pos = lang_begin; *pos; pos++)
+   if (*pos == ':')
+   num_langs++;
+
+   /* Decide the precision for q-factor on number of preferred lang_begin. 
*/
+   num_langs += 1; /* for '*' */
+
+   if (MAX_LANGS < num_langs)
+   num_langs = MAX_LANGS;
+
+   for (max_q = 1, decimal_places = 0;
+   max_q < num_langs;
+   decimal_places++, max_q *= 10)
+   ;
+
+   sprintf(q_format, ";q=0.%%0%dd", decimal_places);
+
+   q = max_q;
+
+   strbuf_addstr(buf, "Accept-Language: ");
+
+   /*
+* Convert a list of colon-separated locale values [1][2] to a list of
+* comma-separated language tags [3] which can be used as a value of
+* Accept-Language header.
+*
+* [1]: http://pubs.opengroup.org/onlinepubs/007908799/xbd/envvar.html
+* [2]: 
http://www.gnu.org/software/libc/manual/html_node/Using-gettextized-software.html
+* [3]: http://tools.ietf.org/html/rfc7231#section-5.3.5
+*/
+   for (pos = lang_begin; ; pos++) {
+   if (!*pos || *pos == ':') {
+   if (is_q_factor_required) {
+

[PATCH v6 0/1] http: Add Accept-Language header if possible

2014-12-22 Thread Yi EungJun
Changes since v5

>From Junio C Hamano's review:

* The tests use `ls-remote` instead of `clone` for tests; I copied the test
  code from ba8e63dc30a80656fddc616f714fb217ad220c04.

* Set cached_accept_langauge to NULL after free it.

>From Eric Sunshine's review:

* get_accept_language() returns a pointer to const char instead of strbuf; the
  type of cached_accept_language also has been changed to char* from strbuf*

* write_accept_language(), which is extracted from get_accept_language(),
  respects MAX_SIZE_OF_HEADER.

* The for-loop in write_accept_language() works correctly if lang_begin points
  an empty string.

>From Jeff King's advice:

* get_preferred_languages() considers LC_MESSAGES only if NO_GETTEXT is not
  defined.

* Remove the tests for LC_MESSAGES, LANG and LC_ALL.

Yi EungJun (1):
  http: Add Accept-Language header if possible

 http.c | 173 +
 remote-curl.c  |   2 +
 t/t5550-http-fetch-dumb.sh |  32 +
 3 files changed, 207 insertions(+)

-- 
2.2.0.375.gcd18ce6.dirty

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


Re: Accept-language test fails on Mac OS

2014-12-06 Thread Yi, EungJun
Thank you for providing useful information to fix the failures.

On Sun, Dec 7, 2014 at 6:04 AM, Torsten Bögershausen  wrote:
> On 2014-12-06 20.44, Yi, EungJun wrote:
>> Could you tell me your locale information from executing 'locale'
>> command and the verbose message you can get by accessing any git
>> repository via HTTP protocol? (e.g. GIT_CURL_VERBOSE=1 git clone
>> http://github.com/foo/bar )
> locale -a
> C
> C.UTF-8
> en_US.utf8
> icelandic
> is_IS
> is_IS.iso88591
> is_IS.utf8
> POSIX

I'm sorry for bothering you, but could you tell me the result of
"locale" command without "-a" option? What I want to know is locale
environment variables and its values, so I want to reproduce the test
failures on my laptop.

>
> -
> After patching like this:
> diff --git a/t/t5550-http-fetch-dumb.sh b/t/t5550-http-fetch-dumb.sh
> index fc6e7fc..1e42b42 100755
> --- a/t/t5550-http-fetch-dumb.sh
> +++ b/t/t5550-http-fetch-dumb.sh
> @@ -205,8 +205,8 @@ check_language () {
> LANG=$5 \
> git ls-remote "$HTTPD_URL/dumb/repo.git" 2>&1 |
> tr -d '\015' |
> -   sort -u >stderr &&
> -   grep -i ^Accept-Language: stderr >actual &&
> +   sort -u >stderr
> +   grep -i ^Accept-Language: stderr >actual
> test_cmp expect actual
>  }
> ---
> I get this:
>
>
> expecting success:
> check_language "ko-KR, *;q=0.1" ko_KR.UTF-8 de_DE.UTF-8 ja_JP.UTF-8 
> en_US.UTF-8 &&
> check_language "de-DE, *;q=0.1" ""  de_DE.UTF-8 ja_JP.UTF-8 
> en_US.UTF-8 &&
> check_language "ja-JP, *;q=0.1" ""  ""  ja_JP.UTF-8 
> en_US.UTF-8 &&
> check_language "en-US, *;q=0.1" ""  ""  ""  
> en_US.UTF-8
>
> --- expect  2014-12-06 21:00:59.0 +
> +++ actual  2014-12-06 21:00:59.0 +
> @@ -1 +0,0 @@
> -Accept-Language: de-DE, *;q=0.1
> not ok 25 - git client sends Accept-Language based on LANGUAGE, LC_ALL, 
> LC_MESSAGES and LANG
> #
> #   check_language "ko-KR, *;q=0.1" ko_KR.UTF-8 de_DE.UTF-8 
> ja_JP.UTF-8 en_US.UTF-8 &&
> #   check_language "de-DE, *;q=0.1" ""  de_DE.UTF-8 
> ja_JP.UTF-8 en_US.UTF-8 &&
> #   check_language "ja-JP, *;q=0.1" ""  ""  
> ja_JP.UTF-8 en_US.UTF-8 &&
> #   check_language "en-US, *;q=0.1" ""  ""  ""
>   en_US.UTF-8
> #
>
>

The test seems to fail if LANGUAGE="". I will dig it. Thanks.
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: Accept-language test fails on Mac OS

2014-12-06 Thread Yi, EungJun
Could you tell me your locale information from executing 'locale'
command and the verbose message you can get by accessing any git
repository via HTTP protocol? (e.g. GIT_CURL_VERBOSE=1 git clone
http://github.com/foo/bar )

I think the failures are related with your locale information.

On Sat, Dec 6, 2014 at 6:50 PM, Torsten Bögershausen  wrote:
> On 2014-12-06 00.01, Michael Blume wrote:
>> On Fri, Dec 5, 2014 at 2:51 PM, Junio C Hamano  wrote:
>>> Michael Blume  writes:
>>>
 Test #25 'git client sends Accept-Language based on LANGUAGE, LC_ALL,
 LC_MESSAGES and LANG' in t5550 fails consistently on my mac, and has
 since the test was introduced. Test 26 and 27 ('git client sends
 Accept-Language with many preferred languages' and 'git client does
 not send Accept-Language') seem fine.

 I'm building git with NO_GETTEXT=1, which may be an issue? But in that
 case the test should probably be gated on gettext?
>>>
>>> I recall queuing a SQUASH??? on top of the posted patch; does these
>>> tests pass with it reverted?
>>
>> The test fails both on pu and on 7567fad which is prior to the
>> SQUASH??? commit, so the squash does not seem to change anything.
> pu@c83418638e0c326f:
> t5550 fails here under Debian Linux,
> I haven't digged further
>
> not ok 25 - git client sends Accept-Language based on LANGUAGE, LC_ALL, 
> LC_MESSAGES and LANG
> #
> #   check_language "ko-KR, *;q=0.1" ko_KR.UTF-8 de_DE.UTF-8 
> ja_JP.UTF-8 en_US.UTF-8 &&
> #   check_language "de-DE, *;q=0.1" ""  de_DE.UTF-8 
> ja_JP.UTF-8 en_US.UTF-8 &&
> #   check_language "ja-JP, *;q=0.1" ""  ""  
> ja_JP.UTF-8 en_US.UTF-8 &&
> #   check_language "en-US, *;q=0.1" ""  ""  ""
>   en_US.UTF-8
> #
>
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v5 1/1] http: Add Accept-Language header if possible

2014-12-02 Thread Yi EungJun
From: Yi EungJun 

Add an Accept-Language header which indicates the user's preferred
languages defined by $LANGUAGE, $LC_ALL, $LC_MESSAGES and $LANG.

Examples:
  LANGUAGE= -> ""
  LANGUAGE=ko:en -> "Accept-Language: ko, en;q=0.9, *;q=0.1"
  LANGUAGE=ko LANG=en_US.UTF-8 -> "Accept-Language: ko, *;q=0.1"
  LANGUAGE= LANG=en_US.UTF-8 -> "Accept-Language: en-US, *;q=0.1"

This gives git servers a chance to display remote error messages in
the user's preferred language.

Limit the number of languages to 1,000 because q-value must not be
smaller than 0.001, and limit the length of Accept-Language header to
4,000 bytes for some HTTP servers which cannot accept such long header.

Signed-off-by: Yi EungJun 
---
 http.c | 154 +
 remote-curl.c  |   2 +
 t/t5550-http-fetch-dumb.sh |  31 +
 3 files changed, 187 insertions(+)

diff --git a/http.c b/http.c
index 040f362..69624af 100644
--- a/http.c
+++ b/http.c
@@ -68,6 +68,8 @@ static struct curl_slist *no_pragma_header;
 
 static struct active_request_slot *active_queue_head;
 
+static struct strbuf *cached_accept_language;
+
 size_t fread_buffer(char *ptr, size_t eltsize, size_t nmemb, void *buffer_)
 {
size_t size = eltsize * nmemb;
@@ -515,6 +517,9 @@ void http_cleanup(void)
cert_auth.password = NULL;
}
ssl_cert_password_required = 0;
+
+   if (cached_accept_language)
+   strbuf_release(cached_accept_language);
 }
 
 struct active_request_slot *get_active_slot(void)
@@ -986,6 +991,149 @@ static void extract_content_type(struct strbuf *raw, 
struct strbuf *type,
strbuf_addstr(charset, "ISO-8859-1");
 }
 
+/*
+ * Guess the user's preferred languages from the value in LANGUAGE environment
+ * variable and LC_MESSAGES locale category.
+ *
+ * The result can be a colon-separated list like "ko:ja:en".
+ */
+static const char *get_preferred_languages(void)
+{
+   const char *retval;
+
+   retval = getenv("LANGUAGE");
+   if (retval && *retval)
+   return retval;
+
+   retval = setlocale(LC_MESSAGES, NULL);
+   if (retval && *retval &&
+   strcmp(retval, "C") &&
+   strcmp(retval, "POSIX"))
+   return retval;
+
+   return NULL;
+}
+
+/*
+ * Get an Accept-Language header which indicates user's preferred languages.
+ *
+ * Examples:
+ *   LANGUAGE= -> ""
+ *   LANGUAGE=ko:en -> "Accept-Language: ko, en; q=0.9, *; q=0.1"
+ *   LANGUAGE=ko_KR.UTF-8:sr@latin -> "Accept-Language: ko-KR, sr; q=0.9, *; 
q=0.1"
+ *   LANGUAGE=ko LANG=en_US.UTF-8 -> "Accept-Language: ko, *; q=0.1"
+ *   LANGUAGE= LANG=en_US.UTF-8 -> "Accept-Language: en-US, *; q=0.1"
+ *   LANGUAGE= LANG=C -> ""
+ */
+static struct strbuf *get_accept_language(void)
+{
+   const char *lang_begin, *pos;
+   int q, max_q;
+   int num_langs;
+   int decimal_places;
+   int is_codeset_or_modifier = 0;
+   char q_format[32];
+   /*
+* MAX_LANGS must not be larger than 1,000. If it is larger than that,
+* q-value will be smaller than 0.001, the minimum q-value the HTTP
+* specification allows [1].
+*
+* [1]: http://tools.ietf.org/html/rfc7231#section-5.3.1
+*/
+   const int MAX_LANGS = 1000;
+   const int MAX_SIZE_OF_HEADER = 4000;
+   int last_size = 0;
+
+   if (cached_accept_language)
+   return cached_accept_language;
+
+   cached_accept_language = xmalloc(sizeof(struct strbuf));
+   strbuf_init(cached_accept_language, 0);
+   lang_begin = get_preferred_languages();
+
+   /* Don't add Accept-Language header if no language is preferred. */
+   if (!lang_begin)
+   return cached_accept_language;
+
+   /* Count number of preferred lang_begin to decide precision of 
q-factor. */
+   for (num_langs = 1, pos = lang_begin; *pos; pos++)
+   if (*pos == ':')
+   num_langs++;
+
+   /* Decide the precision for q-factor on number of preferred lang_begin. 
*/
+   num_langs += 1; /* for '*' */
+
+   if (MAX_LANGS < num_langs)
+   num_langs = MAX_LANGS;
+
+   for (max_q = 1, decimal_places = 0;
+   max_q < num_langs;
+   decimal_places++, max_q *= 10);
+
+   sprintf(q_format, ";q=0.%%0%dd", decimal_places);
+
+   q = max_q;
+
+   strbuf_addstr(cached_accept_language, "Accept-Language: ");
+
+   /*
+* Convert a list of colon-separated locale values [1][2] to a list of
+* comma-separated language tags [3] which can be used as a value of
+* Accept-Language header.

[PATCH v5 0/1] http: Add Accept-Language header if possible

2014-12-02 Thread Yi EungJun
Changes since v4

* Fix styles as Junio C Hamano suggested.
* Limit number of languages and length of Accept-Language header.

Yi EungJun (1):
  http: Add Accept-Language header if possible

 http.c | 154 +
 remote-curl.c  |   2 +
 t/t5550-http-fetch-dumb.sh |  31 +
 3 files changed, 187 insertions(+)

-- 
2.2.0

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


Re: [PATCH v4 1/1] http: Add Accept-Language header if possible

2014-08-03 Thread Yi, EungJun
Thanks very much for your detailed review and sorry for late reply.

2014-07-22 4:01 GMT+09:00 Junio C Hamano :
> Yi EungJun  writes:
>
>> From: Yi EungJun 
>>
>> Add an Accept-Language header which indicates the user's preferred
>> languages defined by $LANGUAGE, $LC_ALL, $LC_MESSAGES and $LANG.
>>
>> Examples:
>>   LANGUAGE= -> ""
>>   LANGUAGE=ko:en -> "Accept-Language: ko, en; q=0.9, *; q=0.1"
>>   LANGUAGE=ko LANG=en_US.UTF-8 -> "Accept-Language: ko, *; q=0.1"
>>   LANGUAGE= LANG=en_US.UTF-8 -> "Accept-Language: en-US, *; q=0.1"
>>
>> This gives git servers a chance to display remote error messages in
>> the user's preferred language.
>>
>> Signed-off-by: Yi EungJun 
>> ---
>>  http.c | 134 
>> +
>>  remote-curl.c  |   2 +
>>  t/t5550-http-fetch-dumb.sh |  31 +++
>>  3 files changed, 167 insertions(+)
>>
>> diff --git a/http.c b/http.c
>> index 3a28b21..ed4e8e1 100644
>> --- a/http.c
>> +++ b/http.c
>> @@ -67,6 +67,8 @@ static struct curl_slist *no_pragma_header;
>>
>>  static struct active_request_slot *active_queue_head;
>>
>> +static struct strbuf *cached_accept_language = NULL;
>
> Please drop " = NULL" that is unnecessary for BSS.

Thanks, I'll fix it.

>
>> @@ -512,6 +514,9 @@ void http_cleanup(void)
>>   cert_auth.password = NULL;
>>   }
>>   ssl_cert_password_required = 0;
>> +
>> + if (cached_accept_language)
>> + strbuf_release(cached_accept_language);
>>  }
>
>
>
>> @@ -983,6 +988,129 @@ static void extract_content_type(struct strbuf *raw, 
>> struct strbuf *type,
>>   strbuf_addstr(charset, "ISO-8859-1");
>>  }
>>
>> +/*
>> + * Guess the user's preferred languages from the value in LANGUAGE 
>> environment
>> + * variable and LC_MESSAGES locale category.
>> + *
>> + * The result can be a colon-separated list like "ko:ja:en".
>> + */
>> +static const char *get_preferred_languages(void)
>> +{
>> + const char *retval;
>> +
>> + retval = getenv("LANGUAGE");
>> + if (retval && *retval)
>> + return retval;
>> +
>> + retval = setlocale(LC_MESSAGES, NULL);
>> + if (retval && *retval &&
>> + strcmp(retval, "C") &&
>> + strcmp(retval, "POSIX"))
>> + return retval;
>> +
>> + return NULL;
>> +}
>> +
>> +/*
>> + * Get an Accept-Language header which indicates user's preferred languages.
>> + *
>> + * Examples:
>> + *   LANGUAGE= -> ""
>> + *   LANGUAGE=ko:en -> "Accept-Language: ko, en; q=0.9, *; q=0.1"
>> + *   LANGUAGE=ko_KR.UTF-8:sr@latin -> "Accept-Language: ko-KR, sr; q=0.9, 
>> *; q=0.1"
>> + *   LANGUAGE=ko LANG=en_US.UTF-8 -> "Accept-Language: ko, *; q=0.1"
>> + *   LANGUAGE= LANG=en_US.UTF-8 -> "Accept-Language: en-US, *; q=0.1"
>> + *   LANGUAGE= LANG=C -> ""
>> + */
>> +static struct strbuf *get_accept_language(void)
>> +{
>> + const char *lang_begin, *pos;
>> + int q, max_q;
>> + int num_langs;
>> + int decimal_places;
>> + int is_codeset_or_modifier = 0;
>> + static struct strbuf buf = STRBUF_INIT;
>> + struct strbuf q_format_buf = STRBUF_INIT;
>> + char *q_format;
>> +
>> + if (cached_accept_language)
>> + return cached_accept_language;
>> +
>> + lang_begin = get_preferred_languages();
>> +
>> + /* Don't add Accept-Language header if no language is preferred. */
>> + if (!(lang_begin && *lang_begin)) {
>
> It is not wrong per-se, but given how hard get_preferred_languages()
> tries not to return a pointer to an empty string, this seems a bit
> overly defensive to me.

Thanks, I'll fix it.

>
>> + cached_accept_language = &buf;
>> + return cached_accept_language;
>
> It is somewhat unconventional to have a static pointer outside to
> point at a singleton and then have a singleton actually as a static
> structure.  I would have done without "buf" in this function and
> instead started this function like so:
>
> if (cached_accept_language)
> return cached

[PATCH v4 1/1] http: Add Accept-Language header if possible

2014-07-19 Thread Yi EungJun
From: Yi EungJun 

Add an Accept-Language header which indicates the user's preferred
languages defined by $LANGUAGE, $LC_ALL, $LC_MESSAGES and $LANG.

Examples:
  LANGUAGE= -> ""
  LANGUAGE=ko:en -> "Accept-Language: ko, en; q=0.9, *; q=0.1"
  LANGUAGE=ko LANG=en_US.UTF-8 -> "Accept-Language: ko, *; q=0.1"
  LANGUAGE= LANG=en_US.UTF-8 -> "Accept-Language: en-US, *; q=0.1"

This gives git servers a chance to display remote error messages in
the user's preferred language.

Signed-off-by: Yi EungJun 
---
 http.c | 134 +
 remote-curl.c  |   2 +
 t/t5550-http-fetch-dumb.sh |  31 +++
 3 files changed, 167 insertions(+)

diff --git a/http.c b/http.c
index 3a28b21..ed4e8e1 100644
--- a/http.c
+++ b/http.c
@@ -67,6 +67,8 @@ static struct curl_slist *no_pragma_header;
 
 static struct active_request_slot *active_queue_head;
 
+static struct strbuf *cached_accept_language = NULL;
+
 size_t fread_buffer(char *ptr, size_t eltsize, size_t nmemb, void *buffer_)
 {
size_t size = eltsize * nmemb;
@@ -512,6 +514,9 @@ void http_cleanup(void)
cert_auth.password = NULL;
}
ssl_cert_password_required = 0;
+
+   if (cached_accept_language)
+   strbuf_release(cached_accept_language);
 }
 
 struct active_request_slot *get_active_slot(void)
@@ -983,6 +988,129 @@ static void extract_content_type(struct strbuf *raw, 
struct strbuf *type,
strbuf_addstr(charset, "ISO-8859-1");
 }
 
+/*
+ * Guess the user's preferred languages from the value in LANGUAGE environment
+ * variable and LC_MESSAGES locale category.
+ *
+ * The result can be a colon-separated list like "ko:ja:en".
+ */
+static const char *get_preferred_languages(void)
+{
+   const char *retval;
+
+   retval = getenv("LANGUAGE");
+   if (retval && *retval)
+   return retval;
+
+   retval = setlocale(LC_MESSAGES, NULL);
+   if (retval && *retval &&
+   strcmp(retval, "C") &&
+   strcmp(retval, "POSIX"))
+   return retval;
+
+   return NULL;
+}
+
+/*
+ * Get an Accept-Language header which indicates user's preferred languages.
+ *
+ * Examples:
+ *   LANGUAGE= -> ""
+ *   LANGUAGE=ko:en -> "Accept-Language: ko, en; q=0.9, *; q=0.1"
+ *   LANGUAGE=ko_KR.UTF-8:sr@latin -> "Accept-Language: ko-KR, sr; q=0.9, *; 
q=0.1"
+ *   LANGUAGE=ko LANG=en_US.UTF-8 -> "Accept-Language: ko, *; q=0.1"
+ *   LANGUAGE= LANG=en_US.UTF-8 -> "Accept-Language: en-US, *; q=0.1"
+ *   LANGUAGE= LANG=C -> ""
+ */
+static struct strbuf *get_accept_language(void)
+{
+   const char *lang_begin, *pos;
+   int q, max_q;
+   int num_langs;
+   int decimal_places;
+   int is_codeset_or_modifier = 0;
+   static struct strbuf buf = STRBUF_INIT;
+   struct strbuf q_format_buf = STRBUF_INIT;
+   char *q_format;
+
+   if (cached_accept_language)
+   return cached_accept_language;
+
+   lang_begin = get_preferred_languages();
+
+   /* Don't add Accept-Language header if no language is preferred. */
+   if (!(lang_begin && *lang_begin)) {
+   cached_accept_language = &buf;
+   return cached_accept_language;
+   }
+
+   /* Count number of preferred lang_begin to decide precision of q-factor 
*/
+   for (num_langs = 1, pos = lang_begin; *pos; pos++)
+   if (*pos == ':')
+   num_langs++;
+
+   /* Decide the precision for q-factor on number of preferred lang_begin. 
*/
+   num_langs += 1; /* for '*' */
+   decimal_places = 1 + (num_langs > 10) + (num_langs > 100);
+   strbuf_addf(&q_format_buf, "; q=0.%%0%dd", decimal_places);
+   q_format = strbuf_detach(&q_format_buf, NULL);
+   for (max_q = 1; decimal_places-- > 0;) max_q *= 10;
+   q = max_q;
+
+   strbuf_addstr(&buf, "Accept-Language: ");
+
+   /*
+* Convert a list of colon-separated locale values [1][2] to a list of
+* comma-separated language tags [3] which can be used as a value of
+* Accept-Language header.
+*
+* [1]: http://pubs.opengroup.org/onlinepubs/007908799/xbd/envvar.html
+* [2]: 
http://www.gnu.org/software/libc/manual/html_node/Using-gettextized-software.html
+* [3]: http://tools.ietf.org/html/rfc7231#section-5.3.5
+*/
+   for (pos = lang_begin; ; pos++) {
+   if (*pos == ':' || !*pos) {
+   /* Ignore if this character is the first one. */
+   if (pos == lang_begin)
+   continue;
+
+ 

[PATCH v4 0/1] http: Add Accept-Language header if possible

2014-07-19 Thread Yi EungJun
Changes since v3:

* Fix styles and syntax. (Thanks to Jeff King and Eric Sunshine)
* Cache Accept-Language header. (Thanks to Jeff King)
* Remove floating point numbers. (Thanks to Junio C Hamano)
* Make the for-loop to get the value of the header simpler.
* Add more comments.

Yi EungJun (1):
  http: Add Accept-Language header if possible

 http.c | 134 +
 remote-curl.c  |   2 +
 t/t5550-http-fetch-dumb.sh |  31 +++
 3 files changed, 167 insertions(+)

-- 
2.0.1.473.g731ddce.dirty

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


Re: [PATCH v3] http: Add Accept-Language header if possible

2014-07-13 Thread Yi, EungJun
2014-07-14 1:57 GMT+09:00 Junio C Hamano :
>
> If you do not want floating point (and I think we tend to avoid it
> when we do not need it), you can realize that in your use of "0.1"
> and "0.01" and "0.001" there is nothing fundamentally floating-point;
> you can measure how many digits below the two-byte string zero-dot
> you would want upfront (by counting num_langs), and show an integer
> counter zero-padded to the left to that width.
>
> That would avoid having to even worry about a possible funny case
> where subtracting 0.01 ten times from 0.1 may not yield zero (or the
> result of subtracting nine times may not reach 0.01) due to rounding
> errors accumulating, which was the first thing that came to my mind
> when I saw your loop.

You're right; We don't need floating point numbers. I'll try to fix it.
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v3] http: Add Accept-Language header if possible

2014-07-13 Thread Yi, EungJun
2014-07-13 13:26 GMT+09:00 Eric Sunshine :
>> +   /* Decide the precision for q-factor on number of preferred 
>> languages. */
>> +   if (num_langs + 1 > 100) { /* +1 is for '*' */
>> +   q_precision = 0.001;
>> +   q_format = "; q=%.3f";
>> +   } else if (num_langs + 1 > 10) { /* +1 is for '*' */
>> +   q_precision = 0.01;
>> +   q_format = "; q=%.2f";
>> +   }
>
> It might make sense to have a final 'else' here which sets these
> variables for the 0.1 case so that the reader of the code doesn't have
> to refer back to the top of the function to figure out what is going
> on.
>
> } else {
> q_precision = 0.1;
> q_format = "; q=%.1f";
> }
>
> Better yet, would it be possible to compute these values rather than
> having to set them manually via a cascading if-chain?

I think it is possible like this:

num_langs += 1; /* for '*' */
decimal_places = 1 + (num_langs > 10) + (num_langs > 100);
snprintf(q_format, sizeof(q_format), "; q=%%.%df", decimal_places);
for (q_precision = 1.0; decimal_places-- > 0;) q_precision /= 10;

Does this one look better than before? I'm not sure which one is better.

ps. The last line can be simpler by using pow() but I'm not sure it is
okay to include math.h.
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v3] http: Add Accept-Language header if possible

2014-07-12 Thread Yi, EungJun
Thanks for your detailed review and nice suggestions. I will accept
most of them.

2014-07-12 2:35 GMT+09:00 Jeff King :
>> + /* Decide the precision for q-factor on number of preferred languages. 
>> */
>> + if (num_langs + 1 > 100) { /* +1 is for '*' */
>> + q_precision = 0.001;
>> + q_format = "; q=%.3f";
>> + } else if (num_langs + 1 > 10) { /* +1 is for '*' */
>> + q_precision = 0.01;
>> + q_format = "; q=%.2f";
>> + }
>
> I don't mind this auto-precision too much, but I'm not sure it buys us
> anything. We are still setting a hard-limit at 100, and it just means we
> write "0.1" instead of "0.001" sometimes.

It means we use "0.1" if possible.

>From my observation, many major web browsers doesn't or didn't send
q-factor of 2 or 3 decimal places. Google chrome doesn't currently and
Mozilla firefox also didn't before 2012 [1]. I think it means some old
and naive web servers may not support q-factor of 2 or 3 decimal
places because major web browsers don't send it. So I think we should
use "0.1" if possible for interoperability with the buggy servers.

But, quite frankly, it is just a possibility and I have no evidence
which proves that such kind of buggy servers really exist. Please let
me know if anybody know about it.

[1]: http://hg.mozilla.org/integration/mozilla-inbound/rev/b0b07ef904ea
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3] http: Add Accept-Language header if possible

2014-07-11 Thread Yi EungJun
Add an Accept-Language header which indicates the user's preferred
languages defined by $LANGUAGE, $LC_ALL, $LC_MESSAGES and $LANG.

Examples:
  LANGUAGE= -> ""
  LANGUAGE=ko:en -> "Accept-Language: ko, en; q=0.9, *; q=0.1"
  LANGUAGE=ko LANG=en_US.UTF-8 -> "Accept-Language: ko, *; q=0.1"
  LANGUAGE= LANG=en_US.UTF-8 -> "Accept-Language: en-US, *; q=0.1"

This gives git servers a chance to display remote error messages in
the user's preferred language.

Signed-off-by: Yi EungJun 
---
 http.c | 125 +
 remote-curl.c  |   2 +
 t/t5550-http-fetch-dumb.sh |  21 
 3 files changed, 148 insertions(+)

diff --git a/http.c b/http.c
index 3a28b21..a20f3e2 100644
--- a/http.c
+++ b/http.c
@@ -983,6 +983,129 @@ static void extract_content_type(struct strbuf *raw, 
struct strbuf *type,
strbuf_addstr(charset, "ISO-8859-1");
 }
 
+/*
+ * Guess the user's preferred languages from the value in LANGUAGE environment
+ * variable and LC_MESSAGES locale category.
+ *
+ * The result can be a colon-separated list like "ko:ja:en".
+ */
+static const char* get_preferred_languages() {
+const char* retval;
+
+   retval = getenv("LANGUAGE");
+   if (retval != NULL && retval[0] != '\0')
+   return retval;
+
+   retval = setlocale(LC_MESSAGES, NULL);
+   if (retval != NULL && retval[0] != '\0'
+   && strcmp(retval, "C") != 0
+   && strcmp(retval, "POSIX") != 0)
+   return retval;
+
+   return NULL;
+}
+
+/*
+ * Add an Accept-Language header which indicates user's preferred languages.
+ *
+ * Examples:
+ *   LANGUAGE= -> ""
+ *   LANGUAGE=ko:en -> "Accept-Language: ko, en; q=0.9, *; q=0.1"
+ *   LANGUAGE=ko_KR.UTF-8:sr@latin -> "Accept-Language: ko-KR, sr; q=0.9, *; 
q=0.1"
+ *   LANGUAGE=ko LANG=en_US.UTF-8 -> "Accept-Language: ko, *; q=0.1"
+ *   LANGUAGE= LANG=en_US.UTF-8 -> "Accept-Language: en-US, *; q=0.1"
+ *   LANGUAGE= LANG=C -> ""
+ */
+static struct curl_slist* add_accept_language(struct curl_slist *headers)
+{
+   const char *p1, *p2, *p3;
+   struct strbuf buf = STRBUF_INIT;
+   float q = 1.0;
+   float q_precision = 0.1;
+   int num_langs = 1;
+   char* q_format = "; q=%.1f";
+
+   p1 = get_preferred_languages();
+
+   /* Don't add Accept-Language header if no language is preferred. */
+   if (p1 == NULL || p1[0] == '\0') {
+   strbuf_release(&buf);
+   return headers;
+   }
+
+   /* Count number of preferred languages to decide precision of q-factor 
*/
+   for (p3 = p1; *p3 != '\0'; p3++) {
+   if (*p3 == ':') {
+   num_langs++;
+   }
+   }
+
+   /* Decide the precision for q-factor on number of preferred languages. 
*/
+   if (num_langs + 1 > 100) { /* +1 is for '*' */
+   q_precision = 0.001;
+   q_format = "; q=%.3f";
+   } else if (num_langs + 1 > 10) { /* +1 is for '*' */
+   q_precision = 0.01;
+   q_format = "; q=%.2f";
+   }
+
+   strbuf_addstr(&buf, "Accept-Language: ");
+
+   for (p2 = p1; q > q_precision; p2++) {
+   if ((*p2 == ':' || *p2 == '\0') && p1 != p2) {
+   if (q < 1.0) {
+   strbuf_addstr(&buf, ", ");
+   }
+
+   for (p3 = p1; p3 < p2; p3++) {
+   /* Replace '_' with '-'. */
+   if (*p3 == '_') {
+   strbuf_add(&buf, p1, p3 - p1);
+   strbuf_addstr(&buf, "-");
+   p1 = p3 + 1;
+   }
+
+   /* Chop off anything after '.' or '@'. */
+   if ((*p3 == '.' || *p3 == '@')) {
+   break;
+   }
+   }
+
+   if (p3 > p1) {
+   strbuf_add(&buf, p1, p3 - p1);
+   }
+
+   /* Put the q factor if only it is less than 1.0. */
+   if (q < 1.0) {
+   strbuf_addf(&buf, q_format, q);
+   }
+
+   q -= q_precision;
+   p1 = p2 + 1;
+
+   

Re: [PATCH] http: Add Accept-Language header if possible

2014-07-11 Thread Yi, EungJun
2014-07-12 1:24 GMT+09:00 Eric Sunshine :
> On Fri, Jul 11, 2014 at 5:22 AM, Yi, EungJun  wrote:
>> 2014-07-09 6:52 GMT+09:00 Eric Sunshine :
>>>> +   grep "^Accept-Language: ko; q=1.000, en; q=0.999, \*; q=0.001" 
>>>> actual
>>>
>>> Do you want to \-escape the periods? (Or maybe use 'grep -F'?)
>>
>> I just want to match '*' character. I tried 'grep -F' but it does not help.
>
> I meant that the periods in your grep pattern are matching any
> character. If you want to be very strict, so that they match only
> period, then you should \-escape them.

Oops, I misunderstood you. You are right. I'll \- escape them.
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2] http: Add Accept-Language header if possible

2014-07-11 Thread Yi EungJun
From: Yi EungJun 

Add an Accept-Language header which indicates the user's preferred
languages defined by $LANGUAGE, $LC_ALL, $LC_MESSAGES and $LANG.

Examples:
  LANGUAGE= -> ""
  LANGUAGE=ko:en -> "Accept-Language: ko, en; q=0.9, *; q=0.1"
  LANGUAGE=ko LANG=en_US.UTF-8 -> "Accept-Language: ko, *; q=0.1"
  LANGUAGE= LANG=en_US.UTF-8 -> "Accept-Language: en-US, *; q=0.1"

This gives git servers a chance to display remote error messages in
the user's preferred language.

Signed-off-by: Yi EungJun 
---
 http.c | 125 +
 remote-curl.c  |   2 +
 t/t5550-http-fetch-dumb.sh |  21 
 3 files changed, 148 insertions(+)

diff --git a/http.c b/http.c
index 3a28b21..a20f3e2 100644
--- a/http.c
+++ b/http.c
@@ -983,6 +983,129 @@ static void extract_content_type(struct strbuf *raw, 
struct strbuf *type,
strbuf_addstr(charset, "ISO-8859-1");
 }
 
+/*
+ * Guess the user's preferred languages from the value in LANGUAGE environment
+ * variable and LC_MESSAGES locale category.
+ *
+ * The result can be a colon-separated list like "ko:ja:en".
+ */
+static const char* get_preferred_languages() {
+const char* retval;
+
+   retval = getenv("LANGUAGE");
+   if (retval != NULL && retval[0] != '\0')
+   return retval;
+
+   retval = setlocale(LC_MESSAGES, NULL);
+   if (retval != NULL && retval[0] != '\0'
+   && strcmp(retval, "C") != 0
+   && strcmp(retval, "POSIX") != 0)
+   return retval;
+
+   return NULL;
+}
+
+/*
+ * Add an Accept-Language header which indicates user's preferred languages.
+ *
+ * Examples:
+ *   LANGUAGE= -> ""
+ *   LANGUAGE=ko:en -> "Accept-Language: ko, en; q=0.9, *; q=0.1"
+ *   LANGUAGE=ko_KR.UTF-8:sr@latin -> "Accept-Language: ko-KR, sr; q=0.9, *; 
q=0.1"
+ *   LANGUAGE=ko LANG=en_US.UTF-8 -> "Accept-Language: ko, *; q=0.1"
+ *   LANGUAGE= LANG=en_US.UTF-8 -> "Accept-Language: en-US, *; q=0.1"
+ *   LANGUAGE= LANG=C -> ""
+ */
+static struct curl_slist* add_accept_language(struct curl_slist *headers)
+{
+   const char *p1, *p2, *p3;
+   struct strbuf buf = STRBUF_INIT;
+   float q = 1.0;
+   float q_precision = 0.1;
+   int num_langs = 1;
+   char* q_format = "; q=%.1f";
+
+   p1 = get_preferred_languages();
+
+   /* Don't add Accept-Language header if no language is preferred. */
+   if (p1 == NULL || p1[0] == '\0') {
+   strbuf_release(&buf);
+   return headers;
+   }
+
+   /* Count number of preferred languages to decide precision of q-factor 
*/
+   for (p3 = p1; *p3 != '\0'; p3++) {
+   if (*p3 == ':') {
+   num_langs++;
+   }
+   }
+
+   /* Decide the precision for q-factor on number of preferred languages. 
*/
+   if (num_langs + 1 > 100) { /* +1 is for '*' */
+   q_precision = 0.001;
+   q_format = "; q=%.3f";
+   } else if (num_langs + 1 > 10) { /* +1 is for '*' */
+   q_precision = 0.01;
+   q_format = "; q=%.2f";
+   }
+
+   strbuf_addstr(&buf, "Accept-Language: ");
+
+   for (p2 = p1; q > q_precision; p2++) {
+   if ((*p2 == ':' || *p2 == '\0') && p1 != p2) {
+   if (q < 1.0) {
+   strbuf_addstr(&buf, ", ");
+   }
+
+   for (p3 = p1; p3 < p2; p3++) {
+   /* Replace '_' with '-'. */
+   if (*p3 == '_') {
+   strbuf_add(&buf, p1, p3 - p1);
+   strbuf_addstr(&buf, "-");
+   p1 = p3 + 1;
+   }
+
+   /* Chop off anything after '.' or '@'. */
+   if ((*p3 == '.' || *p3 == '@')) {
+   break;
+   }
+   }
+
+   if (p3 > p1) {
+   strbuf_add(&buf, p1, p3 - p1);
+   }
+
+   /* Put the q factor if only it is less than 1.0. */
+   if (q < 1.0) {
+   strbuf_addf(&buf, q_format, q);
+   }
+
+   q -= q_precision;
+   p1 = p

Re: [PATCH] http: Add Accept-Language header if possible

2014-07-11 Thread Yi, EungJun
2014-07-11 5:10 GMT+09:00 Jeff King :
> On Wed, Jul 09, 2014 at 11:46:14AM +0100, Peter Krefting wrote:
>
>> Jeff King:
>>
>> >I did some digging, and I think the public API is setlocale with a NULL
>> >parameter, like:
>> >
>> > printf("%s\n", setlocale(LC_MESSAGES, NULL));
>> >
>> >That still will end up like "en_US.UTF-8", though;
>>
>> And it only yields the highest-priority language, I think.
>
> I wasn't clear on whether POSIX locale variables actually supported
> multiple languages with priorities. I have never seen that, though the
> original commit message indicated that LANGUAGE=x:y was a thing (I
> wasn't sure if that was a made-up thing, or something that libc actually
> supported).
>
>> Debian's website has a nice writeup on the subject:
>> http://www.debian.org/intro/cn#howtoset
>
> That seems to be about language settings in browsers, which are a much
> richer set of preferences than POSIX locales (I think).
>
> It would not be wrong to have that level of configuration for git's http
> requests, but I do not know if it is worth the effort. Mapping the
> user's gettext locale into an accept-language header seems like a
> straightforward way to communicate to the other side what the client is
> using to show errors (so that errors coming from the server can match).

Thanks for you advice. I'll write a path to use both of
setlocale(LC_MESSAGES, NULL) and getenv("LANGUAGE") to get the user's
preferred language. setlocale(LC_MESSAGES, NULL) is quite nice way
because it takes LC_ALL, LC_MESSAGES and LANG into account, but not
LANGUAGE. I think we should take also LANGUAGE into account as gettext
does. [1]

[1]: 
http://www.gnu.org/software/gettext/manual/gettext.html#Locale-Environment-Variables
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] http: Add Accept-Language header if possible

2014-07-11 Thread Yi, EungJun
2014-07-09 19:40 GMT+09:00 Peter Krefting :
> Yi EungJun:
>
>
>> Example:
>>  LANGUAGE= -> ""
>>  LANGUAGE=ko -> "Accept-Language: ko; q=1.000, *; q=0.001"
>>  LANGUAGE=ko:en -> "Accept-Language: ko; q=1.000, en; q=0.999, *; q=0.001"
>
>
> Avoid adding "q=1.000". It is redundant (the default for any unqualified
> language names is 1.0, and additionally there has historically been some
> buggy servers that failed if it was included.

Ok, I'll fix it.

>
>
>> +   p1 = getenv("LANGUAGE");
>
>
> You need a fallback mechanism here to parse all the possible language
> variables. I would use the first one I find of these:
>
>  1. LANGUAGE
>  2. LC_ALL
>  3. LC_MESSAGES
>  4. LANG
>
> Only "LANGUAGE" holds a colon-separated list, but the same code can parse
> all of them, just yielding a single entry for the others.

I'll use setlocale(LC_MESSAGES, NULL) as well as getenv("LANGUAGE").

>
>
>> +   strbuf_add(buf, p1, p2 - p1);
>
>
> The tokens are on the form language_COUNTRY.encoding@identifier, whereas
> Accept-Language wants language-COUNTRY, so you need to a) replace "_" with
> "-", and b) chop off anything following a "." or "@".
>
>
>> +   strbuf_addf(buf, "; q=%.3f", q);
>> +   q -= 0.001;
>
>
> Three decimals seems a bit overkill, but some experimentation might be
> necessary.

I'll use three decimals only if there are 100 or more preferred languages.

>
>
>> +   strbuf_addstr(buf, "*; q=0.001\r\n");
>
>
> You should probably also add an explicit "en" here, if none was already
> included. I've seen some servers break horribly if "en" isn't included.

I'll send Accept-Language only if there is at least one preferred
language. Is it enough?

Thanks for your review.
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] http: Add Accept-Language header if possible

2014-07-08 Thread Yi, EungJun
2014-07-09 14:10 GMT+09:00 Jeff King :
> On Wed, Jul 09, 2014 at 12:54:06AM +0900, Yi EungJun wrote:
>
>> From: Yi EungJun 
>>
>> Add an Accept-Language header which indicates the user's preferred
>> languages defined by 'LANGUAGE' environment variable if the variable is
>> not empty.
>>
>> Example:
>>   LANGUAGE= -> ""
>>   LANGUAGE=ko -> "Accept-Language: ko; q=1.000, *; q=0.001"
>>   LANGUAGE=ko:en -> "Accept-Language: ko; q=1.000, en; q=0.999, *; q=0.001"
>>
>> This gives git servers a chance to display remote error messages in
>> the user's preferred language.
>
> Should this also take into account other language-related variables? I'd
> think $LC_ALL, $LC_MESSAGES, and $LANG would affect it, too.  Are
> colon-separated values a standard in $LANGUAGE? I have never seen them,
> but I admit I am not very knowledgeable about localization issues.
>
> Also, we do we need to do more parsing? My $LANG is set to en_US.UTF-8.
> The encoding part is presumably uninteresting to the remote server.  I
> also wonder if there are support functions in libc or as part of gettext
> that can help us get these values.
>
> -Peff

I agree with you. In fact, I tried to get user's preferred language in
the same way as gettext. It has guess_category_value() to do that and
the function is good enough because it considers $LANGUAGE, $LC_ALL,
$LANG, and also system-dependent preferences. But the function does
not seem a public API and I don't know how can I use the function in
Git. So I chose to use $LANGUAGE only.
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] http: Add Accept-Language header if possible

2014-07-08 Thread Yi EungJun
From: Yi EungJun 

Add an Accept-Language header which indicates the user's preferred
languages defined by 'LANGUAGE' environment variable if the variable is
not empty.

Example:
  LANGUAGE= -> ""
  LANGUAGE=ko -> "Accept-Language: ko; q=1.000, *; q=0.001"
  LANGUAGE=ko:en -> "Accept-Language: ko; q=1.000, en; q=0.999, *; q=0.001"

This gives git servers a chance to display remote error messages in
the user's preferred language.
---
 http.c | 43 +++
 t/t5550-http-fetch-dumb.sh | 10 ++
 2 files changed, 53 insertions(+)

diff --git a/http.c b/http.c
index 3a28b21..c345616 100644
--- a/http.c
+++ b/http.c
@@ -983,6 +983,47 @@ static void extract_content_type(struct strbuf *raw, 
struct strbuf *type,
strbuf_addstr(charset, "ISO-8859-1");
 }
 
+/*
+ * Add an Accept-Language header which indicates user's preferred languages
+ * defined by 'LANGUAGE' environment variable if the variable is not empty.
+ *
+ * Example:
+ *   LANGUAGE= -> ""
+ *   LANGUAGE=ko -> "Accept-Language: ko; q=1.000, *; q=0.001"
+ *   LANGUAGE=ko:en -> "Accept-Language: ko; q=1.000, en; q=0.999, *; q=0.001"
+ */
+static void add_accept_language(struct strbuf *buf)
+{
+   const char *p1, *p2;
+   float q = 1.000;
+
+   p1 = getenv("LANGUAGE");
+
+   if (p1 != NULL && p1[0] != '\0') {
+   strbuf_reset(buf);
+   strbuf_addstr(buf, "Accept-Language: ");
+   for (p2 = p1; q > 0.001; p2++) {
+   if ((*p2 == ':' || *p2 == '\0') && p1 != p2) {
+   if (q < 1.0) {
+   strbuf_addstr(buf, ", ");
+   }
+   strbuf_add(buf, p1, p2 - p1);
+   strbuf_addf(buf, "; q=%.3f", q);
+   q -= 0.001;
+   p1 = p2 + 1;
+
+   if (*p2 == '\0') {
+   break;
+   }
+   }
+   }
+   if (q < 1.0) {
+   strbuf_addstr(buf, ", ");
+   }
+   strbuf_addstr(buf, "*; q=0.001\r\n");
+   }
+}
+
 /* http_request() targets */
 #define HTTP_REQUEST_STRBUF0
 #define HTTP_REQUEST_FILE  1
@@ -1020,6 +1061,8 @@ static int http_request(const char *url,
 fwrite_buffer);
}
 
+   add_accept_language(&buf);
+
strbuf_addstr(&buf, "Pragma:");
if (options && options->no_cache)
strbuf_addstr(&buf, " no-cache");
diff --git a/t/t5550-http-fetch-dumb.sh b/t/t5550-http-fetch-dumb.sh
index ac71418..ea15158 100755
--- a/t/t5550-http-fetch-dumb.sh
+++ b/t/t5550-http-fetch-dumb.sh
@@ -196,5 +196,15 @@ test_expect_success 'reencoding is robust to whitespace 
oddities' '
grep "this is the error message" stderr
 '
 
+test_expect_success 'git client sends Accept-Language' '
+   GIT_CURL_VERBOSE=1 LANGUAGE=ko:en git clone 
"$HTTPD_URL/accept/language" 2>actual
+   grep "^Accept-Language: ko; q=1.000, en; q=0.999, \*; q=0.001" actual
+'
+
+test_expect_success 'git client does not send Accept-Language' '
+   GIT_CURL_VERBOSE=1 LANGUAGE= git clone "$HTTPD_URL/accept/language" 
2>actual
+   test_must_fail grep "^Accept-Language:" actual
+'
+
 stop_httpd
 test_done
-- 
2.0.1.473.gafdefd9.dirty

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


[PATCH v4] http: fix charset detection of extract_content_type()

2014-06-17 Thread Yi EungJun
From: Yi EungJun 

extract_content_type() could not extract a charset parameter if the
parameter is not the first one and there is a whitespace and a following
semicolon just before the parameter. For example:

text/plain; format=fixed ;charset=utf-8

And it also could not handle correctly some other cases, such as:

text/plain; charset=utf-8; format=fixed
text/plain; some-param="a long value with ;semicolons;"; charset=utf-8

Thanks-to: Jeff King 
Signed-off-by: Yi EungJun 
---
 http.c | 4 ++--
 t/lib-httpd/error.sh   | 4 
 t/t5550-http-fetch-dumb.sh | 5 +
 3 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/http.c b/http.c
index 2b4f6a3..3a28b21 100644
--- a/http.c
+++ b/http.c
@@ -927,7 +927,7 @@ static int extract_param(const char *raw, const char *name,
return -1;
raw++;
 
-   while (*raw && !isspace(*raw))
+   while (*raw && !isspace(*raw) && *raw != ';')
strbuf_addch(out, *raw++);
return 0;
 }
@@ -971,7 +971,7 @@ static void extract_content_type(struct strbuf *raw, struct 
strbuf *type,
 
strbuf_reset(charset);
while (*p) {
-   while (isspace(*p))
+   while (isspace(*p) || *p == ';')
p++;
if (!extract_param(p, "charset", charset))
return;
diff --git a/t/lib-httpd/error.sh b/t/lib-httpd/error.sh
index eafc9d2..a77b8e5 100755
--- a/t/lib-httpd/error.sh
+++ b/t/lib-httpd/error.sh
@@ -19,6 +19,10 @@ case "$PATH_INFO" in
printf "text/plain; charset=utf-16"
charset=utf-16
;;
+*odd-spacing*)
+   printf "text/plain; foo=bar ;charset=utf-16; other=nonsense"
+   charset=utf-16
+   ;;
 esac
 printf "\n"
 
diff --git a/t/t5550-http-fetch-dumb.sh b/t/t5550-http-fetch-dumb.sh
index 01b8aae..ac71418 100755
--- a/t/t5550-http-fetch-dumb.sh
+++ b/t/t5550-http-fetch-dumb.sh
@@ -191,5 +191,10 @@ test_expect_success 'http error messages are reencoded' '
grep "this is the error message" stderr
 '
 
+test_expect_success 'reencoding is robust to whitespace oddities' '
+   test_must_fail git clone "$HTTPD_URL/error/odd-spacing" 2>stderr &&
+   grep "this is the error message" stderr
+'
+
 stop_httpd
 test_done
-- 
2.0.0.422.gb6302de

Oops, I fixed the whitespace error.
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3] http: fix charset detection of extract_content_type()

2014-06-17 Thread Yi, EungJun
From: Yi EungJun 

extract_content_type() could not extract a charset parameter if the
parameter is not the first one and there is a whitespace and a following
semicolon just before the parameter. For example:

text/plain; format=fixed ;charset=utf-8

And it also could not handle correctly some other cases, such as:

text/plain; charset=utf-8; format=fixed
text/plain; some-param="a long value with ;semicolons;"; charset=utf-8

Thanks-to: Jeff King 
Signed-off-by: Yi EungJun 
---
 http.c | 4 ++--
 t/lib-httpd/error.sh   | 4 
 t/t5550-http-fetch-dumb.sh | 5 +
 3 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/http.c b/http.c
index 2b4f6a3..3a28b21 100644
--- a/http.c
+++ b/http.c
@@ -927,7 +927,7 @@ static int extract_param(const char *raw, const char *name,
  return -1;
  raw++;

- while (*raw && !isspace(*raw))
+ while (*raw && !isspace(*raw) && *raw != ';')
  strbuf_addch(out, *raw++);
  return 0;
 }
@@ -971,7 +971,7 @@ static void extract_content_type(struct strbuf
*raw, struct strbuf *type,

  strbuf_reset(charset);
  while (*p) {
- while (isspace(*p))
+ while (isspace(*p) || *p == ';')
  p++;
  if (!extract_param(p, "charset", charset))
  return;
diff --git a/t/lib-httpd/error.sh b/t/lib-httpd/error.sh
index eafc9d2..a77b8e5 100755
--- a/t/lib-httpd/error.sh
+++ b/t/lib-httpd/error.sh
@@ -19,6 +19,10 @@ case "$PATH_INFO" in
  printf "text/plain; charset=utf-16"
  charset=utf-16
  ;;
+*odd-spacing*)
+ printf "text/plain; foo=bar ;charset=utf-16; other=nonsense"
+ charset=utf-16
+ ;;
 esac
 printf "\n"

diff --git a/t/t5550-http-fetch-dumb.sh b/t/t5550-http-fetch-dumb.sh
index 01b8aae..ac71418 100755
--- a/t/t5550-http-fetch-dumb.sh
+++ b/t/t5550-http-fetch-dumb.sh
@@ -191,5 +191,10 @@ test_expect_success 'http error messages are reencoded' '
  grep "this is the error message" stderr
 '

+test_expect_success 'reencoding is robust to whitespace oddities' '
+ test_must_fail git clone "$HTTPD_URL/error/odd-spacing" 2>stderr &&
+ grep "this is the error message" stderr
+'
+
 stop_httpd
 test_done
-- 
2.0.0.422.gb6302de

I have squashed Jeff King's patch. How can I credit him in this commit message?
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2] http-protocol.txt: Basic Auth is RFC 2617, not RFC 2616

2014-06-16 Thread Yi, EungJun
From: Yi EungJun 

Signed-off-by: Yi EungJun 
---
 Documentation/technical/http-protocol.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Documentation/technical/http-protocol.txt
b/Documentation/technical/http-protocol.txt
index 544373b..2d0eb19 100644
--- a/Documentation/technical/http-protocol.txt
+++ b/Documentation/technical/http-protocol.txt
@@ -60,7 +60,7 @@ Because Git repositories are accessed by standard
path components
 server administrators MAY use directory based permissions within
 their HTTP server to control repository access.

-Clients SHOULD support Basic authentication as described by RFC 2616.
+Clients SHOULD support Basic authentication as described by RFC 2617.
 Servers SHOULD support Basic authentication by relying upon the
 HTTP server placed in front of the Git server software.

-- 
2.0.0.422.gb6302de
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] http-protocol.txt: Basic Auth is RFC 2617, not RFC 2616

2014-06-16 Thread Yi, EungJun
Thanks for your advice. i'll resend it.

2014-06-17 3:26 GMT+09:00 Junio C Hamano :
> Yi EungJun  writes:
>
>> Could you change the author to "Yi EungJun "
>> if you apply this patch?
>
> You can send a patch with the desired "From: " line that matches the
> identity on the "Signed-off-by: " line at the beginning of the log
> message, like this:
>
> From: nori 
> Subject: [PATCH] http-protocol.txt: Basic Auth is RFC 2617, not RFC 
> 2616
> To: unlisted-recipients:; (no To-header on input)
> Date: Sun, 15 Jun 2014 04:09:29 +0900
>     Message-ID: <539cafe8.c1a4420a.08dd.f...@mx.google.com>
>
> From: Yi EungJun 
>
> Here you write your log message, after a blank line to
> separate the in-body From: header above with the log
>     message.  And then after a blank line below, you sign-off
> your patch.
>
> Signed-off-by: Yi EungJun 
> ---
>  ... diffstat here ...
>
> diff --git a/... diff here ...
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] http: fix charset detection of extract_content_type()

2014-06-15 Thread Yi EungJun
Could you change the author to "Yi EungJun "
if you apply this patch?
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] http-protocol.txt: Basic Auth is RFC 2617, not RFC 2616

2014-06-15 Thread Yi EungJun
Could you change the author to "Yi EungJun "
if you apply this patch?
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: More detailed error message for 403 forbidden.

2013-03-31 Thread Yi, EungJun
>
> Maybe. But I would worry somewhat about sites which provide a useless
> and verbose text/plain message. Ideally an x-git-error-message would be
> no more than few lines, suitable for the error message of a terminal
> program. I would not want a site-branded "Your page cannot be found.
> Here's a complete navigation bar" page to be spewed to the terminal.
> Those tend to be text/html, though, so we may be safe. It's just that
> we're gambling on what random servers do, and if we show useless spew
> even some of the time, that would be a regression.
>
> -Peff

I completely agree with you.

And should git client need to add x-git-error-message in Accept header
and/or perhaps language preference in Accept-Language header?

Accept: x-git-error-message, */*;q=0.8
Accept-Language: ko,en;q=0.8
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


More detailed error message for 403 forbidden.

2013-03-26 Thread Yi, EungJun
Currently, if user tried to access a git repository via HTTP and it
fails because the user's permission is not enough to access the
repository, git client tells that http request failed and the error
was 403 forbidden.

But It is not enough for user to understand why it fails, especially
if the user don't know the username because git-credential-osxkeychain
authenticate implicitly without user knowing.

It would be much better if git client shows response body which might
include an explanation of the failure. For example,

before:

$ git clone http://localhost/foo/bar
error: The requested URL returned error: 403 while accessing
http://localhost/foo/bar
fatal: HTTP request failed

after:

$ git clone http://localhost/foo/bar
error: The requested URL returned error: 403 while accessing
http://localhost/foo/bar
remote: User 'me' does not have enough permission to access the repository.
fatal: HTTP request failed
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: Remove all files except a few files, using filter-branch

2012-09-18 Thread Yi, EungJun
> I think it should be '... && git reset -q $GIT_COMMIT -- filename'

It works! Thanks to Hannes and Andreas!

On Wed, Sep 19, 2012 at 12:10 AM, Johannes Sixt  wrote:
> Am 9/18/2012 17:01, schrieb Yi, EungJun:
>>> --index-filter "git rm --cached -qr -- . && git reset -q -- filename"
>>
>> Hmm... I tried as you said, but it seems to lose history.
>
> I think it should be '... && git reset -q $GIT_COMMIT -- filename'
>
> -- Hannes
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: Remove all files except a few files, using filter-branch

2012-09-18 Thread Yi, EungJun
> --index-filter "git rm --cached -qr -- . && git reset -q -- filename"

Hmm... I tried as you said, but it seems to lose history.

In the below example, after rewriting there must be two commits for
'b' file but only one exists.

~$ git init filter-branch2
Initialized empty Git repository in
/home/nori/mysrc/test/git/filter-branch2/.git/
~/filter-branch2$ cd filter-branch2
~/filter-branch2$ echo 1 > a
~/filter-branch2$ echo 1 > b
~/filter-branch2$ git add a b
~/filter-branch2$ git commit -m 'first'
[master (root-commit) ae2b5fd] first
 2 files changed, 2 insertions(+)
 create mode 100644 a
 create mode 100644 b
~/filter-branch2$ echo 2 >> b
~/filter-branch2$ git add b
~/filter-branch2$ git commit -m 'second'
[master a32b84e] second
 1 file changed, 1 insertion(+)
~/filter-branch2$ git filter-branch --index-filter "git rm --cached
-qr -- . && git reset -q -- b"
Rewrite a32b84ed7cec5686e43a47195dfa8114f83619f3 (2/2)
Ref 'refs/heads/master' was rewritten
~/filter-branch2$ git log -- b
commit 19611f9eaf412232e237afcc059d0324a862062f
Author: Yi EungJun 
Date:   Tue Sep 18 23:51:53 2012 +0900

first

Am I doing something wrong?

On Mon, Sep 17, 2012 at 2:06 AM, Andreas Schwab  wrote:
> "Yi, EungJun"  writes:
>
>> Hi, all.
>>
>> I want to remove all files except a few files, in the history of my
>> git repository.
>>
>> I tried to do that as follows:
>>
>> git filter-branch --index-filter "git rm --cached --ignore-unmatch
>> $(git ls-files | grep -v '^filename$' | tr '\n' ' ')"
>
> Try instead first removing all files, then restoring the files you want
> to keep.
>
> --index-filter "git rm --cached -qr -- . && git reset -q -- filename"
>
> Andreas.
>
> --
> Andreas Schwab, sch...@linux-m68k.org
> GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
> "And now for something completely different."
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: How do I pronounce "blob"?

2012-09-16 Thread Yi, EungJun
Thanks, now I can pronounce the word confidently with your help.

On Sun, Sep 16, 2012 at 2:17 AM, Martin Langhoff
 wrote:
> On Sat, Sep 15, 2012 at 9:24 AM, Yi, EungJun  wrote:
>> "bee-lob" or "bla:b"?
>
> Like Bob, add an L in there.
>
>
> m
> --
>  martin.langh...@gmail.com
>  mar...@laptop.org -- Software Architect - OLPC
>  - ask interesting questions
>  - don't get distracted with shiny stuff  - working code first
>  - http://wiki.laptop.org/go/User:Martinlanghoff
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Remove all files except a few files, using filter-branch

2012-09-16 Thread Yi, EungJun
Hi, all.

I want to remove all files except a few files, in the history of my
git repository.

I tried to do that as follows:

git filter-branch --index-filter "git rm --cached --ignore-unmatch
$(git ls-files | grep -v '^filename$' | tr '\n' ' ')"

But this does not work well if there is a file whose name is not
encoded in us-ascii or includes parenthesis. git-filter-branch is
great to remove some files in my repository, but not good enough to
remove all except only a few.

Does anyone know the better way?
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: How do I pronounce "blob"?

2012-09-15 Thread Yi, EungJun
Thanks for your help, Jan!

On Sat, Sep 15, 2012 at 10:26 PM, Jan Engelhardt  wrote:
> On Saturday 2012-09-15 15:24, Yi, EungJun wrote:
>
>>"bee-lob" or "bla:b"?
>
> http://en.wiktionary.org/wiki/blob
>
> BLOB as a Binary Large OBject reeks of a retronym.
>
>>I guess "bee-lob" is correct if it means binary large object. But I'm
>>not sure because gitglossary does not tell me about that.
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


How do I pronounce "blob"?

2012-09-15 Thread Yi, EungJun
"bee-lob" or "bla:b"?

I guess "bee-lob" is correct if it means binary large object. But I'm
not sure because gitglossary does not tell me about that.
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html