trimPath cleans up a path by removing prefixes that are commonly found on profiles plus configured prefixes. TODO(aalexand): Consider optimizing out the redundant work done in this function if it proves to matter.
(path, trimPath, searchPath string)
| 1034 | // TODO(aalexand): Consider optimizing out the redundant work done in this |
| 1035 | // function if it proves to matter. |
| 1036 | func trimPath(path, trimPath, searchPath string) string { |
| 1037 | // Keep path variable intact as it's used below to form the return value. |
| 1038 | sPath, searchPath := filepath.ToSlash(path), filepath.ToSlash(searchPath) |
| 1039 | if trimPath == "" { |
| 1040 | // If the trim path is not configured, try to guess it heuristically: |
| 1041 | // search for basename of each search path in the original path and, if |
| 1042 | // found, strip everything up to and including the basename. So, for |
| 1043 | // example, given original path "/some/remote/path/my-project/foo/bar.c" |
| 1044 | // and search path "/my/local/path/my-project" the heuristic will return |
| 1045 | // "/my/local/path/my-project/foo/bar.c". |
| 1046 | for _, dir := range filepath.SplitList(searchPath) { |
| 1047 | want := "/" + filepath.Base(dir) + "/" |
| 1048 | if found := strings.Index(sPath, want); found != -1 { |
| 1049 | return path[found+len(want):] |
| 1050 | } |
| 1051 | } |
| 1052 | } |
| 1053 | // Trim configured trim prefixes. |
| 1054 | trimPaths := append(filepath.SplitList(filepath.ToSlash(trimPath)), "/proc/self/cwd/./", "/proc/self/cwd/") |
| 1055 | for _, trimPath := range trimPaths { |
| 1056 | if !strings.HasSuffix(trimPath, "/") { |
| 1057 | trimPath += "/" |
| 1058 | } |
| 1059 | if strings.HasPrefix(sPath, trimPath) { |
| 1060 | return path[len(trimPath):] |
| 1061 | } |
| 1062 | } |
| 1063 | return path |
| 1064 | } |
| 1065 | |
| 1066 | func indentation(line string) int { |
| 1067 | column := 0 |
no outgoing calls
no test coverage detected
searching dependent graphs…