@@ -7,20 +7,19 @@ import (
7
7
"os"
8
8
"log"
9
9
"strings"
10
- "strconv"
11
10
)
12
11
13
12
type fileInfo struct {
14
13
Name string
14
+ Path string
15
15
Url string
16
16
Size int64
17
17
Level int
18
18
IsDir bool
19
19
Id string
20
20
Extension string
21
21
ModTime int64
22
- ParentName string
23
- ParentId string
22
+ ParentPath string
24
23
Contributions []fileContribution
25
24
CommitCount int
26
25
}
@@ -42,12 +41,6 @@ func initFlags() {
42
41
flag .Parse ()
43
42
}
44
43
45
- // getUniqueNameString creates a unique string for a file based on its nested depth in the folder and its name
46
- // TODO: instead of depth, modified timestamp might be a better value to create unique variable names with
47
- func getUniqueNameString (index int , element string ) string {
48
- return strconv .Itoa (index ) + "-" + element
49
- }
50
-
51
44
// getFileExtension returns the extension for a given file's full name
52
45
func getFileExtension (info os.FileInfo ) string {
53
46
if (info .IsDir () == false ) {
@@ -85,9 +78,10 @@ func main() {
85
78
fileDepth := len (pathSegments ) - 1
86
79
fileName := info .Name ()
87
80
verboseLog ("fileName: " + fileName )
88
- uniqueNameString := getUniqueNameString (fileDepth , fileName )
89
81
90
- if (processedFiles [uniqueNameString ] != true ) {
82
+ if (processedFiles [path ] != true ) {
83
+ parentPath := strings .Join (pathSegments [:len (pathSegments )- 1 ], "/" )
84
+ verboseLog ("parentPath: " + parentPath )
91
85
parentDepth := fileDepth - 1
92
86
if (parentDepth < 0 ) {
93
87
parentDepth = 0
@@ -97,19 +91,19 @@ func main() {
97
91
98
92
nodes = append (nodes , fileInfo {
99
93
Name : fileName ,
94
+ Path : path ,
100
95
Url : buildGitHubUrl (gitRepoUrl , path , info .IsDir ()),
101
96
Size : info .Size (),
102
97
Level : fileDepth ,
103
98
Extension : getFileExtension (info ),
104
- Id : createCypherFriendlyVarName (fileName , fileDepth ),
99
+ Id : createCypherFriendlyVarName (path , fileDepth ),
105
100
IsDir : info .IsDir (),
106
101
ModTime : info .ModTime ().Unix (),
107
- ParentName : pathSegments [parentDepth ],
108
- ParentId : createCypherFriendlyVarName (pathSegments [parentDepth ], parentDepth ),
102
+ ParentPath : parentPath ,
109
103
Contributions : contributions ,
110
104
CommitCount : len (contributions ),
111
105
})
112
- processedFiles [uniqueNameString ] = true
106
+ processedFiles [path ] = true
113
107
}
114
108
}
115
109
@@ -126,9 +120,9 @@ func main() {
126
120
fmt .Println (":BEGIN" )
127
121
label := getLabelForFileNode (currentFile )
128
122
129
- if (! processedNodes [currentFile .Id ]) {
123
+ if (! processedNodes [currentFile .Path ]) {
130
124
fmt .Println (fileInfoToCypher (currentFile , label ))
131
- processedNodes [currentFile .Id ] = true
125
+ processedNodes [currentFile .Path ] = true
132
126
}
133
127
134
128
if (label == "file" ) {
@@ -157,7 +151,7 @@ func main() {
157
151
fmt .Println (";" )
158
152
fmt .Println (":COMMIT" )
159
153
160
- if (currentFile .Id != currentFile . ParentId ) {
154
+ if (len ( currentFile .ParentPath ) > 0 ) {
161
155
fmt .Println (":BEGIN" )
162
156
fmt .Println (folderStructureToCypher (currentFile ))
163
157
fmt .Println (";" )
0 commit comments