From: Jeff King <peff@peff.net>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org
Subject: [PATCH 4/4] include agent identifier in capability string
Date: Sat, 2 Jun 2012 15:05:03 -0400 [thread overview]
Message-ID: <20120602190503.GD14369@sigill.intra.peff.net> (raw)
In-Reply-To: <20120602184948.GA14269@sigill.intra.peff.net>
Instead of having the client advertise a particular version
number in the git protocol, we have managed extensions and
backwards compatibility by having clients and servers
advertise capabilities that they support. This is far more
robust than having each side consult a table of
known versions, and provides sufficient information for the
protocol interaction to complete.
However, it does not allow servers to keep statistics on
which client versions are being used. This information is
not necessary to complete the network request (the
capabilities provide enough information for that), but it
may be helpful to conduct a general survey of client
versions in use.
We already send the client version in the user-agent header
for http requests; adding it here allows us to gather
similar statistics for non-http requests.
Signed-off-by: Jeff King <peff@peff.net>
---
Two important changes from the previous round:
1. We sanitize the agent string to remove non-printable characters and
whitespace (they are replaced with '.'). This generally shouldn't
happen, but is a defensive measure against breaking the protocol.
2. The server half of the connection will advertise their versions in
the capability strings, too.
builtin/fetch-pack.c | 2 ++
builtin/receive-pack.c | 6 ++++--
builtin/send-pack.c | 7 +++++--
upload-pack.c | 7 +++++--
version.c | 21 +++++++++++++++++++++
version.h | 1 +
6 files changed, 38 insertions(+), 6 deletions(-)
diff --git a/builtin/fetch-pack.c b/builtin/fetch-pack.c
index 149db88..fe56596 100644
--- a/builtin/fetch-pack.c
+++ b/builtin/fetch-pack.c
@@ -10,6 +10,7 @@
#include "remote.h"
#include "run-command.h"
#include "transport.h"
+#include "version.h"
static int transfer_unpack_limit = -1;
static int fetch_unpack_limit = -1;
@@ -327,6 +328,7 @@ static int find_common(int fd[2], unsigned char *result_sha1,
if (args.no_progress) strbuf_addstr(&c, " no-progress");
if (args.include_tag) strbuf_addstr(&c, " include-tag");
if (prefer_ofs_delta) strbuf_addstr(&c, " ofs-delta");
+ strbuf_addf(&c, " agent=%s", git_user_agent_sanitized());
packet_buf_write(&req_buf, "want %s%s\n", remote_hex, c.buf);
strbuf_release(&c);
} else
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index 0afb8b2..fbfa128 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -12,6 +12,7 @@
#include "string-list.h"
#include "sha1-array.h"
#include "connected.h"
+#include "version.h"
static const char receive_pack_usage[] = "git receive-pack <git-dir>";
@@ -121,10 +122,11 @@ static void show_ref(const char *path, const unsigned char *sha1)
if (sent_capabilities)
packet_write(1, "%s %s\n", sha1_to_hex(sha1), path);
else
- packet_write(1, "%s %s%c%s%s\n",
+ packet_write(1, "%s %s%c%s%s agent=%s\n",
sha1_to_hex(sha1), path, 0,
" report-status delete-refs side-band-64k quiet",
- prefer_ofs_delta ? " ofs-delta" : "");
+ prefer_ofs_delta ? " ofs-delta" : "",
+ git_user_agent_sanitized());
sent_capabilities = 1;
}
diff --git a/builtin/send-pack.c b/builtin/send-pack.c
index d5d7105..c4d4211 100644
--- a/builtin/send-pack.c
+++ b/builtin/send-pack.c
@@ -8,6 +8,7 @@
#include "send-pack.h"
#include "quote.h"
#include "transport.h"
+#include "version.h"
static const char send_pack_usage[] =
"git send-pack [--all | --mirror] [--dry-run] [--force] [--receive-pack=<git-receive-pack>] [--verbose] [--thin] [<host>:]<directory> [<ref>...]\n"
@@ -306,11 +307,13 @@ int send_pack(struct send_pack_args *args,
int quiet = quiet_supported && (args->quiet || !args->progress);
if (!cmds_sent && (status_report || use_sideband || args->quiet)) {
- packet_buf_write(&req_buf, "%s %s %s%c%s%s%s",
+ packet_buf_write(&req_buf,
+ "%s %s %s%c%s%s%s agent=%s",
old_hex, new_hex, ref->name, 0,
status_report ? " report-status" : "",
use_sideband ? " side-band-64k" : "",
- quiet ? " quiet" : "");
+ quiet ? " quiet" : "",
+ git_user_agent_sanitized());
}
else
packet_buf_write(&req_buf, "%s %s %s",
diff --git a/upload-pack.c b/upload-pack.c
index bb08e2e..2e90ccb 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -11,6 +11,7 @@
#include "list-objects.h"
#include "run-command.h"
#include "sigchain.h"
+#include "version.h"
static const char upload_pack_usage[] = "git upload-pack [--strict] [--timeout=<n>] <dir>";
@@ -734,9 +735,11 @@ static int send_ref(const char *refname, const unsigned char *sha1, int flag, vo
}
if (capabilities)
- packet_write(1, "%s %s%c%s%s\n", sha1_to_hex(sha1), refname_nons,
+ packet_write(1, "%s %s%c%s%s agent=%s\n",
+ sha1_to_hex(sha1), refname_nons,
0, capabilities,
- stateless_rpc ? " no-done" : "");
+ stateless_rpc ? " no-done" : "",
+ git_user_agent_sanitized());
else
packet_write(1, "%s %s\n", sha1_to_hex(sha1), refname_nons);
capabilities = NULL;
diff --git a/version.c b/version.c
index f98d5a6..6106a80 100644
--- a/version.c
+++ b/version.c
@@ -1,5 +1,6 @@
#include "git-compat-util.h"
#include "version.h"
+#include "strbuf.h"
const char git_version_string[] = GIT_VERSION;
@@ -15,3 +16,23 @@ const char *git_user_agent(void)
return agent;
}
+
+const char *git_user_agent_sanitized(void)
+{
+ static const char *agent = NULL;
+
+ if (!agent) {
+ struct strbuf buf = STRBUF_INIT;
+ int i;
+
+ strbuf_addstr(&buf, git_user_agent());
+ strbuf_trim(&buf);
+ for (i = 0; i < buf.len; i++) {
+ if (buf.buf[i] <= 32 || buf.buf[i] >= 127)
+ buf.buf[i] = '.';
+ }
+ agent = buf.buf;
+ }
+
+ return agent;
+}
diff --git a/version.h b/version.h
index fd9cdd6..6911a4f 100644
--- a/version.h
+++ b/version.h
@@ -4,5 +4,6 @@
extern const char git_version_string[];
const char *git_user_agent(void);
+const char *git_user_agent_sanitized(void);
#endif /* VERSION_H */
--
1.7.7.7.32.g4b73117
next prev parent reply other threads:[~2012-06-02 19:05 UTC|newest]
Thread overview: 84+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-31 11:48 git version statistics Jeff King
2012-05-31 12:00 ` Jeff King
2012-05-31 19:35 ` Junio C Hamano
2012-06-01 9:03 ` Jeff King
2012-06-01 14:49 ` Junio C Hamano
2012-06-02 16:32 ` Jeff King
2012-06-02 16:59 ` Tomas Carnecky
2012-06-02 18:49 ` Jeff King
2012-06-02 18:51 ` [PATCH 1/4] move git_version_string into version.c Jeff King
2012-06-02 19:01 ` [PATCH 2/4] version: add git_user_agent function Jeff King
2012-06-19 18:40 ` Thomas Rast
2012-06-19 18:59 ` Jeff King
2012-06-19 19:52 ` Jeff King
2012-06-19 19:52 ` [PATCH 1/3] Makefile: apply dependencies consistently to sparse/asm targets Jeff King
2012-06-19 20:38 ` Junio C Hamano
2012-06-19 20:01 ` [PATCH 2/3] Makefile: split GIT_USER_AGENT from GIT-CFLAGS Jeff King
2012-06-19 20:38 ` Junio C Hamano
2012-06-19 20:03 ` [PATCH 3/3] Makefile: split prefix flags " Jeff King
2012-06-19 20:51 ` Junio C Hamano
2012-06-19 21:04 ` Jeff King
2012-06-19 21:39 ` Junio C Hamano
2012-06-19 23:36 ` Jeff King
2012-06-19 23:58 ` Junio C Hamano
2012-06-19 21:43 ` Jeff King
2012-06-19 23:22 ` [PATCHv2 0/8] makefile cleanups Jeff King
2012-06-19 23:23 ` [PATCHv2 1/8] Makefile: apply dependencies consistently to sparse/asm targets Jeff King
2012-06-20 3:50 ` Jonathan Nieder
2012-06-20 4:26 ` Jeff King
2012-06-20 10:27 ` Jonathan Nieder
2012-06-20 16:37 ` Jeff King
2012-06-20 18:28 ` Jeff King
2012-06-20 18:30 ` [PATCHv3 01/11] Makefile: sort LIB_H list Jeff King
2012-06-20 20:00 ` Junio C Hamano
2012-06-20 20:01 ` Jeff King
2012-06-20 18:30 ` [PATCHv3 02/11] Makefile: fold MISC_H into LIB_H Jeff King
2012-06-20 20:01 ` Junio C Hamano
2012-06-20 21:07 ` Jonathan Nieder
2012-06-20 22:11 ` Jeff King
2012-07-07 3:39 ` [PATCH 02.5/11] Makefile: fold XDIFF_H and VCSSVN_H " Jonathan Nieder
2012-07-09 14:59 ` Junio C Hamano
2012-07-06 22:47 ` [PATCHv3 02/11] Makefile: fold MISC_H " Jonathan Nieder
2012-06-20 18:31 ` [PATCHv3 03/11] Makefile: do not have git.o depend on common-cmds.h Jeff King
2012-06-20 21:09 ` Jonathan Nieder
2012-06-20 18:31 ` [PATCHv3 04/11] Makefile: apply dependencies consistently to sparse/asm targets Jeff King
2012-06-20 21:12 ` Jonathan Nieder
2012-06-20 22:15 ` Jeff King
2012-07-07 4:19 ` [PATCH/RFC] Makefile: document ground rules for target-specific dependencies Jonathan Nieder
2012-06-20 18:31 ` [PATCHv3 05/11] Makefile: do not replace @@GIT_USER_AGENT@@ in scripts Jeff King
2012-06-20 20:06 ` Junio C Hamano
2012-06-20 20:09 ` Jeff King
2012-06-20 18:31 ` [PATCHv3 06/11] Makefile: split GIT_USER_AGENT from GIT-CFLAGS Jeff King
2012-06-20 21:21 ` Jonathan Nieder
2012-06-20 22:16 ` Jeff King
2012-06-20 22:21 ` Jonathan Nieder
2012-07-07 4:42 ` [RFC/PATCH v4 " Jonathan Nieder
2012-06-20 18:31 ` [PATCHv3 07/11] Makefile: split prefix flags " Jeff King
2012-06-20 21:28 ` Jonathan Nieder
2012-06-20 22:22 ` Jeff King
2012-06-20 18:32 ` [PATCHv3 08/11] Makefile: do not replace @@GIT_VERSION@@ in shell scripts Jeff King
2012-06-20 18:32 ` [PATCHv3 09/11] Makefile: update scripts when build-time parameters change Jeff King
2012-06-20 18:32 ` [PATCHv3 10/11] Makefile: build instaweb similar to other scripts Jeff King
2012-06-20 18:32 ` [PATCHv3 11/11] Makefile: move GIT-VERSION-FILE dependencies closer to use Jeff King
2012-06-20 21:31 ` Jonathan Nieder
2012-06-20 19:30 ` [PATCHv2 1/8] Makefile: apply dependencies consistently to sparse/asm targets Jonathan Nieder
2012-06-20 19:36 ` Jeff King
2012-06-20 19:45 ` Jonathan Nieder
2012-06-20 19:57 ` Jeff King
2012-06-20 21:00 ` Jonathan Nieder
2012-06-21 8:52 ` Automatic dependency tracking in the Git build system (was: Re: [PATCHv2 1/8] Makefile: apply dependencies consistently to sparse/asm targets) Stefano Lattarini
2012-06-20 20:10 ` [PATCHv2 1/8] Makefile: apply dependencies consistently to sparse/asm targets Junio C Hamano
2012-06-20 23:00 ` Thomas Rast
2012-06-21 5:18 ` Jeff King
2012-06-21 5:43 ` Junio C Hamano
2012-06-19 23:24 ` [PATCHv2 2/8] Makefile: do not replace @@GIT_USER_AGENT@@ in scripts Jeff King
2012-06-19 23:25 ` [PATCHv2 3/8] Makefile: split GIT_USER_AGENT from GIT-CFLAGS Jeff King
2012-06-19 23:25 ` [PATCHv2 4/8] Makefile: split prefix flags " Jeff King
2012-06-19 23:27 ` [PATCHv2 5/8] Makefile: do not replace @@GIT_VERSION@@ in shell scripts Jeff King
2012-06-19 23:28 ` [PATCHv2 6/8] Makefile: update scripts when build-time parameters change Jeff King
2012-06-19 23:29 ` [PATCHv2 7/8] Makefile: build instaweb similar to other scripts Jeff King
2012-06-19 23:30 ` [PATCHv2 8/8] Makefile: move GIT-VERSION-FILE dependencies closer to use Jeff King
2012-06-02 19:03 ` [PATCH 3/4] http: get default user-agent from git_user_agent Jeff King
2012-06-02 19:05 ` Jeff King [this message]
2012-05-31 15:20 ` git version statistics Stephen Bash
2012-06-01 8:52 ` Jeff King
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20120602190503.GD14369@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).