sort entries numerically

2014-06-07 Thread Toralf Förster
Hi,

is there any chance to have 1.8 before 1.10 in an output like the following 
:

...
From https://code.wireshark.org/review/wireshark
   52fe0aa..b69642d  master - origin/master
   460db8a..540f061  master-1.10 - origin/master-1.10
   25bb29a..5741a40  master-1.12 - origin/master-1.12
   4ee4fc11..97898a2 master-1.8 - origin/master-1.8


-- 
Toralf

--
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 2/4] replace: add test for --graft

2014-06-07 Thread Christian Couder
Signed-off-by: Christian Couder chrisc...@tuxfamily.org
---
 t/t6050-replace.sh | 12 
 1 file changed, 12 insertions(+)

diff --git a/t/t6050-replace.sh b/t/t6050-replace.sh
index 68b3cb2..ca45a84 100755
--- a/t/t6050-replace.sh
+++ b/t/t6050-replace.sh
@@ -351,4 +351,16 @@ test_expect_success 'replace ref cleanup' '
test -z $(git replace)
 '
 
+test_expect_success '--graft with and without already replaced object' '
+   test $(git log --oneline | wc -l) = 7 
+   git replace --graft $HASH5 
+   test $(git log --oneline | wc -l) = 3 
+   git cat-file -p $HASH5 | test_must_fail grep parent 
+   test_must_fail git replace --graft $HASH5 $HASH4 $HASH3 
+   git replace --force -g $HASH5 $HASH4 $HASH3 
+   git cat-file -p $HASH5 | grep parent $HASH4 
+   git cat-file -p $HASH5 | grep parent $HASH3 
+   git replace -d $HASH5
+'
+
 test_done
-- 
2.0.0.rc0.40.gd30ccc4


--
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 0/4] Add --graft option to git replace

2014-06-07 Thread Christian Couder
Here is a small patch series to implement:

git replace [-f] --graft commit [parent...]

This patch series goes on top of the patch series that
implements --edit.

The changes since v3, thanks to Junio, are:

- remove function read_sha1_commit() and its call as well as a
  call to parse_commit_buffer(), as lookup_commit_or_die()
  already reads the commit buffer and parses it (patch 1/4)

- source git-sh-setup and other small cosmetic changes in
  convert-grafts-to-replace-refs.sh (patch 4/4)

Christian Couder (4):
  replace: add --graft option
  replace: add test for --graft
  Documentation: replace: add --graft option
  contrib: add convert-grafts-to-replace-refs.sh

 Documentation/git-replace.txt | 10 +
 builtin/replace.c | 62 ++-
 contrib/convert-grafts-to-replace-refs.sh | 28 ++
 t/t6050-replace.sh| 12 ++
 4 files changed, 111 insertions(+), 1 deletion(-)
 create mode 100755 contrib/convert-grafts-to-replace-refs.sh

-- 
2.0.0.rc0.40.gd30ccc4

--
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 4/4] contrib: add convert-grafts-to-replace-refs.sh

2014-06-07 Thread Christian Couder
This patch adds into contrib/ an example script to convert
grafts from an existing grafts file into replace refs using
the new --graft option of git replace.

While at it let's mention this new script in the
git replace documentation for the --graft option.

Signed-off-by: Christian Couder chrisc...@tuxfamily.org
---
 Documentation/git-replace.txt |  4 +++-
 contrib/convert-grafts-to-replace-refs.sh | 28 
 2 files changed, 31 insertions(+), 1 deletion(-)
 create mode 100755 contrib/convert-grafts-to-replace-refs.sh

diff --git a/Documentation/git-replace.txt b/Documentation/git-replace.txt
index 491875e..e1be2e6 100644
--- a/Documentation/git-replace.txt
+++ b/Documentation/git-replace.txt
@@ -79,7 +79,9 @@ OPTIONS
content as commit except that its parents will be
[parent...] instead of commit's parents. A replacement ref
is then created to replace commit with the newly created
-   commit.
+   commit. See contrib/convert-grafts-to-replace-refs.sh for an
+   example script based on this option that can convert grafts to
+   replace refs.
 
 -l pattern::
 --list pattern::
diff --git a/contrib/convert-grafts-to-replace-refs.sh 
b/contrib/convert-grafts-to-replace-refs.sh
new file mode 100755
index 000..0cbc917
--- /dev/null
+++ b/contrib/convert-grafts-to-replace-refs.sh
@@ -0,0 +1,28 @@
+#!/bin/sh
+
+# You should execute this script in the repository where you
+# want to convert grafts to replace refs.
+
+GRAFTS_FILE=${GIT_DIR:-.git}/info/grafts
+
+. $(git --exec-path)/git-sh-setup
+
+test -f $GRAFTS_FILE || die Could not find graft file: '$GRAFTS_FILE'
+
+grep '^[^# ]' $GRAFTS_FILE |
+while read definition
+do
+   if test -n $definition
+   then
+   echo Converting: $definition
+   git replace --graft $definition ||
+   die Conversion failed for: $definition
+   fi
+done
+
+mv $GRAFTS_FILE $GRAFTS_FILE.bak ||
+   die Could not rename '$GRAFTS_FILE' to '$GRAFTS_FILE.bak'
+
+echo Success!
+echo All the grafts in '$GRAFTS_FILE' have been converted to replace refs!
+echo The grafts file '$GRAFTS_FILE' has been renamed: '$GRAFTS_FILE.bak'
-- 
2.0.0.rc0.40.gd30ccc4

--
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 3/4] Documentation: replace: add --graft option

2014-06-07 Thread Christian Couder
Signed-off-by: Christian Couder chrisc...@tuxfamily.org
---
 Documentation/git-replace.txt | 8 
 1 file changed, 8 insertions(+)

diff --git a/Documentation/git-replace.txt b/Documentation/git-replace.txt
index 61461b9..491875e 100644
--- a/Documentation/git-replace.txt
+++ b/Documentation/git-replace.txt
@@ -10,6 +10,7 @@ SYNOPSIS
 [verse]
 'git replace' [-f] object replacement
 'git replace' [-f] --edit object
+'git replace' [-f] --graft commit [parent...]
 'git replace' -d object...
 'git replace' [--format=format] [-l [pattern]]
 
@@ -73,6 +74,13 @@ OPTIONS
newly created object. See linkgit:git-var[1] for details about
how the editor will be chosen.
 
+--graft commit [parent...]::
+   Create a graft commit. A new commit is created with the same
+   content as commit except that its parents will be
+   [parent...] instead of commit's parents. A replacement ref
+   is then created to replace commit with the newly created
+   commit.
+
 -l pattern::
 --list pattern::
List replace refs for objects that match the given pattern (or
-- 
2.0.0.rc0.40.gd30ccc4


--
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 1/4] replace: add --graft option

2014-06-07 Thread Christian Couder
The usage string for this option is:

git replace [-f] --graft commit [parent...]

First we create a new commit that is the same as commit
except that its parents are [parents...]

Then we create a replace ref that replace commit with
the commit we just created.

With this new option, it should be straightforward to
convert grafts to replace refs.

Signed-off-by: Christian Couder chrisc...@tuxfamily.org
---
 builtin/replace.c | 62 ++-
 1 file changed, 61 insertions(+), 1 deletion(-)

diff --git a/builtin/replace.c b/builtin/replace.c
index 1bb491d..91eda61 100644
--- a/builtin/replace.c
+++ b/builtin/replace.c
@@ -17,6 +17,7 @@
 static const char * const git_replace_usage[] = {
N_(git replace [-f] object replacement),
N_(git replace [-f] --edit object),
+   N_(git replace [-f] --graft commit [parent...]),
N_(git replace -d object...),
N_(git replace [--format=format] [-l [pattern]]),
NULL
@@ -294,6 +295,54 @@ static int edit_and_replace(const char *object_ref, int 
force)
return replace_object_sha1(object_ref, old, replacement, new, force);
 }
 
+static int create_graft(int argc, const char **argv, int force)
+{
+   unsigned char old[20], new[20];
+   const char *old_ref = argv[0];
+   struct commit *commit;
+   struct strbuf buf = STRBUF_INIT;
+   struct strbuf new_parents = STRBUF_INIT;
+   const char *parent_start, *parent_end;
+   int i;
+
+   if (get_sha1(old_ref, old)  0)
+   die(_(Not a valid object name: '%s'), old_ref);
+   commit = lookup_commit_or_die(old, old_ref);
+
+   /* find existing parents */
+   strbuf_addstr(buf, commit-buffer);
+   parent_start = buf.buf;
+   parent_start += 46; /* tree  + hex sha1 + \n */
+   parent_end = parent_start;
+
+   while (starts_with(parent_end, parent ))
+   parent_end += 48; /* parent  + hex sha1 + \n */
+
+   /* prepare new parents */
+   for (i = 1; i  argc; i++) {
+   unsigned char sha1[20];
+   if (get_sha1(argv[i], sha1)  0)
+   die(_(Not a valid object name: '%s'), argv[i]);
+   lookup_commit_or_die(sha1, argv[i]);
+   strbuf_addf(new_parents, parent %s\n, sha1_to_hex(sha1));
+   }
+
+   /* replace existing parents with new ones */
+   strbuf_splice(buf, parent_start - buf.buf, parent_end - parent_start,
+ new_parents.buf, new_parents.len);
+
+   if (write_sha1_file(buf.buf, buf.len, commit_type, new))
+   die(_(could not write replacement commit for: '%s'), old_ref);
+
+   strbuf_release(new_parents);
+   strbuf_release(buf);
+
+   if (!hashcmp(old, new))
+   return error(new commit is the same as the old one: '%s', 
sha1_to_hex(old));
+
+   return replace_object_sha1(old_ref, old, replacement, new, force);
+}
+
 int cmd_replace(int argc, const char **argv, const char *prefix)
 {
int force = 0;
@@ -303,12 +352,14 @@ int cmd_replace(int argc, const char **argv, const char 
*prefix)
MODE_LIST,
MODE_DELETE,
MODE_EDIT,
+   MODE_GRAFT,
MODE_REPLACE
} cmdmode = MODE_UNSPECIFIED;
struct option options[] = {
OPT_CMDMODE('l', list, cmdmode, N_(list replace refs), 
MODE_LIST),
OPT_CMDMODE('d', delete, cmdmode, N_(delete replace refs), 
MODE_DELETE),
OPT_CMDMODE('e', edit, cmdmode, N_(edit existing object), 
MODE_EDIT),
+   OPT_CMDMODE('g', graft, cmdmode, N_(change a commit's 
parents), MODE_GRAFT),
OPT_BOOL('f', force, force, N_(replace the ref if it 
exists)),
OPT_STRING(0, format, format, N_(format), N_(use this 
format)),
OPT_END()
@@ -325,7 +376,10 @@ int cmd_replace(int argc, const char **argv, const char 
*prefix)
usage_msg_opt(--format cannot be used when not listing,
  git_replace_usage, options);
 
-   if (force  cmdmode != MODE_REPLACE  cmdmode != MODE_EDIT)
+   if (force 
+   cmdmode != MODE_REPLACE 
+   cmdmode != MODE_EDIT 
+   cmdmode != MODE_GRAFT)
usage_msg_opt(-f only makes sense when writing a replacement,
  git_replace_usage, options);
 
@@ -348,6 +402,12 @@ int cmd_replace(int argc, const char **argv, const char 
*prefix)
  git_replace_usage, options);
return edit_and_replace(argv[0], force);
 
+   case MODE_GRAFT:
+   if (argc  1)
+   usage_msg_opt(-g needs at least one argument,
+ git_replace_usage, options);
+   return create_graft(argc, argv, force);
+
case MODE_LIST:
if (argc  1)

[PATCH v2 0/2] mingw: macro main(), const warnings

2014-06-07 Thread Stepan Kasal
Hi,

On Fri, Jun 06, 2014 at 11:15:04PM +0200, Karsten Blees wrote:
 Am 06.06.2014 21:13, schrieb Junio C Hamano:
  I am wondering why the solution is not a more obvious drop const
  that is not ANSI C, though.  I only have a ready-access to N1570
  draft but in it I find:
 

 Actually, that was the original solution ($gmane/247535).

  Karsten Blees karsten.bl...@gmail.com writes:
  A simpler solution that works with all definitions of main() is to
  cast to void* (tell the compiler all responsibility is on
  us).

Indeed, verified.  Re-submitting.
Cheers,
Stepan

Karsten Blees (1):
  Win32: move main macro to a function

Stepan Kasal (1):
  mingw: avoid const warning

 compat/mingw.c | 15 +++
 compat/mingw.h | 14 --
 2 files changed, 19 insertions(+), 10 deletions(-)

-- 
2.0.0.9635.g0be03cb

--
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 2/2] mingw: avoid const warning

2014-06-07 Thread Stepan Kasal
Fix const warnings in http-fetch.c and remote-curl.c main() where is
argv declared as const.

The fix should work for all future declarations of main, no matter
whether the second parameter's type is char**, const char**, or
char *[].

Signed-off-by: Stepan Kasal ka...@ucw.cz
---
 compat/mingw.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/compat/mingw.h b/compat/mingw.h
index 15f0c9d..6dc8b1a 100644
--- a/compat/mingw.h
+++ b/compat/mingw.h
@@ -372,7 +372,7 @@ static int mingw_main(c,v); \
 int main(int argc, char **argv) \
 { \
mingw_startup(); \
-   return mingw_main(__argc, __argv); \
+   return mingw_main(__argc, (void *)__argv); \
 } \
 static int mingw_main(c,v)
 
-- 
2.0.0.9635.g0be03cb

--
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 1/2] Win32: move main macro to a function

2014-06-07 Thread Stepan Kasal
From: Karsten Blees bl...@dcon.de
Date: Fri, 7 Jan 2011 19:47:23 +0100

The code in the MinGW main macro is getting more and more complex, move to
a separate initialization function for readabiliy and extensibility.

Signed-off-by: Karsten Blees bl...@dcon.de
Signed-off-by: Erik Faye-Lund kusmab...@gmail.com
Signed-off-by: Stepan Kasal ka...@ucw.cz
---
 compat/mingw.c | 15 +++
 compat/mingw.h | 14 --
 2 files changed, 19 insertions(+), 10 deletions(-)

diff --git a/compat/mingw.c b/compat/mingw.c
index a0e13bc..c03bafa 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -1847,3 +1847,18 @@ int mingw_offset_1st_component(const char *path)
 
return offset + is_dir_sep(path[offset]);
 }
+
+void mingw_startup()
+{
+   /* copy executable name to argv[0] */
+   __argv[0] = xstrdup(_pgmptr);
+
+   /* initialize critical section for waitpid pinfo_t list */
+   InitializeCriticalSection(pinfo_cs);
+
+   /* set up default file mode and file modes for stdin/out/err */
+   _fmode = _O_BINARY;
+   _setmode(_fileno(stdin), _O_BINARY);
+   _setmode(_fileno(stdout), _O_BINARY);
+   _setmode(_fileno(stderr), _O_BINARY);
+}
diff --git a/compat/mingw.h b/compat/mingw.h
index 3eaf822..15f0c9d 100644
--- a/compat/mingw.h
+++ b/compat/mingw.h
@@ -363,22 +363,16 @@ void free_environ(char **env);
 extern CRITICAL_SECTION pinfo_cs;
 
 /*
- * A replacement of main() that ensures that argv[0] has a path
- * and that default fmode and std(in|out|err) are in binary mode
+ * A replacement of main() that adds win32 specific initialization.
  */
 
+void mingw_startup();
 #define main(c,v) dummy_decl_mingw_main(); \
 static int mingw_main(c,v); \
 int main(int argc, char **argv) \
 { \
-   extern CRITICAL_SECTION pinfo_cs; \
-   _fmode = _O_BINARY; \
-   _setmode(_fileno(stdin), _O_BINARY); \
-   _setmode(_fileno(stdout), _O_BINARY); \
-   _setmode(_fileno(stderr), _O_BINARY); \
-   argv[0] = xstrdup(_pgmptr); \
-   InitializeCriticalSection(pinfo_cs); \
-   return mingw_main(argc, argv); \
+   mingw_startup(); \
+   return mingw_main(__argc, __argv); \
 } \
 static int mingw_main(c,v)
 
-- 
2.0.0.9635.g0be03cb

--
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: [msysGit] Re: [PATCH 3/5] Warn if the Windows console font doesn't support Unicode

2014-06-07 Thread Stepan Kasal
Hi,

On Fri, Jun 06, 2014 at 10:18:43PM +0100, Peter Krefting wrote:
 Stepan Kasal:
 +switching to a TrueType font such as Lucida Console!);
[...]
 modernizing the suggestion here to recomment Consolas. It is available 

Indeed.

So, I'll keep this patch as it is, for the records, and apply your
suggestion to the subsequent
[PATCH 5/5] Win32: Thread-safe windows console output

Stepan
--
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 restore changes to the remote master branch to its previous stage ?

2014-06-07 Thread Arup Rakshit
Hi,

I am working in a project, where I am using *Git*. Today, I have been advised  
by my manager to do some change and it was an urgent request. I did the change 
and tested also, All was working fine. The big mistake I did, all the changes I 
made in the *master* branch without creating a topic a branch. So, once I done 
with the changes I did *git push origin master* and the changed got merged to 
*master* branch of the remote repository. I know this is not a good practice, 
all happened accidentally. 

Now my question is in such a case, if I see, something wrong I pushed and 
merged to the remote repo's *master* branch, how to restore it to its previous 
stage using *git* ? 

- 

Regards,
Arup Rakshit

Debugging is twice as hard as writing the code in the first place. Therefore, 
if you write the code as cleverly as possible, you are, by definition, not 
smart enough to debug it.

--Brian Kernighan
--
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: What's cooking in git.git (Jun 2014, #02; Fri, 6)

2014-06-07 Thread David Kastrup
Junio C Hamano gits...@pobox.com writes:

  git blame has been optimized greatly by reorganising the data
  structure that is used to keep track of the work to be done, thanks
  to David Karstrup d...@gnu.org.

I guess that reorganising the data structure for months is not worth
the trouble of getting the name right.

At any rate, as promised I'll post a list of remaining low-hanging fruit
in the next days for somebody else to get praised for, and then I'm out.

-- 
David Kastrup
--
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 restore changes to the remote master branch to its previous stage ?

2014-06-07 Thread Johannes Sixt
Am 07.06.2014 08:07, schrieb Arup Rakshit:
 Hi,
 
 I am working in a project, where I am using *Git*. Today, I have been advised 
  
 by my manager to do some change and it was an urgent request. I did the 
 change 
 and tested also, All was working fine. The big mistake I did, all the changes 
 I 
 made in the *master* branch without creating a topic a branch. So, once I 
 done 
 with the changes I did *git push origin master* and the changed got merged to 
 *master* branch of the remote repository. I know this is not a good practice, 
 all happened accidentally. 
 
 Now my question is in such a case, if I see, something wrong I pushed and 
 merged to the remote repo's *master* branch, how to restore it to its 
 previous 
 stage using *git* ? 

Assuming that the remote master branch is tracked in your local
repository, the following should do it:

  git push origin origin/master@{1}:master

The plus forces a non-fast-forward push. See 'man gitrevisions' about
the foo@{1} syntax before you run the command.

-- 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


[PATCH v2 1/6] Support Unicode console output on Windows

2014-06-07 Thread Stepan Kasal
From: Karsten Blees bl...@dcon.de
Date: Sat, 31 Jul 2010 00:04:01 +

WriteConsoleW seems to be the only way to reliably print unicode to the
console (without weird code page conversions).

Also redirects vfprintf to the winansi.c version.

Signed-off-by: Karsten Blees bl...@dcon.de
Signed-off-by: Johannes Schindelin johannes.schinde...@gmx.de
Signed-off-by: Stepan Kasal ka...@ucw.cz
---
 compat/mingw.h   |  2 ++
 compat/winansi.c | 26 --
 2 files changed, 22 insertions(+), 6 deletions(-)

diff --git a/compat/mingw.h b/compat/mingw.h
index 6dc8b1a..d3cffb7 100644
--- a/compat/mingw.h
+++ b/compat/mingw.h
@@ -320,9 +320,11 @@ int mingw_raise(int sig);
 int winansi_fputs(const char *str, FILE *stream);
 int winansi_printf(const char *format, ...) __attribute__((format (printf, 1, 
2)));
 int winansi_fprintf(FILE *stream, const char *format, ...) 
__attribute__((format (printf, 2, 3)));
+int winansi_vfprintf(FILE *stream, const char *format, va_list list);
 #define fputs winansi_fputs
 #define printf(...) winansi_printf(__VA_ARGS__)
 #define fprintf(...) winansi_fprintf(__VA_ARGS__)
+#define vfprintf winansi_vfprintf
 
 /*
  * git specific compatibility
diff --git a/compat/winansi.c b/compat/winansi.c
index dedce21..abe0fea 100644
--- a/compat/winansi.c
+++ b/compat/winansi.c
@@ -3,6 +3,7 @@
  */
 
 #include ../git-compat-util.h
+#include malloc.h
 
 /*
  Functions to be wrapped:
@@ -10,6 +11,7 @@
 #undef printf
 #undef fprintf
 #undef fputs
+#undef vfprintf
 /* TODO: write */
 
 /*
@@ -46,6 +48,18 @@ static void init(void)
initialized = 1;
 }
 
+static int write_console(const char *str, size_t len)
+{
+   /* convert utf-8 to utf-16, write directly to console */
+   int wlen = MultiByteToWideChar(CP_UTF8, 0, str, len, NULL, 0);
+   wchar_t *wbuf = (wchar_t *) alloca(wlen * sizeof(wchar_t));
+   MultiByteToWideChar(CP_UTF8, 0, str, len, wbuf, wlen);
+
+   WriteConsoleW(console, wbuf, wlen, NULL, NULL);
+
+   /* return original (utf-8 encoded) length */
+   return len;
+}
 
 #define FOREGROUND_ALL (FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE)
 #define BACKGROUND_ALL (BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE)
@@ -245,13 +259,15 @@ static int ansi_emulate(const char *str, FILE *stream)
int rv = 0;
const char *pos = str;
 
+   fflush(stream);
+
while (*pos) {
pos = strstr(str, \033[);
if (pos) {
size_t len = pos - str;
 
if (len) {
-   size_t out_len = fwrite(str, 1, len, stream);
+   size_t out_len = write_console(str, len);
rv += out_len;
if (out_len  len)
return rv;
@@ -260,14 +276,12 @@ static int ansi_emulate(const char *str, FILE *stream)
str = pos + 2;
rv += 2;
 
-   fflush(stream);
-
pos = set_attr(str);
rv += pos - str;
str = pos;
} else {
-   rv += strlen(str);
-   fputs(str, stream);
+   size_t len = strlen(str);
+   rv += write_console(str, len);
return rv;
}
}
@@ -294,7 +308,7 @@ int winansi_fputs(const char *str, FILE *stream)
return EOF;
 }
 
-static int winansi_vfprintf(FILE *stream, const char *format, va_list list)
+int winansi_vfprintf(FILE *stream, const char *format, va_list list)
 {
int len, rv;
char small_buf[256];
-- 
2.0.0.9635.g0be03cb

--
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 4/6] Win32: add Unicode conversion functions

2014-06-07 Thread Stepan Kasal
From: Karsten Blees bl...@dcon.de
Date: Fri, 25 Nov 2011 21:05:06 +0100

Add Unicode conversion functions to convert between Windows native UTF-16LE
encoding to UTF-8 and back.

To support repositories with legacy-encoded file names, the UTF-8 to UTF-16
conversion function tries to create valid, unique file names even for
invalid UTF-8 byte sequences, so that these repositories can be checked out
without error.

The current implementation leaves invalid UTF-8 bytes in range 0xa0 - 0xff
as is (producing printable Unicode chars \u00a0 - \u00ff, equivalent to
ISO-8859-1), and converts 0x80 - 0x9f to hex-code (\u0080 - \u009f are
control chars).

The Windows MultiByteToWideChar API was not used as it either drops invalid
UTF-8 sequences (on Win2k/XP; producing non-unique or even empty file
names) or converts them to the replacement char \ufffd (Vista/7; causing
ERROR_INVALID_NAME in subsequent calls to file system APIs).

Signed-off-by: Karsten Blees bl...@dcon.de
Signed-off-by: Stepan Kasal ka...@ucw.cz
---
 compat/mingw.c |  85 ++
 compat/mingw.h | 104 +
 2 files changed, 189 insertions(+)

diff --git a/compat/mingw.c b/compat/mingw.c
index c03bafa..6f1fb10 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -1848,6 +1848,91 @@ int mingw_offset_1st_component(const char *path)
return offset + is_dir_sep(path[offset]);
 }
 
+int xutftowcsn(wchar_t *wcs, const char *utfs, size_t wcslen, int utflen)
+{
+   int upos = 0, wpos = 0;
+   const unsigned char *utf = (const unsigned char*) utfs;
+   if (!utf || !wcs || wcslen  1) {
+   errno = EINVAL;
+   return -1;
+   }
+   /* reserve space for \0 */
+   wcslen--;
+   if (utflen  0)
+   utflen = INT_MAX;
+
+   while (upos  utflen) {
+   int c = utf[upos++]  0xff;
+   if (utflen == INT_MAX  c == 0)
+   break;
+
+   if (wpos = wcslen) {
+   wcs[wpos] = 0;
+   errno = ERANGE;
+   return -1;
+   }
+
+   if (c  0x80) {
+   /* ASCII */
+   wcs[wpos++] = c;
+   } else if (c = 0xc2  c  0xe0  upos  utflen 
+   (utf[upos]  0xc0) == 0x80) {
+   /* 2-byte utf-8 */
+   c = ((c  0x1f)  6);
+   c |= (utf[upos++]  0x3f);
+   wcs[wpos++] = c;
+   } else if (c = 0xe0  c  0xf0  upos + 1  utflen 
+   !(c == 0xe0  utf[upos]  0xa0)  /* 
over-long encoding */
+   (utf[upos]  0xc0) == 0x80 
+   (utf[upos + 1]  0xc0) == 0x80) {
+   /* 3-byte utf-8 */
+   c = ((c  0x0f)  12);
+   c |= ((utf[upos++]  0x3f)  6);
+   c |= (utf[upos++]  0x3f);
+   wcs[wpos++] = c;
+   } else if (c = 0xf0  c  0xf5  upos + 2  utflen 
+   wpos + 1  wcslen 
+   !(c == 0xf0  utf[upos]  0x90)  /* 
over-long encoding */
+   !(c == 0xf4  utf[upos] = 0x90)  /*  
\u10 */
+   (utf[upos]  0xc0) == 0x80 
+   (utf[upos + 1]  0xc0) == 0x80 
+   (utf[upos + 2]  0xc0) == 0x80) {
+   /* 4-byte utf-8: convert to \ud8xx \udcxx surrogate 
pair */
+   c = ((c  0x07)  18);
+   c |= ((utf[upos++]  0x3f)  12);
+   c |= ((utf[upos++]  0x3f)  6);
+   c |= (utf[upos++]  0x3f);
+   c -= 0x1;
+   wcs[wpos++] = 0xd800 | (c  10);
+   wcs[wpos++] = 0xdc00 | (c  0x3ff);
+   } else if (c = 0xa0) {
+   /* invalid utf-8 byte, printable unicode char: convert 
1:1 */
+   wcs[wpos++] = c;
+   } else {
+   /* invalid utf-8 byte, non-printable unicode: convert 
to hex */
+   static const char *hex = 0123456789abcdef;
+   wcs[wpos++] = hex[c  4];
+   if (wpos  wcslen)
+   wcs[wpos++] = hex[c  0x0f];
+   }
+   }
+   wcs[wpos] = 0;
+   return wpos;
+}
+
+int xwcstoutf(char *utf, const wchar_t *wcs, size_t utflen)
+{
+   if (!wcs || !utf || utflen  1) {
+   errno = EINVAL;
+   return -1;
+   }
+   utflen = WideCharToMultiByte(CP_UTF8, 0, wcs, -1, utf, utflen, NULL, 
NULL);
+   if (utflen)
+   return utflen - 1;
+   errno = ERANGE;
+   return -1;
+}
+
 void mingw_startup()
 {
/* copy executable name 

[PATCH v2 5/6] Win32: Thread-safe windows console output

2014-06-07 Thread Stepan Kasal
From: Karsten Blees bl...@dcon.de
Date: Sat, 14 Jan 2012 22:24:19 +0100

Winansi.c has many static variables that are accessed and modified from
the [v][f]printf / fputs functions overridden in the file. This may cause
multi threaded git commands that print to the console to produce corrupted
output or even crash.

Additionally, winansi.c doesn't override all functions that can be used to
print to the console (e.g. fwrite, write, fputc are missing), so that ANSI
escapes don't work properly for some git commands (e.g. git-grep).

Instead of doing ANSI emulation in just a few wrapped functions on top of
the IO API, let's plug into the IO system and take advantage of the thread
safety inherent to the IO system.

Redirect stdout and stderr to a pipe if they point to the console. A
background thread reads from the pipe, handles ANSI escape sequences and
UTF-8 to UTF-16 conversion, then writes to the console.

The pipe-based stdout and stderr replacements must be set to unbuffered, as
MSVCRT doesn't support line buffering and fully buffered streams are
inappropriate for console output.

Due to the byte-oriented pipe, ANSI escape sequences and multi-byte UTF-8
sequences can no longer be expected to arrive in one piece. Replace the
string-based ansi_emulate() with a simple stateful parser (this also fixes
colored diff hunk headers, which were broken as of commit 2efcc977).

Override isatty to return true for the pipes redirecting to the console.

Exec/spawn obtain the original console handle to pass to the next process
via winansi_get_osfhandle().

All other overrides are gone, the default stdio implementations work as
expected with the piped stdout/stderr descriptors.

Global variables are either initialized on startup (single threaded) or
exclusively modified by the background thread. Threads communicate through
the pipe, no further synchronization is necessary.

The background thread is terminated by disonnecting the pipe after flushing
the stdio and pipe buffers. This doesn't work for anonymous pipes (created
via CreatePipe), as DisconnectNamedPipe only works on the read end, which
discards remaining data. Thus we have to setup the pipe manually, with the
write end beeing the server (opened with CreateNamedPipe) and the read end
the client (opened with CreateFile).

Limitations: doesn't track reopened or duped file descriptors, i.e.:
- fdopen(1/2) returns fully buffered streams
- dup(1/2), dup2(1/2) returns normal pipe descriptors (i.e. isatty() =
  false, winansi_get_osfhandle won't return the original console handle)

Currently, only the git-format-patch command uses xfdopen(xdup(1)) (see
realstdout in builtin/log.c), but works well with these limitations.

Many thanks to Atsushi Nakagawa at...@chejz.com for suggesting and
reviewing the thread-exit-mechanism.

Signed-off-by: Karsten Blees bl...@dcon.de
Signed-off-by: Stepan Kasal ka...@ucw.cz
---
 compat/mingw.c   |   9 +-
 compat/mingw.h   |  12 +-
 compat/winansi.c | 401 ---
 3 files changed, 273 insertions(+), 149 deletions(-)

diff --git a/compat/mingw.c b/compat/mingw.c
index 6f1fb10..d242557 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -865,9 +865,9 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char 
**argv, char **env,
memset(si, 0, sizeof(si));
si.cb = sizeof(si);
si.dwFlags = STARTF_USESTDHANDLES;
-   si.hStdInput = (HANDLE) _get_osfhandle(fhin);
-   si.hStdOutput = (HANDLE) _get_osfhandle(fhout);
-   si.hStdError = (HANDLE) _get_osfhandle(fherr);
+   si.hStdInput = winansi_get_osfhandle(fhin);
+   si.hStdOutput = winansi_get_osfhandle(fhout);
+   si.hStdError = winansi_get_osfhandle(fherr);
 
/* concatenate argv, quoting args as we go */
strbuf_init(args, 0);
@@ -1946,4 +1946,7 @@ void mingw_startup()
_setmode(_fileno(stdin), _O_BINARY);
_setmode(_fileno(stdout), _O_BINARY);
_setmode(_fileno(stderr), _O_BINARY);
+
+   /* initialize Unicode console */
+   winansi_init();
 }
diff --git a/compat/mingw.h b/compat/mingw.h
index 921ba08..4b638d8 100644
--- a/compat/mingw.h
+++ b/compat/mingw.h
@@ -317,14 +317,10 @@ int mingw_raise(int sig);
  * ANSI emulation wrappers
  */
 
-int winansi_fputs(const char *str, FILE *stream);
-int winansi_printf(const char *format, ...) __attribute__((format (printf, 1, 
2)));
-int winansi_fprintf(FILE *stream, const char *format, ...) 
__attribute__((format (printf, 2, 3)));
-int winansi_vfprintf(FILE *stream, const char *format, va_list list);
-#define fputs winansi_fputs
-#define printf(...) winansi_printf(__VA_ARGS__)
-#define fprintf(...) winansi_fprintf(__VA_ARGS__)
-#define vfprintf winansi_vfprintf
+void winansi_init(void);
+int winansi_isatty(int fd);
+HANDLE winansi_get_osfhandle(int fd);
+#define isatty winansi_isatty
 
 /*
  * git specific compatibility
diff --git a/compat/winansi.c b/compat/winansi.c
index bec6713..fcdd6dc 100644
--- 

[PATCH v2 6/6] Win32: fix broken pipe detection

2014-06-07 Thread Stepan Kasal
From: Karsten Blees bl...@dcon.de
Date: Thu, 1 Mar 2012 21:53:54 +0100

As of Win32: Thread-safe windows console output, git-log no longer
terminates when the pager process dies. This is due to disabling buffering
for the replaced stdout / stderr streams. Git-log will periodically fflush
stdout (see write_or_die.c/mayble_flush_or_die()), but with no buffering,
this is a NOP that always succeeds (so we never detect the EPIPE error).

Exchange the original console handles with our console thread pipe handles
by accessing the internal MSVCRT data structures directly (which are
exposed via __pioinfo for some reason).

Implement this with minimal assumptions about the actual data structure to
make it work with different (hopefully even future) MSVCRT versions.

While messing with internal data structures is ugly, this patch solves the
problem at the source instead of adding more workarounds. We no longer need
the special winansi_isatty override, and the limitations documented in
Win32: Thread-safe windows console output are gone (i.e. fdopen(1/2)
returns unbuffered streams now, and isatty() for duped console file
descriptors works as expected).

Signed-off-by: Karsten Blees bl...@dcon.de
Signed-off-by: Stepan Kasal ka...@ucw.cz
---
 compat/mingw.h   |   2 -
 compat/winansi.c | 114 ++-
 2 files changed, 70 insertions(+), 46 deletions(-)

diff --git a/compat/mingw.h b/compat/mingw.h
index 4b638d8..8dac6f9 100644
--- a/compat/mingw.h
+++ b/compat/mingw.h
@@ -318,9 +318,7 @@ int mingw_raise(int sig);
  */
 
 void winansi_init(void);
-int winansi_isatty(int fd);
 HANDLE winansi_get_osfhandle(int fd);
-#define isatty winansi_isatty
 
 /*
  * git specific compatibility
diff --git a/compat/winansi.c b/compat/winansi.c
index fcdd6dc..f96d5c2 100644
--- a/compat/winansi.c
+++ b/compat/winansi.c
@@ -8,11 +8,6 @@
 #include winreg.h
 
 /*
- Functions to be wrapped:
-*/
-#undef isatty
-
-/*
  ANSI codes used by git: m, K
 
  This file is git-specific. Therefore, this file does not attempt
@@ -104,6 +99,7 @@ static int is_console(int fd)
 
/* initialize attributes */
if (!initialized) {
+   console = hcon;
attr = plain_attr = sbi.wAttributes;
negative = 0;
initialized = 1;
@@ -465,29 +461,80 @@ static HANDLE duplicate_handle(HANDLE hnd)
return hresult;
 }
 
-static HANDLE redirect_console(FILE *stream, HANDLE *phcon, int new_fd)
-{
-   /* get original console handle */
-   int fd = _fileno(stream);
-   HANDLE hcon = (HANDLE) _get_osfhandle(fd);
-   if (hcon == INVALID_HANDLE_VALUE)
-   die_errno(_get_osfhandle(%i) failed, fd);
 
-   /* save a copy to phcon and console (used by the background thread) */
-   console = *phcon = duplicate_handle(hcon);
+/*
+ * Make MSVCRT's internal file descriptor control structure accessible
+ * so that we can tweak OS handles and flags directly (we need MSVCRT
+ * to treat our pipe handle as if it were a console).
+ *
+ * We assume that the ioinfo structure (exposed by MSVCRT.dll via
+ * __pioinfo) starts with the OS handle and the flags. The exact size
+ * varies between MSVCRT versions, so we try different sizes until
+ * toggling the FDEV bit of _pioinfo(1)-osflags is reflected in
+ * isatty(1).
+ */
+typedef struct {
+   HANDLE osfhnd;
+   char osflags;
+} ioinfo;
+
+extern __declspec(dllimport) ioinfo *__pioinfo[];
 
-   /* duplicate new_fd over fd (closes fd and associated handle (hcon)) */
-   if (_dup2(new_fd, fd))
-   die_errno(_dup2(%i, %i) failed, new_fd, fd);
+static size_t sizeof_ioinfo = 0;
 
-   /* no buffering, or stdout / stderr will be out of sync */
-   setbuf(stream, NULL);
-   return (HANDLE) _get_osfhandle(fd);
+#define IOINFO_L2E 5
+#define IOINFO_ARRAY_ELTS (1  IOINFO_L2E)
+
+#define FDEV  0x40
+
+static inline ioinfo* _pioinfo(int fd)
+{
+   return (ioinfo*)((char*)__pioinfo[fd  IOINFO_L2E] +
+   (fd  (IOINFO_ARRAY_ELTS - 1)) * sizeof_ioinfo);
+}
+
+static int init_sizeof_ioinfo()
+{
+   int istty, wastty;
+   /* don't init twice */
+   if (sizeof_ioinfo)
+   return sizeof_ioinfo = 256;
+
+   sizeof_ioinfo = sizeof(ioinfo);
+   wastty = isatty(1);
+   while (sizeof_ioinfo  256) {
+   /* toggle FDEV flag, check isatty, then toggle back */
+   _pioinfo(1)-osflags ^= FDEV;
+   istty = isatty(1);
+   _pioinfo(1)-osflags ^= FDEV;
+   /* return if we found the correct size */
+   if (istty != wastty)
+   return 0;
+   sizeof_ioinfo += sizeof(void*);
+   }
+   error(Tweaking file descriptors doesn't work with this MSVCRT.dll);
+   return 1;
+}
+
+static HANDLE swap_osfhnd(int fd, HANDLE new_handle)
+{
+   ioinfo *pioinfo;
+   HANDLE old_handle;
+
+   /* init ioinfo size if we 

[PATCH v2 0/6] First part of Unicode console support for msysgit

2014-06-07 Thread Stepan Kasal
Hello,
this patch series is to be applied on top of move main() macro to a function,
discussed in another thread.

I added the two patches Karsten mentioned:
  Win32: add Unicode conversion functions
  Win32: fix broken pipe detection

I also copied the links for the fixups incuded.

Regards,
Stepan

Karsten Blees (6):
  Support Unicode console output on Windows
  Detect console streams more reliably on Windows
  Warn if the Windows console font doesn't support Unicode
includes fixups:
- https://github.com/msysgit/git/commit/3abcb04d
- https://github.com/msysgit/git/commit/981aa538
  Win32: add Unicode conversion functions
  Win32: Thread-safe windows console output
includes fixups:
- https://github.com/msysgit/git/commit/cd0792af
- https://github.com/msysgit/git/commit/45e28a4d
  Win32: fix broken pipe detection

 compat/mingw.c   |  94 ++-
 compat/mingw.h   | 112 +-
 compat/winansi.c | 465 +--
 3 files changed, 546 insertions(+), 125 deletions(-)

-- 
2.0.0.9635.g0be03cb

--
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 3/6] Warn if the Windows console font doesn't support Unicode

2014-06-07 Thread Stepan Kasal
From: Karsten Blees bl...@dcon.de
Date: Sat, 31 Jul 2010 00:04:03 +

Unicode console output won't display correctly with default settings
because the default console font (Terminal) only supports the system's
OEM charset. Unfortunately, this is a user specific setting, so it cannot
be easily fixed by e.g. some registry tricks in the setup program.

This change prints a warning on exit if console output contained non-ascii
characters and the console font is supposedly not a TrueType font (which
usually have decent Unicode support).

Signed-off-by: Karsten Blees bl...@dcon.de
Signed-off-by: Johannes Schindelin johannes.schinde...@gmx.de
Signed-off-by: Stepan Kasal ka...@ucw.cz
---
 compat/winansi.c | 66 
 1 file changed, 66 insertions(+)

diff --git a/compat/winansi.c b/compat/winansi.c
index c4be401..bec6713 100644
--- a/compat/winansi.c
+++ b/compat/winansi.c
@@ -2,8 +2,11 @@
  * Copyright 2008 Peter Harris g...@peter.is-a-geek.org
  */
 
+#undef NOGDI
 #include ../git-compat-util.h
 #include malloc.h
+#include wingdi.h
+#include winreg.h
 
 /*
  Functions to be wrapped:
@@ -27,6 +30,62 @@ static WORD attr;
 static int negative;
 static FILE *last_stream = NULL;
 
+#ifdef __MINGW32__
+typedef struct _CONSOLE_FONT_INFOEX {
+   ULONG cbSize;
+   DWORD nFont;
+   COORD dwFontSize;
+   UINT FontFamily;
+   UINT FontWeight;
+   WCHAR FaceName[LF_FACESIZE];
+} CONSOLE_FONT_INFOEX, *PCONSOLE_FONT_INFOEX;
+#endif
+
+typedef BOOL (WINAPI *PGETCURRENTCONSOLEFONTEX)(HANDLE, BOOL,
+   PCONSOLE_FONT_INFOEX);
+
+static void print_font_warning(void)
+{
+   warning(Your console font probably doesn\'t support Unicode. If 
+   you experience strange characters in the output, consider 
+   switching to a TrueType font such as Lucida Console!);
+}
+
+static void check_truetype_font(void)
+{
+   static int truetype_font_checked;
+   DWORD fontFamily = 0;
+   PGETCURRENTCONSOLEFONTEX pGetCurrentConsoleFontEx;
+
+   /* don't do this twice */
+   if (truetype_font_checked)
+   return;
+   truetype_font_checked = 1;
+
+   /* GetCurrentConsoleFontEx is available since Vista */
+   pGetCurrentConsoleFontEx = (PGETCURRENTCONSOLEFONTEX) GetProcAddress(
+   GetModuleHandle(kernel32.dll), 
GetCurrentConsoleFontEx);
+   if (pGetCurrentConsoleFontEx) {
+   CONSOLE_FONT_INFOEX cfi;
+   cfi.cbSize = sizeof(cfi);
+   if (pGetCurrentConsoleFontEx(console, 0, cfi))
+   fontFamily = cfi.FontFamily;
+   } else {
+   /* pre-Vista: check default console font in registry */
+   HKEY hkey;
+   if (ERROR_SUCCESS == RegOpenKeyExA(HKEY_CURRENT_USER, 
Console, 0,
+   KEY_READ, hkey)) {
+   DWORD size = sizeof(fontFamily);
+   RegQueryValueExA(hkey, FontFamily, NULL, NULL,
+   (LPVOID) fontFamily, size);
+   RegCloseKey(hkey);
+   }
+   }
+
+   if (!(fontFamily  TMPF_TRUETYPE))
+   atexit(print_font_warning);
+}
+
 static int is_console(FILE *stream)
 {
CONSOLE_SCREEN_BUFFER_INFO sbi;
@@ -69,6 +128,13 @@ static int write_console(const char *str, size_t len)
 
WriteConsoleW(console, wbuf, wlen, NULL, NULL);
 
+   /*
+* if non-ascii characters are printed, check that the current console
+* font supports this
+*/
+   if (wlen != len)
+   check_truetype_font();
+
/* return original (utf-8 encoded) length */
return len;
 }
-- 
2.0.0.9635.g0be03cb

--
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 2/6] Detect console streams more reliably on Windows

2014-06-07 Thread Stepan Kasal
From: Karsten Blees bl...@dcon.de
Date: Sat, 31 Jul 2010 00:04:02 +

GetStdHandle(STD_OUTPUT_HANDLE) doesn't work for stderr if stdout is
redirected. Use _get_osfhandle of the FILE* instead.

_isatty() is true for all character devices (including parallel and serial
ports). Check return value of GetConsoleScreenBufferInfo instead to
reliably detect console handles (also don't initialize internal state from
an uninitialized CONSOLE_SCREEN_BUFFER_INFO structure if the function
fails).

Signed-off-by: Karsten Blees bl...@dcon.de
Signed-off-by: Johannes Schindelin johannes.schinde...@gmx.de
Signed-off-by: Stepan Kasal ka...@ucw.cz
---
 compat/winansi.c | 50 ++
 1 file changed, 26 insertions(+), 24 deletions(-)

diff --git a/compat/winansi.c b/compat/winansi.c
index abe0fea..c4be401 100644
--- a/compat/winansi.c
+++ b/compat/winansi.c
@@ -25,27 +25,39 @@ static HANDLE console;
 static WORD plain_attr;
 static WORD attr;
 static int negative;
+static FILE *last_stream = NULL;
 
-static void init(void)
+static int is_console(FILE *stream)
 {
CONSOLE_SCREEN_BUFFER_INFO sbi;
+   HANDLE hcon;
 
static int initialized = 0;
-   if (initialized)
-   return;
 
-   console = GetStdHandle(STD_OUTPUT_HANDLE);
-   if (console == INVALID_HANDLE_VALUE)
-   console = NULL;
+   /* use cached value if stream hasn't changed */
+   if (stream == last_stream)
+   return console != NULL;
 
-   if (!console)
-   return;
+   last_stream = stream;
+   console = NULL;
 
-   GetConsoleScreenBufferInfo(console, sbi);
-   attr = plain_attr = sbi.wAttributes;
-   negative = 0;
+   /* get OS handle of the stream */
+   hcon = (HANDLE) _get_osfhandle(_fileno(stream));
+   if (hcon == INVALID_HANDLE_VALUE)
+   return 0;
+
+   /* check if its a handle to a console output screen buffer */
+   if (!GetConsoleScreenBufferInfo(hcon, sbi))
+   return 0;
+
+   if (!initialized) {
+   attr = plain_attr = sbi.wAttributes;
+   negative = 0;
+   initialized = 1;
+   }
 
-   initialized = 1;
+   console = hcon;
+   return 1;
 }
 
 static int write_console(const char *str, size_t len)
@@ -292,12 +304,7 @@ int winansi_fputs(const char *str, FILE *stream)
 {
int rv;
 
-   if (!isatty(fileno(stream)))
-   return fputs(str, stream);
-
-   init();
-
-   if (!console)
+   if (!is_console(stream))
return fputs(str, stream);
 
rv = ansi_emulate(str, stream);
@@ -315,12 +322,7 @@ int winansi_vfprintf(FILE *stream, const char *format, 
va_list list)
char *buf = small_buf;
va_list cp;
 
-   if (!isatty(fileno(stream)))
-   goto abort;
-
-   init();
-
-   if (!console)
+   if (!is_console(stream))
goto abort;
 
va_copy(cp, list);
-- 
2.0.0.9635.g0be03cb

--
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] send-email: do not insert third header

2014-06-07 Thread Stepan Kasal
It is sometimes desirable to insert several header lines at the top of
the body, e.g., if From or Date differs from the mail header.
(Linus even recommends to use this second header for all kernel
submissions.)

send-email has a minimal support for this; make sure it is not applied
when there is a second header already inserted in the patch file.

Signed-off-by: Stepan Kasal ka...@ucw.cz
---
 git-send-email.perl | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/git-send-email.perl b/git-send-email.perl
index 9949db0..891df13 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -1456,7 +1456,9 @@ foreach my $t (@files) {
}
 
if (defined $sauthor and $sauthor ne $sender) {
-   $message = From: $author\n\n$message;
+   if ($message !~ m/^From: /) {
+   $message = From: $author\n\n$message;
+   }
if (defined $author_encoding) {
if ($has_content_type) {
if ($body_encoding eq $author_encoding) {
-- 
1.9.2.msysgit.0.496.g9a846d6

--
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: sort entries numerically

2014-06-07 Thread Fredrik Gustafsson
On Sat, Jun 07, 2014 at 08:05:34AM +0200, Toralf Förster wrote:
 is there any chance to have 1.8 before 1.10 in an output like the 
 following :
 
 ...
 From https://code.wireshark.org/review/wireshark
52fe0aa..b69642d  master - origin/master
460db8a..540f061  master-1.10 - origin/master-1.10
25bb29a..5741a40  master-1.12 - origin/master-1.12
4ee4fc11..97898a2 master-1.8 - origin/master-1.8

I don't find anything about it in git branch man page. However there's always:

git command | sort -d -r

as a workaround.

-- 
Med vänlig hälsning
Fredrik Gustafsson

tel: 0733-608274
e-post: iv...@iveqy.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: sort entries numerically

2014-06-07 Thread Duy Nguyen
On Sat, Jun 7, 2014 at 1:05 PM, Toralf Förster toralf.foers...@gmx.de wrote:
 Hi,

 is there any chance to have 1.8 before 1.10 in an output like the 
 following :

 ...
 From https://code.wireshark.org/review/wireshark
52fe0aa..b69642d  master - origin/master
460db8a..540f061  master-1.10 - origin/master-1.10
25bb29a..5741a40  master-1.12 - origin/master-1.12
4ee4fc11..97898a2 master-1.8 - origin/master-1.8

git-tag supports version sorting. Not sure if it should be default
sorting order in these listings (from fetch and push?). Maybe we could
have a config key for default sorting order.
-- 
Duy
--
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: Reset by checkout?

2014-06-07 Thread Philip Oakley

From: Atsushi Nakagawa at...@chejz.com

Kevin Bracey ke...@bracey.fi wrote:

On 01/06/2014 07:26, Atsushi Nakagawa wrote:
 Kevin Bracey ke...@bracey.fi wrote:
 The original git reset --hard used to be a pretty top-level 
 command.

 It was used for aborting merges in particular. But I think it now
 stands out as being one of the only really dangerous porcelain
 commands, and I can't think of any real workflow it's still useful
 for.
 My thoughts exactly.  I think the 'reset --soft/--mixed/--hard' 
 pattern
 is so ingrained, that many people just don't realize there's a 
 safer

 alternative.  (I've heard work mates on more than one occasion
 recommending 'reset --hard' as the go-to command for discarding 
 commits.)


 I believe this is likely because many third party GUI tools just 
 don't
 support 'reset --keep', and these tools present a Reset... dialog 
 with

 the de facto Soft/Mixed/Hard options.  (Even 'gitk' does this.)
True on the GUI - hard really needs demotion.

It would help if the documentation explained better straight off what
the different reset modes are intended /for/ in a more practical way,
rather than the technical jargon.


On one hand, I agree that improving man git-reset and making it easier
to understand would be of benefit.

However, one of the main culprits of confusion here seems to be the 
mere

existance of '--keep', which is somewhat of a conceptual black sheep.

The --soft/--mixed/--hard trio seems quite easy to explain, /if/ you
didn't need to also explain --keep...

To that end, I'm wondering if it's better to just deprecate 'reset
--keep' and shift the use-case over to 'checkout':

checkout [-u|--update] [commit|branch]

-u
--update
   Rather than checking out a branch to work on it, check out a commit
   and reset the current branch to that commit.

   This is functionally equivalent to 'checkout -B CURRENT_BRANCH 
commit'.


   (...Maybe a warning here about commits becoming unreachable...)


Then, as an added bonus, anything I've staged is kept intact.  *And*, 
I

can attempt 'checkout -u --merge' if I'm feeling particulary careless.


--hard
All [] changes are dropped[] and the [working tree] and index are
forcibly reset to the [state of commit].  Note that this is
dangerous if used carelessly.  ALL uncommitted changes to ALL
tracked files will be lost[].

Older documentation often recommends git reset --hard to
undo commits; the newer --keep option is [safer and is now the
recommended] alternative [for use in this situation].


I like this explaination of '--hard' and prefer it over current, which
doesn't much explain the gravity of the command.  I've made some edits
above.


--merge
Performs the operation of git merge --abort, intended for use
during a merge resolution - see git-merge(1) for more 
information.

This form is not normally used directly.


Aha, so that's what that's for.  I couldn't really understand the
explanation in the current manpage, but your version at least tells me
that it's an option I don't need to worry about.



Just to say there has been a similar confusion about 'git reset' 
reported on the Git Users group for the case of reset with added 
(staged), but uncommitted changes being wiped out, which simlarly 
reports on the difficulty of explaining some of the conditions 
especially when some are wrong ;-)


https://groups.google.com/forum/#!topic/git-users/27_FxIV_100


--
Philip 


--
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] completion: Handle '!f() { ... }; f' aliases

2014-06-07 Thread Steffen Prohaska
'!f() { ... }; f' is a recommended pattern to declare more complex
aliases (see git wiki [1]).  This commit teaches the completion to
handle them.

When determining which completion to use for an alias, the opening brace
is now ignored in order to continue the search for a git command inside
the function body.  For example, the alias '!f() { git commit ... }' now
triggers commit completion.  Previously, the search stopped on '{', and
the completion tried it to determine how to complete, which obviously
was useless.

Furthermore, the null command ':' is now skipped, so that it can be used
as a workaround to declare the desired completion style.  For example,
the alias '!f() { : git commit ; if ...  ' now triggers commit
completion.

[1] https://git.wiki.kernel.org/index.php/Aliases

Signed-off-by: Steffen Prohaska proha...@zib.de
---
 contrib/completion/git-completion.bash |  7 +++
 t/t9902-completion.sh  | 20 
 2 files changed, 27 insertions(+)

diff --git a/contrib/completion/git-completion.bash 
b/contrib/completion/git-completion.bash
index 2c59a76..aecb975 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -21,6 +21,11 @@
 #source ~/.git-completion.sh
 #3) Consider changing your PS1 to also show the current branch,
 #   see git-prompt.sh for details.
+#
+# If you use complex aliases of form '!f() { ... }; f', you can use the null
+# command ':' as the first command in the function body to declare the desired
+# completion style.  For example '!f() { : git commit ; ... }; f' will
+# tell the completion to use commit completion.
 
 case $COMP_WORDBREAKS in
 *:*) : great ;;
@@ -781,6 +786,8 @@ __git_aliased_command ()
-*) : option ;;
*=*): setting env ;;
git): git itself ;;
+   {)  : skip start of shell helper function ;;
+   :)  : skip null command ;;
*)
echo $word
return
diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh
index 2d4beb5..ea48681 100755
--- a/t/t9902-completion.sh
+++ b/t/t9902-completion.sh
@@ -550,6 +550,26 @@ test_expect_success 'complete files' '
test_completion git add mom momified
 '
 
+test_expect_success 'completion uses cmd completion for alias !f() { VAR=val 
git cmd ... }' '
+   git config alias.co !f() { VAR=val git checkout ... ; } f 
+   test_completion git co m -\EOF 
+   master Z
+   mybranch Z
+   mytag Z
+   EOF
+   git config --unset alias.co
+'
+
+test_expect_success 'completion used cmd completion for alias !f() { : git 
cmd ; ... }' '
+   git config alias.co !f() { : git checkout ; if ... } f 
+   test_completion git co m -\EOF 
+   master Z
+   mybranch Z
+   mytag Z
+   EOF
+   git config --unset alias.co
+'
+
 test_expect_failure 'complete with tilde expansion' '
git init tmp  cd tmp 
test_when_finished cd ..  rm -rf tmp 
-- 
2.0.0.244.g4e8e734

--
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 1/2] userdiff: support C# async methods and correct C# keywords

2014-06-07 Thread Steve Hoelzer
On Fri, Jun 6, 2014 at 12:34 PM, Junio C Hamano gits...@pobox.com wrote:
 Steve Hoelzer shoel...@gmail.com writes:

 instanceof() is listed as keywords, but there is no such thing (it is
 in Java, though); in C# we use typeof(), 'is', and 'as for similar
 purposes

 You would need to balance the quotes around as ;-)

Indeed. Doh.

 But reading the patch again after noticing that you have () after
 typeof but not after is/as, I am not sure if the change proposed
 here is even correct for the latter two.  I do not speal c-sharp, so
 I asked http://msdn.microsoft.com/en-us/library/cscsdfbt.aspx for
 some examples and here are what I found:

 Type t = typeof(ExampleClass)
 Base b = derived as Base;
 if (obj is MyObject) ...

 Unlike the control-flow keywords (e.g. do/while/for/...), do they
 typically appear at the beginning of lines?

No, I would never expect to see 'is' or 'as' at the beginning of a line.

 Isn't the purpose of these !^[ \t]* patterns to reject lines that
 begin with the language keywords that do not start functions, so
 listing a keyword that does not usually appear at the beginning of
 line looks like a churn that is not useful.

Not sure about the purpose of those lines, but I think you're correct.

Steve

 diff --git a/userdiff.c b/userdiff.c
 index fad52d6..96eda6c 100644
 --- a/userdiff.c
 +++ b/userdiff.c
 @@ -134,9 +134,9 @@ PATTERNS(cpp,
|[-+*/%^|=!]=|--|\\+\\+|=?|=?||\\|\\||::|-\\*?|\\.\\*),
  PATTERNS(csharp,
/* Keywords */
 -  !^[ 
 \t]*(do|while|for|if|else|instanceof|new|return|switch|case|throw|catch|using)\n
 +  !^[ 
 \t]*(do|while|for|foreach|if|else|typeof|is|as|new|return|switch|case|default|throw|try|catch|using)\n
/* Methods and constructors */
 -  ^[ 
 \t]*(((static|public|internal|private|protected|new|virtual|sealed|override|unsafe)[
  \t]+)*[][@.~_[:alnum:]]+[ \t]+[@._[:alnum:]]+[ \t]*\\(.*\\))[ \t]*$\n
 +  ^[ 
 \t]*(((static|public|internal|private|protected|new|virtual|sealed|override|unsafe|async)[
  \t]+)*[][@.~_[:alnum:]]+[ \t]+[@._[:alnum:]]+[ \t]*\\(.*\\))[ \t]*$\n
/* Properties */
^[ 
 \t]*(((static|public|internal|private|protected|new|virtual|sealed|override|unsafe)[
  \t]+)*[][@.~_[:alnum:]]+[ \t]+[@._[:alnum:]]+)[ \t]*$\n
/* Type definitions */
--
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