From: Mike Hommey <hidden> Date: 2016-06-16 02:19:03
As you may be aware, I'm working on a git remote helper to access
mercurial repositories (https://github.com/glandium/git-cinnabar/).
At the moment, a small part is written in C, relying on the git code
base, but eventually, there would be more C.
As I want to get rid of the dependency on Mercurial itself, I'm planning
to implement the wire protocol parts in git-cinnabar. And while at it, I
figured I'd evaluate if I can't just rely on some git internals, from C
code. So I've turned to the git_connect function, that implements the
niceties around GIT_SSH and GIT_SSH_COMMAND, and also handles ssh client
specificities. (I'd rather not have to copy the code or reimplement it).
It also turns out to be a convenient wrapper around start_command() for
local urls.
The git commands that git_connect is invoked for all take the repository
path as their last argument. In mercurial's case, the command is:
hg -R $path serve --stdio
which doesn't match that pattern. So one hack I was thinking about was
scan the url on my end, extract the path, replace it with "--stdio",
and pass "hg -R $path serve" as command. Unfortunately, parse_connect_url
is static, which means I'd either have to change connect.c to expose it,
or copy it. Since I'd rather avoid copying code, I figured that since I
was going to have to change connect.c, I might as well go with something
less hacky, assuming it's accepted mainline.
So following here are four patches that allow me to connect, via ssh, to
hg.mozilla.org, and access mercurial repositories there using:
git_connect(fd, url, "hg -R %s serve --stdio",
CONNECT_RELATIVE_SSH | CONNECT_WANT_STDERR)
And this works for local urls too, invoking `hg serve` locally.
Note that what the second patch does could be done in sq_quote_buf
instead, arguably.
I'm certainly open to any better ideas as long as they can make it to
mainline :).
Mike Hommey (4):
git_connect: extend to take a pseudo format string for the program to
run
git_connect: avoid quoting the path on the command line when it's not
necessary
git_connect: allow a file descriptor to be allocated for stderr
git_connect: add a flag to consider the path part of ssh urls relative
connect.c | 52 ++++++++++++++++++++++++++++++++++++++++++++--------
connect.h | 2 ++
2 files changed, 46 insertions(+), 8 deletions(-)
--
2.8.1.5.g18c8a48
From: Mike Hommey <hidden> Date: 2016-06-16 02:19:03
Currently, the path extracted from the url is passed as last argument to
the program/command passed to git_connect(). In every case the function
is used in the git code base, it's enough, but in order to allow the
reuse of e.g. the GIT_SSH/GIT_SSH_COMMAND logic, additional flexibility
is welcome.
With this change, when the program/command passed to git_connect()
contains a "%s", that "%s" is replaced with the path from the url,
allowing the path to be at a different position than last on the
executed command line.
Signed-off-by: Mike Hommey <redacted>
---
connect.c | 29 ++++++++++++++++++++++++-----
1 file changed, 24 insertions(+), 5 deletions(-)
From: Mike Hommey <hidden> Date: 2016-06-16 02:19:03
In Mercurial ssh urls, the path part of the url is relative to the home
directory of the account being logged to instead of being absolute.
Add a flag allowing git_connect() to handle this kind of usecase.
Signed-off-by: Mike Hommey <redacted>
---
connect.c | 10 +++++++---
connect.h | 1 +
2 files changed, 8 insertions(+), 3 deletions(-)
From: Mike Hommey <hidden> Date: 2016-06-16 02:19:03
Some remote systems can employ restricted shells that aren't very smart
with quotes, so avoid quoting when it's not strictly necessary.
The list of "safe" characters comes from Mercurial's shell quoting
function used for its ssh client side. There likely are more that could
be added to the list.
Signed-off-by: Mike Hommey <redacted>
---
connect.c | 11 +++++++++++
1 file changed, 11 insertions(+)
From: Mike Hommey <hidden> Date: 2016-06-16 02:19:03
It can be useful to the caller of git_connect() to get access to stderr,
so add a flag that makes start_command allocate a file descriptor for
it.
Signed-off-by: Mike Hommey <redacted>
---
connect.c | 2 ++
connect.h | 1 +
2 files changed, 3 insertions(+)
From: Stefan Beller <hidden> Date: 2016-06-16 02:19:03
On Thu, Apr 28, 2016 at 7:12 AM, Mike Hommey [off-list ref] wrote:
Some remote systems can employ restricted shells that aren't very smart
with quotes, so avoid quoting when it's not strictly necessary.
The list of "safe" characters comes from Mercurial's shell quoting
function used for its ssh client side. There likely are more that could
be added to the list.
Would it make sense to move the new code into its own function and
document it with this paragraph of the commit message, i.e. hinting
at Mercurial safe characters or others?
2.8.1.5.g18c8a48
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html