@@ -37,59 +37,67 @@ githist <- function (path, n = NULL, step_size = 1L, num_cores = -1L) {
37
37
38
38
num_cores <- set_num_cores (num_cores )
39
39
40
- path_cp <- fs :: path (fs :: path_temp (), basename (path ))
41
- clean_after <- FALSE
42
- if (fs :: path (fs :: path_dir (path )) != fs :: path_temp () &&
43
- ! fs :: dir_exists (path_cp )) {
44
- path_cp <- fs :: dir_copy (path , fs :: path_temp ())
45
- clean_after <- TRUE
46
- }
47
-
48
- h <- gert :: git_log (repo = path_cp , max = 1e6 )
40
+ h <- gert :: git_log (repo = path , max = 1e6 )
49
41
if (step_size > 1L ) {
50
42
h <- h [seq (1 , nrow (h ), by = step_size ), ]
51
43
}
52
44
if (! is.null (n )) {
53
45
h <- h [seq_len (n ), ]
54
46
}
55
47
56
- res <- extract_pkgstats_data (h , path_cp , num_cores )
48
+ if (num_cores == 1L ) {
49
+
50
+ res <- extract_pkgstats_data_single (h , path )
51
+
52
+ } else {
53
+
54
+ res <- extract_pkgstats_data_multi (h , path , num_cores )
57
55
58
- if (clean_after ) {
59
- fs :: dir_delete (path_cp )
60
56
}
61
57
62
58
collate_pkgstats (res )
63
59
}
64
60
65
- extract_pkgstats_data <- function (log , path , num_cores ) {
61
+ extract_pkgstats_data_single <- function (log , path ) {
66
62
67
- if (num_cores == 1L ) {
68
-
69
- res <- pbapply :: pblapply (seq_len (nrow (log )), function (i ) {
70
- g <- gert :: git_reset_hard (ref = log $ commit [i ], repo = path )
71
- run_one_pkgstats (path = path , pkg_date = log $ time [i ])
72
- })
63
+ path_cp <- fs :: path (fs :: path_temp (), basename (path ))
64
+ clean_after <- FALSE
65
+ if (fs :: path (fs :: path_dir (path )) != fs :: path_temp () &&
66
+ ! fs :: dir_exists (path_cp )) {
67
+ path_cp <- fs :: dir_copy (path , fs :: path_temp ())
68
+ clean_after <- TRUE
69
+ }
73
70
74
- } else {
71
+ res <- pbapply :: pblapply (seq_len (nrow (log )), function (i ) {
72
+ g <- gert :: git_reset_hard (ref = log $ commit [i ], repo = path_cp )
73
+ run_one_pkgstats (path = path_cp , pkg_date = log $ time [i ])
74
+ })
75
75
76
- cl <- parallel :: makeCluster (num_cores )
77
- parallel :: clusterExport (cl , c (" log" , " path" , " run_one_pkgstats" ))
78
- res <- pbapply :: pblapply (seq_len (nrow (log )), function (i ) {
79
- path_cp <- fs :: dir_copy (path , fs :: path_temp ())
80
- g <- gert :: git_reset_hard (ref = log $ commit [i ], repo = path_cp )
81
- s <- run_one_pkgstats (path = path_cp , pkg_date = log $ time [i ])
82
- fs :: dir_delete (path_cp )
83
- return (s )
84
- }, cl = cl )
85
- parallel :: stopCluster (cl )
86
-
87
- return (res )
76
+ if (clean_after ) {
77
+ fs :: dir_delete (path_cp )
88
78
}
89
79
90
80
return (res )
91
81
}
92
82
83
+ extract_pkgstats_data_multi <- function (log , path , num_cores ) {
84
+
85
+ cl <- parallel :: makeCluster (num_cores )
86
+ parallel :: clusterExport (cl , c (" log" , " path" , " run_one_pkgstats" ))
87
+ res <- pbapply :: pblapply (seq_len (nrow (log )), function (i ) {
88
+ path_cp <- fs :: dir_copy (path , fs :: path_temp ())
89
+ g <- gert :: git_reset_hard (ref = log $ commit [i ], repo = path_cp )
90
+ s <- run_one_pkgstats (path = path_cp , pkg_date = log $ time [i ])
91
+ fs :: dir_delete (path_cp )
92
+ return (s )
93
+ }, cl = cl )
94
+ parallel :: stopCluster (cl )
95
+
96
+ return (res )
97
+
98
+ return (res )
99
+ }
100
+
93
101
collate_pkgstats <- function (x ) {
94
102
nms <- names (x [[1 ]])
95
103
nms2df <- nms [seq_len (which (nms == " loc" ) - 1L )]
0 commit comments