{"thread":{"id":"45182","subject":"Sending informational messages from upload-pack","startedAt":"2017-02-20T18:38:20Z","lastAt":"2017-02-21T06:00:12Z","messageCount":3,"participants":["Lukas Fleischer","Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"312157","messageId":"148761588216.31363.15518967793189077139@typhoon","threadId":"45182","inReplyTo":null,"subject":"Sending informational messages from upload-pack","fromName":"Lukas Fleischer","fromEmail":"lfleischer@lfos.de","sentAt":"2017-02-20T18:38:02Z","receivedAt":"2017-02-20T18:38:20Z","isPatch":false,"sender":{"key":"lfleischer@lfos.de","avatar":"https://avatars.githubusercontent.com/u/5530842?v=4"},"body":"Hi,\n\nIt would be handy to be able to show a message to the user when\ncloning/fetching from a repository (e.g. to show a warning if a\nrepository is deprecated). This should technically already be possible\nusing the current pack protocol and sidebands. However, to my knowledge,\nthere is no easy way to configure this on the server side; writing a\nwrapper around git-upload-pack(1) or replacing git-upload-pack(1) seem\nto be the only options.\n\nWhat I have in mind is something like a post-upload hook whose stdout\nand stderr are redirected to sideband 2 and 3, respectively. The commit\nmessage of 20b20a22f (upload-pack: provide a hook for running\npack-objects, 2016-05-18) suggests that such a hook should be\nimplemented as a \"config variable hook\" rather than a regular hook.\n\nOne could think of additional parameters passed to such a hook. For the\npurposes I intend to use this, no parameters are needed. However, a\nfixed per-repository MOTD would be too inflexible since we are using\nnamespaces and database accesses to determine whether a repository is\n\"deprecated\".\n\nAm I missing any \"easy\" already supported way to add such messages\nwithout patching Git or writing a git-upload-pack(1) wrapper? If not,\ndoes this sound general and useful enough to become an official feature?\nAre there any alternative suggestions on how to display such messages?\n\nRegards,\nLukas\n"},{"id":"312158","messageId":"20170220192103.6v66lpghgir3erhn@sigill.intra.peff.net","threadId":"45182","inReplyTo":"148761588216.31363.15518967793189077139@typhoon","subject":"Re: Sending informational messages from upload-pack","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2017-02-20T19:21:03Z","receivedAt":"2017-02-20T19:21:11Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Mon, Feb 20, 2017 at 07:38:02PM +0100, Lukas Fleischer wrote:\n\n> It would be handy to be able to show a message to the user when\n> cloning/fetching from a repository (e.g. to show a warning if a\n> repository is deprecated). This should technically already be possible\n> using the current pack protocol and sidebands. However, to my knowledge,\n> there is no easy way to configure this on the server side; writing a\n> wrapper around git-upload-pack(1) or replacing git-upload-pack(1) seem\n> to be the only options.\n\nI wouldn't recommend wrapping upload-pack. You don't know you have a\nsideband until partway through the upload-pack conversation. And clients\ndo not expect sideband at all until we get to the pack-sending part of\nthe protocol (I think; I just quickly verified the location of the\ndemuxer async code in fetch-pack.c, but I didn't dig into it in depth).\n\nSo I don't think you can do a MOTD or similar in a backwards-compatible\nway. You're only allowed to talk if the conversation results in an\nactual pack being sent.\n\n> What I have in mind is something like a post-upload hook whose stdout\n> and stderr are redirected to sideband 2 and 3, respectively. The commit\n> message of 20b20a22f (upload-pack: provide a hook for running\n> pack-objects, 2016-05-18) suggests that such a hook should be\n> implemented as a \"config variable hook\" rather than a regular hook.\n\nYeah, because of the \"upload-pack is special and untrusted\" rule, this\ncan't be a regular hook. I think the config mechanism used by 20b20a22f\nwould be the right approach.\n\nIf my fetch-pack assertion above is right, technically the hook added by\n20b20a22f is sufficient for your purposes, if your hook looks like:\n\n  echo >&2 \"pre-pack message\"\n  git pack-objects \"$@\"\n  echo >72 \"post-pack message\"\n\nbut I would not be opposed to having pre-/post- hooks that run\nseparately, if only for the convenience of the admin.\n\n> One could think of additional parameters passed to such a hook. For the\n> purposes I intend to use this, no parameters are needed. However, a\n> fixed per-repository MOTD would be too inflexible since we are using\n> namespaces and database accesses to determine whether a repository is\n> \"deprecated\".\n\nThere was a proposed post-upload-pack hook a long time ago that\ncollected clone/fetch stats, and we used it at GitHub for many years.\nThese days we use something much more invasive that dumps stats from\nevery git invocation over a Unix socket.\n\n> Am I missing any \"easy\" already supported way to add such messages\n> without patching Git or writing a git-upload-pack(1) wrapper? If not,\n> does this sound general and useful enough to become an official feature?\n> Are there any alternative suggestions on how to display such messages?\n\nI don't think there's any other mechanism to do what you're asking,\naside from the hook in 20b20a22f.\n\n-Peff\n"},{"id":"312187","messageId":"148765676392.7729.13179395516270132623@typhoon","threadId":"45182","inReplyTo":"20170220192103.6v66lpghgir3erhn@sigill.intra.peff.net","subject":"Re: Sending informational messages from upload-pack","fromName":"Lukas Fleischer","fromEmail":"lfleischer@lfos.de","sentAt":"2017-02-21T05:59:23Z","receivedAt":"2017-02-21T06:00:12Z","isPatch":false,"sender":{"key":"lfleischer@lfos.de","avatar":"https://avatars.githubusercontent.com/u/5530842?v=4"},"body":"On Mon, 20 Feb 2017 at 20:21:03, Jeff King wrote:\n> On Mon, Feb 20, 2017 at 07:38:02PM +0100, Lukas Fleischer wrote:\n> \n> > It would be handy to be able to show a message to the user when\n> > cloning/fetching from a repository (e.g. to show a warning if a\n> > repository is deprecated). This should technically already be possible\n> > using the current pack protocol and sidebands. However, to my knowledge,\n> > there is no easy way to configure this on the server side; writing a\n> > wrapper around git-upload-pack(1) or replacing git-upload-pack(1) seem\n> > to be the only options.\n> \n> I wouldn't recommend wrapping upload-pack. You don't know you have a\n> sideband until partway through the upload-pack conversation. And clients\n> do not expect sideband at all until we get to the pack-sending part of\n> the protocol (I think; I just quickly verified the location of the\n> demuxer async code in fetch-pack.c, but I didn't dig into it in depth).\n\nBy wrapper I meant something that understands the pack protocol itself,\nintercepts the traffic, forwards most of it to git-upload-pack(1) and\ninjects the message at the right time. I agree that it is a fairly ugly\nworkaround, though.\n\n> [...]\n> If my fetch-pack assertion above is right, technically the hook added by\n> 20b20a22f is sufficient for your purposes, if your hook looks like:\n> \n>   echo >&2 \"pre-pack message\"\n>   git pack-objects \"$@\"\n>   echo >72 \"post-pack message\"\n> \n> but I would not be opposed to having pre-/post- hooks that run\n> separately, if only for the convenience of the admin.\n> [...]\n\nI will give it a try. And I agree that it would still be convenient to\nhave pre-upload-pack and post-upload-pack hooks.\n\nRegards,\nLukas\n"}]}