2013-02-20 20:01:56 +00:00
|
|
|
#include "cache.h"
|
sideband: highlight keywords in remote sideband output
The colorization is controlled with the config setting "color.remote".
Supported keywords are "error", "warning", "hint" and "success". They
are highlighted if they appear at the start of the line, which is
common in error messages, eg.
ERROR: commit is missing Change-Id
The Git push process itself prints lots of non-actionable messages
(eg. bandwidth statistics, object counters for different phases of the
process). This obscures actionable error messages that servers may
send back. Highlighting keywords in the sideband draws more attention
to those messages.
The background for this change is that Gerrit does server-side
processing to create or update code reviews, and actionable error
messages (eg. missing Change-Id) must be communicated back to the user
during the push. User research has shown that new users have trouble
seeing these messages.
The highlighting is done on the client rather than server side, so
servers don't have to grow capabilities to understand terminal escape
codes and terminal state. It also consistent with the current state
where Git is control of the local display (eg. prefixing messages with
"remote: ").
The highlighting can be configured using color.remote.<KEYWORD>
configuration settings. Since the keys are matched case insensitively,
we match the keywords case insensitively too.
Finally, this solution is backwards compatible: many servers already
prefix their messages with "error", and they will benefit from this
change without requiring a server update. By contrast, a server-side
solution would likely require plumbing the TERM variable through the
git protocol, so it would require changes to both server and client.
Helped-by: Duy Nguyen <pclouds@gmail.com>
Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2018-08-07 12:51:08 +00:00
|
|
|
#include "color.h"
|
|
|
|
#include "config.h"
|
2006-09-10 08:06:33 +00:00
|
|
|
#include "pkt-line.h"
|
|
|
|
#include "sideband.h"
|
sideband: highlight keywords in remote sideband output
The colorization is controlled with the config setting "color.remote".
Supported keywords are "error", "warning", "hint" and "success". They
are highlighted if they appear at the start of the line, which is
common in error messages, eg.
ERROR: commit is missing Change-Id
The Git push process itself prints lots of non-actionable messages
(eg. bandwidth statistics, object counters for different phases of the
process). This obscures actionable error messages that servers may
send back. Highlighting keywords in the sideband draws more attention
to those messages.
The background for this change is that Gerrit does server-side
processing to create or update code reviews, and actionable error
messages (eg. missing Change-Id) must be communicated back to the user
during the push. User research has shown that new users have trouble
seeing these messages.
The highlighting is done on the client rather than server side, so
servers don't have to grow capabilities to understand terminal escape
codes and terminal state. It also consistent with the current state
where Git is control of the local display (eg. prefixing messages with
"remote: ").
The highlighting can be configured using color.remote.<KEYWORD>
configuration settings. Since the keys are matched case insensitively,
we match the keywords case insensitively too.
Finally, this solution is backwards compatible: many servers already
prefix their messages with "error", and they will benefit from this
change without requiring a server update. By contrast, a server-side
solution would likely require plumbing the TERM variable through the
git protocol, so it would require changes to both server and client.
Helped-by: Duy Nguyen <pclouds@gmail.com>
Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2018-08-07 12:51:08 +00:00
|
|
|
#include "help.h"
|
|
|
|
|
|
|
|
struct keyword_entry {
|
|
|
|
/*
|
|
|
|
* We use keyword as config key so it should be a single alphanumeric word.
|
|
|
|
*/
|
|
|
|
const char *keyword;
|
|
|
|
char color[COLOR_MAXLEN];
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct keyword_entry keywords[] = {
|
|
|
|
{ "hint", GIT_COLOR_YELLOW },
|
|
|
|
{ "warning", GIT_COLOR_BOLD_YELLOW },
|
|
|
|
{ "success", GIT_COLOR_BOLD_GREEN },
|
|
|
|
{ "error", GIT_COLOR_BOLD_RED },
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Returns a color setting (GIT_COLOR_NEVER, etc). */
|
|
|
|
static int use_sideband_colors(void)
|
|
|
|
{
|
|
|
|
static int use_sideband_colors_cached = -1;
|
|
|
|
|
|
|
|
const char *key = "color.remote";
|
|
|
|
struct strbuf sb = STRBUF_INIT;
|
|
|
|
char *value;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (use_sideband_colors_cached >= 0)
|
|
|
|
return use_sideband_colors_cached;
|
|
|
|
|
|
|
|
if (!git_config_get_string(key, &value)) {
|
|
|
|
use_sideband_colors_cached = git_config_colorbool(key, value);
|
|
|
|
} else if (!git_config_get_string("color.ui", &value)) {
|
|
|
|
use_sideband_colors_cached = git_config_colorbool("color.ui", value);
|
|
|
|
} else {
|
|
|
|
use_sideband_colors_cached = GIT_COLOR_AUTO;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(keywords); i++) {
|
|
|
|
strbuf_reset(&sb);
|
|
|
|
strbuf_addf(&sb, "%s.%s", key, keywords[i].keyword);
|
|
|
|
if (git_config_get_string(sb.buf, &value))
|
|
|
|
continue;
|
|
|
|
if (color_parse(value, keywords[i].color))
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
strbuf_release(&sb);
|
|
|
|
return use_sideband_colors_cached;
|
|
|
|
}
|
|
|
|
|
|
|
|
void list_config_color_sideband_slots(struct string_list *list, const char *prefix)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(keywords); i++)
|
|
|
|
list_config_item(list, prefix, keywords[i].keyword);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Optionally highlight one keyword in remote output if it appears at the start
|
|
|
|
* of the line. This should be called for a single line only, which is
|
|
|
|
* passed as the first N characters of the SRC array.
|
2018-08-18 16:16:28 +00:00
|
|
|
*
|
|
|
|
* NEEDSWORK: use "size_t n" instead for clarity.
|
sideband: highlight keywords in remote sideband output
The colorization is controlled with the config setting "color.remote".
Supported keywords are "error", "warning", "hint" and "success". They
are highlighted if they appear at the start of the line, which is
common in error messages, eg.
ERROR: commit is missing Change-Id
The Git push process itself prints lots of non-actionable messages
(eg. bandwidth statistics, object counters for different phases of the
process). This obscures actionable error messages that servers may
send back. Highlighting keywords in the sideband draws more attention
to those messages.
The background for this change is that Gerrit does server-side
processing to create or update code reviews, and actionable error
messages (eg. missing Change-Id) must be communicated back to the user
during the push. User research has shown that new users have trouble
seeing these messages.
The highlighting is done on the client rather than server side, so
servers don't have to grow capabilities to understand terminal escape
codes and terminal state. It also consistent with the current state
where Git is control of the local display (eg. prefixing messages with
"remote: ").
The highlighting can be configured using color.remote.<KEYWORD>
configuration settings. Since the keys are matched case insensitively,
we match the keywords case insensitively too.
Finally, this solution is backwards compatible: many servers already
prefix their messages with "error", and they will benefit from this
change without requiring a server update. By contrast, a server-side
solution would likely require plumbing the TERM variable through the
git protocol, so it would require changes to both server and client.
Helped-by: Duy Nguyen <pclouds@gmail.com>
Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2018-08-07 12:51:08 +00:00
|
|
|
*/
|
|
|
|
static void maybe_colorize_sideband(struct strbuf *dest, const char *src, int n)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!want_color_stderr(use_sideband_colors())) {
|
|
|
|
strbuf_add(dest, src, n);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-08-18 16:16:28 +00:00
|
|
|
while (0 < n && isspace(*src)) {
|
sideband: highlight keywords in remote sideband output
The colorization is controlled with the config setting "color.remote".
Supported keywords are "error", "warning", "hint" and "success". They
are highlighted if they appear at the start of the line, which is
common in error messages, eg.
ERROR: commit is missing Change-Id
The Git push process itself prints lots of non-actionable messages
(eg. bandwidth statistics, object counters for different phases of the
process). This obscures actionable error messages that servers may
send back. Highlighting keywords in the sideband draws more attention
to those messages.
The background for this change is that Gerrit does server-side
processing to create or update code reviews, and actionable error
messages (eg. missing Change-Id) must be communicated back to the user
during the push. User research has shown that new users have trouble
seeing these messages.
The highlighting is done on the client rather than server side, so
servers don't have to grow capabilities to understand terminal escape
codes and terminal state. It also consistent with the current state
where Git is control of the local display (eg. prefixing messages with
"remote: ").
The highlighting can be configured using color.remote.<KEYWORD>
configuration settings. Since the keys are matched case insensitively,
we match the keywords case insensitively too.
Finally, this solution is backwards compatible: many servers already
prefix their messages with "error", and they will benefit from this
change without requiring a server update. By contrast, a server-side
solution would likely require plumbing the TERM variable through the
git protocol, so it would require changes to both server and client.
Helped-by: Duy Nguyen <pclouds@gmail.com>
Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2018-08-07 12:51:08 +00:00
|
|
|
strbuf_addch(dest, *src);
|
|
|
|
src++;
|
|
|
|
n--;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(keywords); i++) {
|
|
|
|
struct keyword_entry *p = keywords + i;
|
|
|
|
int len = strlen(p->keyword);
|
2018-08-18 16:16:28 +00:00
|
|
|
|
|
|
|
if (n <= len)
|
|
|
|
continue;
|
sideband: highlight keywords in remote sideband output
The colorization is controlled with the config setting "color.remote".
Supported keywords are "error", "warning", "hint" and "success". They
are highlighted if they appear at the start of the line, which is
common in error messages, eg.
ERROR: commit is missing Change-Id
The Git push process itself prints lots of non-actionable messages
(eg. bandwidth statistics, object counters for different phases of the
process). This obscures actionable error messages that servers may
send back. Highlighting keywords in the sideband draws more attention
to those messages.
The background for this change is that Gerrit does server-side
processing to create or update code reviews, and actionable error
messages (eg. missing Change-Id) must be communicated back to the user
during the push. User research has shown that new users have trouble
seeing these messages.
The highlighting is done on the client rather than server side, so
servers don't have to grow capabilities to understand terminal escape
codes and terminal state. It also consistent with the current state
where Git is control of the local display (eg. prefixing messages with
"remote: ").
The highlighting can be configured using color.remote.<KEYWORD>
configuration settings. Since the keys are matched case insensitively,
we match the keywords case insensitively too.
Finally, this solution is backwards compatible: many servers already
prefix their messages with "error", and they will benefit from this
change without requiring a server update. By contrast, a server-side
solution would likely require plumbing the TERM variable through the
git protocol, so it would require changes to both server and client.
Helped-by: Duy Nguyen <pclouds@gmail.com>
Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2018-08-07 12:51:08 +00:00
|
|
|
/*
|
|
|
|
* Match case insensitively, so we colorize output from existing
|
|
|
|
* servers regardless of the case that they use for their
|
|
|
|
* messages. We only highlight the word precisely, so
|
|
|
|
* "successful" stays uncolored.
|
|
|
|
*/
|
|
|
|
if (!strncasecmp(p->keyword, src, len) && !isalnum(src[len])) {
|
|
|
|
strbuf_addstr(dest, p->color);
|
|
|
|
strbuf_add(dest, src, len);
|
|
|
|
strbuf_addstr(dest, GIT_COLOR_RESET);
|
|
|
|
n -= len;
|
|
|
|
src += len;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
strbuf_add(dest, src, n);
|
|
|
|
}
|
|
|
|
|
2006-09-10 08:06:33 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Receive multiplexed output stream over git native protocol.
|
|
|
|
* in_stream is the input stream from the remote, which carries data
|
|
|
|
* in pkt_line format with band designator. Demultiplex it into out
|
|
|
|
* and err and return error appropriately. Band #1 carries the
|
|
|
|
* primary payload. Things coming over band #2 is not necessarily
|
|
|
|
* error; they are usually informative message on the standard error
|
|
|
|
* stream, aka "verbose"). A message over band #3 is a signal that
|
|
|
|
* the remote died unexpectedly. A flush() concludes the stream.
|
|
|
|
*/
|
2007-11-04 04:22:42 +00:00
|
|
|
|
2018-04-21 11:18:42 +00:00
|
|
|
#define DISPLAY_PREFIX "remote: "
|
2008-01-08 16:24:53 +00:00
|
|
|
|
|
|
|
#define ANSI_SUFFIX "\033[K"
|
|
|
|
#define DUMB_SUFFIX " "
|
|
|
|
|
2009-03-10 21:54:17 +00:00
|
|
|
int recv_sideband(const char *me, int in_stream, int out)
|
2006-09-10 08:06:33 +00:00
|
|
|
{
|
2017-11-29 14:37:51 +00:00
|
|
|
const char *suffix;
|
2016-06-28 04:35:26 +00:00
|
|
|
char buf[LARGE_PACKET_MAX + 1];
|
|
|
|
struct strbuf outbuf = STRBUF_INIT;
|
|
|
|
int retval = 0;
|
2008-01-08 16:24:53 +00:00
|
|
|
|
2017-11-29 14:37:51 +00:00
|
|
|
if (isatty(2) && !is_terminal_dumb())
|
2008-01-08 16:24:53 +00:00
|
|
|
suffix = ANSI_SUFFIX;
|
|
|
|
else
|
|
|
|
suffix = DUMB_SUFFIX;
|
|
|
|
|
2016-06-28 04:35:26 +00:00
|
|
|
while (!retval) {
|
|
|
|
const char *b, *brk;
|
2006-10-11 15:49:15 +00:00
|
|
|
int band, len;
|
2016-06-28 04:35:26 +00:00
|
|
|
len = packet_read(in_stream, NULL, NULL, buf, LARGE_PACKET_MAX, 0);
|
2006-09-10 08:06:33 +00:00
|
|
|
if (len == 0)
|
|
|
|
break;
|
|
|
|
if (len < 1) {
|
2016-06-28 04:35:26 +00:00
|
|
|
strbuf_addf(&outbuf,
|
|
|
|
"%s%s: protocol error: no band designator",
|
|
|
|
outbuf.len ? "\n" : "", me);
|
|
|
|
retval = SIDEBAND_PROTOCOL_ERROR;
|
|
|
|
break;
|
2006-09-10 08:06:33 +00:00
|
|
|
}
|
2016-06-28 04:35:26 +00:00
|
|
|
band = buf[0] & 0xff;
|
|
|
|
buf[len] = '\0';
|
2006-09-10 08:06:33 +00:00
|
|
|
len--;
|
2006-10-11 15:49:15 +00:00
|
|
|
switch (band) {
|
2006-09-10 08:06:33 +00:00
|
|
|
case 3:
|
sideband: highlight keywords in remote sideband output
The colorization is controlled with the config setting "color.remote".
Supported keywords are "error", "warning", "hint" and "success". They
are highlighted if they appear at the start of the line, which is
common in error messages, eg.
ERROR: commit is missing Change-Id
The Git push process itself prints lots of non-actionable messages
(eg. bandwidth statistics, object counters for different phases of the
process). This obscures actionable error messages that servers may
send back. Highlighting keywords in the sideband draws more attention
to those messages.
The background for this change is that Gerrit does server-side
processing to create or update code reviews, and actionable error
messages (eg. missing Change-Id) must be communicated back to the user
during the push. User research has shown that new users have trouble
seeing these messages.
The highlighting is done on the client rather than server side, so
servers don't have to grow capabilities to understand terminal escape
codes and terminal state. It also consistent with the current state
where Git is control of the local display (eg. prefixing messages with
"remote: ").
The highlighting can be configured using color.remote.<KEYWORD>
configuration settings. Since the keys are matched case insensitively,
we match the keywords case insensitively too.
Finally, this solution is backwards compatible: many servers already
prefix their messages with "error", and they will benefit from this
change without requiring a server update. By contrast, a server-side
solution would likely require plumbing the TERM variable through the
git protocol, so it would require changes to both server and client.
Helped-by: Duy Nguyen <pclouds@gmail.com>
Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2018-08-07 12:51:08 +00:00
|
|
|
strbuf_addf(&outbuf, "%s%s", outbuf.len ? "\n" : "",
|
|
|
|
DISPLAY_PREFIX);
|
|
|
|
maybe_colorize_sideband(&outbuf, buf + 1, len);
|
|
|
|
|
2016-06-28 04:35:26 +00:00
|
|
|
retval = SIDEBAND_REMOTE_ERROR;
|
|
|
|
break;
|
2006-09-10 08:06:33 +00:00
|
|
|
case 2:
|
2016-06-28 04:35:26 +00:00
|
|
|
b = buf + 1;
|
2007-11-04 04:22:42 +00:00
|
|
|
|
2016-06-28 04:35:26 +00:00
|
|
|
/*
|
|
|
|
* Append a suffix to each nonempty line to clear the
|
|
|
|
* end of the screen line.
|
|
|
|
*
|
|
|
|
* The output is accumulated in a buffer and
|
|
|
|
* each line is printed to stderr using
|
|
|
|
* write(2) to ensure inter-process atomicity.
|
|
|
|
*/
|
|
|
|
while ((brk = strpbrk(b, "\n\r"))) {
|
|
|
|
int linelen = brk - b;
|
2007-11-04 04:22:42 +00:00
|
|
|
|
2016-06-28 04:35:26 +00:00
|
|
|
if (!outbuf.len)
|
2018-04-21 11:18:42 +00:00
|
|
|
strbuf_addstr(&outbuf, DISPLAY_PREFIX);
|
2016-06-28 04:35:26 +00:00
|
|
|
if (linelen > 0) {
|
sideband: highlight keywords in remote sideband output
The colorization is controlled with the config setting "color.remote".
Supported keywords are "error", "warning", "hint" and "success". They
are highlighted if they appear at the start of the line, which is
common in error messages, eg.
ERROR: commit is missing Change-Id
The Git push process itself prints lots of non-actionable messages
(eg. bandwidth statistics, object counters for different phases of the
process). This obscures actionable error messages that servers may
send back. Highlighting keywords in the sideband draws more attention
to those messages.
The background for this change is that Gerrit does server-side
processing to create or update code reviews, and actionable error
messages (eg. missing Change-Id) must be communicated back to the user
during the push. User research has shown that new users have trouble
seeing these messages.
The highlighting is done on the client rather than server side, so
servers don't have to grow capabilities to understand terminal escape
codes and terminal state. It also consistent with the current state
where Git is control of the local display (eg. prefixing messages with
"remote: ").
The highlighting can be configured using color.remote.<KEYWORD>
configuration settings. Since the keys are matched case insensitively,
we match the keywords case insensitively too.
Finally, this solution is backwards compatible: many servers already
prefix their messages with "error", and they will benefit from this
change without requiring a server update. By contrast, a server-side
solution would likely require plumbing the TERM variable through the
git protocol, so it would require changes to both server and client.
Helped-by: Duy Nguyen <pclouds@gmail.com>
Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2018-08-07 12:51:08 +00:00
|
|
|
maybe_colorize_sideband(&outbuf, b, linelen);
|
|
|
|
strbuf_addstr(&outbuf, suffix);
|
2008-09-03 19:13:42 +00:00
|
|
|
}
|
sideband: highlight keywords in remote sideband output
The colorization is controlled with the config setting "color.remote".
Supported keywords are "error", "warning", "hint" and "success". They
are highlighted if they appear at the start of the line, which is
common in error messages, eg.
ERROR: commit is missing Change-Id
The Git push process itself prints lots of non-actionable messages
(eg. bandwidth statistics, object counters for different phases of the
process). This obscures actionable error messages that servers may
send back. Highlighting keywords in the sideband draws more attention
to those messages.
The background for this change is that Gerrit does server-side
processing to create or update code reviews, and actionable error
messages (eg. missing Change-Id) must be communicated back to the user
during the push. User research has shown that new users have trouble
seeing these messages.
The highlighting is done on the client rather than server side, so
servers don't have to grow capabilities to understand terminal escape
codes and terminal state. It also consistent with the current state
where Git is control of the local display (eg. prefixing messages with
"remote: ").
The highlighting can be configured using color.remote.<KEYWORD>
configuration settings. Since the keys are matched case insensitively,
we match the keywords case insensitively too.
Finally, this solution is backwards compatible: many servers already
prefix their messages with "error", and they will benefit from this
change without requiring a server update. By contrast, a server-side
solution would likely require plumbing the TERM variable through the
git protocol, so it would require changes to both server and client.
Helped-by: Duy Nguyen <pclouds@gmail.com>
Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2018-08-07 12:51:08 +00:00
|
|
|
|
|
|
|
strbuf_addch(&outbuf, *brk);
|
2016-06-28 04:35:26 +00:00
|
|
|
xwrite(2, outbuf.buf, outbuf.len);
|
|
|
|
strbuf_reset(&outbuf);
|
2007-11-04 04:22:42 +00:00
|
|
|
|
2016-06-28 04:35:26 +00:00
|
|
|
b = brk + 1;
|
|
|
|
}
|
|
|
|
|
sideband: highlight keywords in remote sideband output
The colorization is controlled with the config setting "color.remote".
Supported keywords are "error", "warning", "hint" and "success". They
are highlighted if they appear at the start of the line, which is
common in error messages, eg.
ERROR: commit is missing Change-Id
The Git push process itself prints lots of non-actionable messages
(eg. bandwidth statistics, object counters for different phases of the
process). This obscures actionable error messages that servers may
send back. Highlighting keywords in the sideband draws more attention
to those messages.
The background for this change is that Gerrit does server-side
processing to create or update code reviews, and actionable error
messages (eg. missing Change-Id) must be communicated back to the user
during the push. User research has shown that new users have trouble
seeing these messages.
The highlighting is done on the client rather than server side, so
servers don't have to grow capabilities to understand terminal escape
codes and terminal state. It also consistent with the current state
where Git is control of the local display (eg. prefixing messages with
"remote: ").
The highlighting can be configured using color.remote.<KEYWORD>
configuration settings. Since the keys are matched case insensitively,
we match the keywords case insensitively too.
Finally, this solution is backwards compatible: many servers already
prefix their messages with "error", and they will benefit from this
change without requiring a server update. By contrast, a server-side
solution would likely require plumbing the TERM variable through the
git protocol, so it would require changes to both server and client.
Helped-by: Duy Nguyen <pclouds@gmail.com>
Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2018-08-07 12:51:08 +00:00
|
|
|
if (*b) {
|
|
|
|
strbuf_addstr(&outbuf, outbuf.len ?
|
|
|
|
"" : DISPLAY_PREFIX);
|
|
|
|
maybe_colorize_sideband(&outbuf, b, strlen(b));
|
|
|
|
}
|
2016-06-28 04:35:26 +00:00
|
|
|
break;
|
2006-09-10 08:06:33 +00:00
|
|
|
case 1:
|
2016-06-28 04:35:26 +00:00
|
|
|
write_or_die(out, buf + 1, len);
|
|
|
|
break;
|
2006-09-10 08:06:33 +00:00
|
|
|
default:
|
2016-06-28 04:35:26 +00:00
|
|
|
strbuf_addf(&outbuf, "%s%s: protocol error: bad band #%d",
|
|
|
|
outbuf.len ? "\n" : "", me, band);
|
|
|
|
retval = SIDEBAND_PROTOCOL_ERROR;
|
|
|
|
break;
|
2006-09-10 08:06:33 +00:00
|
|
|
}
|
|
|
|
}
|
2016-06-28 04:35:26 +00:00
|
|
|
|
|
|
|
if (outbuf.len) {
|
2016-07-05 20:35:50 +00:00
|
|
|
strbuf_addch(&outbuf, '\n');
|
2016-06-28 04:35:26 +00:00
|
|
|
xwrite(2, outbuf.buf, outbuf.len);
|
|
|
|
}
|
|
|
|
strbuf_release(&outbuf);
|
|
|
|
return retval;
|
2006-09-10 08:06:33 +00:00
|
|
|
}
|
2006-09-10 10:20:24 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* fd is connected to the remote side; send the sideband data
|
|
|
|
* over multiplexed packet stream.
|
|
|
|
*/
|
2016-06-14 14:49:16 +00:00
|
|
|
void send_sideband(int fd, int band, const char *data, ssize_t sz, int packet_max)
|
2006-09-10 10:20:24 +00:00
|
|
|
{
|
|
|
|
const char *p = data;
|
|
|
|
|
|
|
|
while (sz) {
|
|
|
|
unsigned n;
|
|
|
|
char hdr[5];
|
|
|
|
|
|
|
|
n = sz;
|
|
|
|
if (packet_max - 5 < n)
|
|
|
|
n = packet_max - 5;
|
2009-10-31 00:47:41 +00:00
|
|
|
if (0 <= band) {
|
2015-09-24 21:06:08 +00:00
|
|
|
xsnprintf(hdr, sizeof(hdr), "%04x", n + 5);
|
2009-10-31 00:47:41 +00:00
|
|
|
hdr[4] = band;
|
2013-02-20 20:01:56 +00:00
|
|
|
write_or_die(fd, hdr, 5);
|
2009-10-31 00:47:41 +00:00
|
|
|
} else {
|
2015-09-24 21:06:08 +00:00
|
|
|
xsnprintf(hdr, sizeof(hdr), "%04x", n + 4);
|
2013-02-20 20:01:56 +00:00
|
|
|
write_or_die(fd, hdr, 4);
|
2009-10-31 00:47:41 +00:00
|
|
|
}
|
2013-02-20 20:01:56 +00:00
|
|
|
write_or_die(fd, p, n);
|
2006-09-10 10:20:24 +00:00
|
|
|
p += n;
|
|
|
|
sz -= n;
|
|
|
|
}
|
|
|
|
}
|