Re: Errors GITtifying GCC and Binutils
- From
Linus Torvalds <torvalds@osdl.org>
- Date
- Mar 23, 2006, 21:48 UTC
- Message-ID
- <Pine.LNX.4.64.0603231347440.26286@g5.osdl.org>
- In-Reply-To
- <20060323.133120.69312511.davem@davemloft.net>
On Thu, 23 Mar 2006, David S. Miller wrote:
Show 9 quoted lines
> > > Yeah, I'm not counting things like Eclipse etc. I'm talking about "plain > > SCM" environments, ie just basic SVN or CVS. What are we missing in that > > department? (The only thing I can think of is a diff colorizer, which some > > prople seem to really want). > > gitk does color the diffs already, or are we talking about some > "side-by-side" multiple window thing showing "before" on the > left and "after" on the right?
I think we're just talking about
git diff | git colorize
like this (and then integrating it a bit better).
Linus
--- colorize.c --- #include "cache.h"
#define BUFSIZE 128
#define NORMAL "" #define BOLD "\033[1m" #define UL "\033[4m"
#define GRAYBG "\033[47m"
#define BLACK "\033[30m" #define RED "\033[31m" #define GREEN "\033[32m" #define YELLOW "\033[33m" #define BLUE "\033[34m" #define MAGENTA "\033[35m" #define CYAN "\033[36m" #define WHITE "\033[37m" #define RESET "\033[m"
enum linetype {
UNKNOWN,
HEAD,
FRAGHEAD,
ADD,
REMOVE,
UNCHANGED,
};static const char *tput[][2] = {
[UNKNOWN] = { NORMAL, NORMAL "\n" },
[HEAD] = { BOLD, RESET "\n" },
[FRAGHEAD] = { GRAYBG, RESET "\n" },
[ADD] = { GREEN, RESET "\n" },
[REMOVE] = { RED, RESET "\n" },
[UNCHANGED] = { NORMAL, NORMAL "\n" },
};static void colorize(FILE *in, FILE *out)
{
char buffer[BUFSIZE];
const char *end = NULL;
int in_fragment = 0; while (fgets(buffer, BUFSIZE, in)) {
int type = UNKNOWN;
int eoln, len = strlen(buffer);
const char *begin;if (!len) break; eoln = buffer[len-1] == '\n'; if (eoln) buffer[--len] = 0;
/* Did we have a partial line from before? */
if (end) {
fputs(buffer, out);
if (!eoln)
continue;
fputs(end, out);
end = NULL;
continue;
} if (in_fragment) {
in_fragment--;
switch (buffer[0]) {
case '+':
type = ADD;
break;
case '-':
type = REMOVE;
break;
case ' ':
type = UNCHANGED;
break;
case '\\':
type = UNCHANGED;
break;
default:
in_fragment = 0;
}
}
if (type == UNKNOWN) {
if (!strncmp(buffer, "@@ ", 3)) {
type = FRAGHEAD;
/* We should parse the line numbers */
in_fragment = INT_MAX;
}
if (!strncmp(buffer, "+++ ", 4) ||
!strncmp(buffer, "--- ", 4) ||
!strncmp(buffer, "diff ", 5))
type = HEAD;
}begin = tput[type][0]; end = tput[type][1]; fputs(begin, out); fputs(buffer, out); if (!eoln) continue; fputs(end, out); end = NULL; } if (end) fputs(end, out); }
int main(int argc, char **argv)
{
colorize(stdin, stdout);
return 0;
}