Commit 36da74e6 authored by Kirill Smelkov's avatar Kirill Smelkov

error/mypkgname: Fix for a package living under dotted prefix

In 28986e0e (Rewrite in Go) I've added mypkgname() with comment that go
escapes all '.' in function name with %2e. That turned out to be not
true: Go escapes only dots in last component after last slash, e.g.

    lab.nexedi.com/kirr/git-backup/package%2ename.Function
    lab.nexedi.com/kirr/git-backup/pkg2.qqq/name%2ezzz.Function

Correct mypkgname() accordingly.

Noted while trying to run git-backup in a GOPATH root, not as
standalone.
parent 302aaaea
...@@ -156,13 +156,18 @@ func mypkgname() string { ...@@ -156,13 +156,18 @@ func mypkgname() string {
if myfunc == "" { if myfunc == "" {
return "" return ""
} }
// NOTE dots in package name are escaped by go as %2e // NOTE dots in package name are after last slash are escaped by go as %2e
// this way the first dot is delimiter between package and function // this way the first '.' after last '/' is delimiter between package and function
idot := strings.IndexByte(myfunc, '.') //
// lab.nexedi.com/kirr/git-backup/package%2ename.Function
// lab.nexedi.com/kirr/git-backup/pkg2.qqq/name%2ezzz.Function
islash := strings.LastIndexByte(myfunc, '/')
iafterslash := islash + 1 // NOTE if '/' not found iafterslash = 0
idot := strings.IndexByte(myfunc[iafterslash:], '.')
if idot == -1 { if idot == -1 {
panic(fmt.Errorf("funcname %q is not fully qualified", myfunc)) panic(fmt.Errorf("funcname %q is not fully qualified", myfunc))
} }
return myfunc[:idot] return myfunc[:iafterslash+idot]
} }
// TODO(go1.7) goes away in favour of runtime.Frame // TODO(go1.7) goes away in favour of runtime.Frame
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment