view mercurial/compat.h @ 32383:f928d53b687c stable

dispatch: setup color before pager for correct console information on windows Before this patch, "hg CMD --pager on" on Windows shows output unintentionally decorated with ANSI color escape sequences, if color mode is "auto". This issue occurs in steps below. 1. dispatch() invokes ui.pager() at detection of "--pager on" 2. stdout of hg process is redirected into stdin of pager process 3. "ui.formatted" = True, because isatty(stdout) is so before (2) 4. color module is loaded for colorization 5. color.w32effects = None, because GetConsoleScreenBufferInfo() fails on stdout redirected at (2) 6. "ansi" color mode is chosen, because of "not w32effects" 7. output is colorized in "ansi" mode because of "ui.formatted" = True Even if "ansi" color mode is chosen, ordinarily redirected stdout makes ui.formatted() return False, and colorization is avoided. But in this issue case, "ui.formatted" = True at (3) forces output to be colorized. For correct console information on win32, it is needed to ensure that color module is loaded before redirection of stdout for pagination. BTW, if any of enabled extensions has "colortable" attribute, this issue is avoided even before this patch, because color module is imported as a part of loading such extension, and extension loading occurs before setting up pager. For example, mq and keyword have "colortable".
author FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
date Tue, 23 May 2017 03:29:23 +0900
parents 7b22599dcb85
children f4433f2713d0
line wrap: on
line source

#ifndef _HG_COMPAT_H_
#define _HG_COMPAT_H_

#ifdef _WIN32
#ifdef _MSC_VER
/* msvc 6.0 has problems */
#define inline __inline
#if defined(_WIN64)
typedef __int64 ssize_t;
#else
typedef int ssize_t;
#endif
typedef signed char int8_t;
typedef short int16_t;
typedef long int32_t;
typedef __int64 int64_t;
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned long uint32_t;
typedef unsigned __int64 uint64_t;
#else
#include <stdint.h>
#endif
#else
/* not windows */
#include <sys/types.h>
#if defined __BEOS__ && !defined __HAIKU__
#include <ByteOrder.h>
#else
#include <arpa/inet.h>
#endif
#include <inttypes.h>
#endif

#if defined __hpux || defined __SUNPRO_C || defined _AIX
#define inline
#endif

#ifdef __linux
#define inline __inline
#endif

#endif