absolute and relative paths with ssh

Stefan van der Walt stefan at sun.ac.za
Sun Sep 18 02:12:51 CDT 2005


On Fri, Sep 16, 2005 at 02:54:37PM -0700, Bryan O'Sullivan wrote:
> On Fri, 2005-09-16 at 23:48 +0200, Zbynek Winkler wrote:
> > But still - am I the only one who thinks that it is "strange" when
> >     ssh://user@example.com/~/hg/
> > means the same thing as
> >     ssh://user@example.com/hg/
> > ???
> 
> Perhaps not, but it fits with my mental model of how I expect ssh to
> work.

While it might look a bit weird, this behaviour is correct.  The "~"
symbol expands to "/home/user", therefore

ssh://user@example.com/~/hg

becomes

ssh://user@example.com//home/user/hg

The relevant part of the RFC is on p. 22:

   If a URI contains an authority component, then the path component
   must either be empty or begin with a slash ("/") character.  If a URI
   does not contain an authority component, then the path cannot begin
   with two slash characters ("//").  In addition, a URI reference
   (Section 4.1) may be a relative-path reference, in which case the
   first path segment cannot contain a colon (":") character.  The ABNF
   requires five separate rules to disambiguate these cases, only one of
   which will match the path substring within a given URI reference.  We
   use the generic term "path component" to describe the URI substring
   matched by the parser to one of these rules.

      path          = path-abempty    ; begins with "/" or is empty
                    / path-absolute   ; begins with "/" but not "//"
                    / path-noscheme   ; begins with a non-colon segment
                    / path-rootless   ; begins with a segment
                    / path-empty      ; zero characters

      path-abempty  = *( "/" segment )
      path-absolute = "/" [ segment-nz *( "/" segment ) ]
      path-noscheme = segment-nz-nc *( "/" segment )
      path-rootless = segment-nz *( "/" segment )
      path-empty    = 0<pchar>

Regards
Stéfan


More information about the Mercurial mailing list