Skip to content

Commit bcc5049

Browse files
committed
Merge remote-tracking branch 'upstream/master' into parallelize
2 parents 99d58d3 + 6cb270f commit bcc5049

File tree

8 files changed

+96
-46
lines changed

8 files changed

+96
-46
lines changed

.gitignore

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ npm-debug.log
33

44
node_modules/
55
assets/
6-
repos/
7-
gitlogg.json
8-
gitlogg.tmp
6+
_repos/
7+
_output/
8+
_tmp/

README.md

Lines changed: 57 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
![Error 002](https://raw.githubusercontent.com/dreamyguy/gitlogg/master/docs/error-002.png "'Error 002' message as on release v0.1.3")
2929
> **Øh nøes!** The path to the folder containing all repositories *exists, but is empty!*
3030
31-
![Success!](https://raw.githubusercontent.com/dreamyguy/gitlogg/master/docs/success.png "Success messages as on release v0.1.3")
31+
![Success!](https://raw.githubusercontent.com/dreamyguy/gitlogg/master/docs/success.png "Success messages as on release v0.1.6")
3232
> **Success!** `JSON` parsed, based on **9** different repositories with a total of **25,537** commits.
3333
3434
Note that I've included two huge repos _(*react* & *react-native*, that have 7,813 & 10,065 commits respectively at the time of this writting)_ for the sake of demonstration. The resulting parsed `JSON` file has 715,040 lines. All that done in less than 25 seconds.
@@ -41,13 +41,17 @@ _I have successfully compiled **`470`** repositories at once_ (all repos under t
4141
* Commits processed: `118,117`
4242
* Parsed `JSON` file, lines: `3,307,280`
4343

44-
## Requirementss
44+
## Getting started
4545

46-
[NodeJS][2] and [BabelJS][3].
46+
**Gitlogg** requires [NodeJS][2] and [BabelJS][3].
4747

4848
1. Install `NodeJS` (visit [their page][2] to find the right install for your system).
49-
2. Install `BabelJS` globally by running `npm install babel-cli -g`. One can also choose to install it locally by simply running `npm install babel-cli`, but in most cases it is smarter to install `-cli` packages globally.
50-
3. Run `npm install` to install the remaining dependencies.
49+
2. Run `npm run setup`. That will:
50+
51+
* Install `BabelJS` globally by running `npm install babel-cli -g`.
52+
* Install all the local dependencies, through `npm install`.
53+
* Create the directory in which all repos to be parsed to `JSON` will be at (only on **Simple Mode**).
54+
* Create the directories expected by the scripts that output files.
5155

5256
## The `JSON` output
5357

@@ -152,56 +156,68 @@ There are two modes and they are basically the same, except that the **Simple Mo
152156

153157
To simplify the generation process to a point that no configuration is required, follow this directory structure:
154158

155-
.
156-
├── gitlogg
159+
gitlogg/ <== This repository's root
160+
├── scripts/
157161
│   ├── gitlogg-generate-log.sh
158162
│   ├── gitlogg-parse-json.js
159163
│   └── gitlogg.sh
160-
└── repos <== place/keep your repositories under the folder "repos"
164+
└── _repos/ <== Copy/place/keep your repositories under the folder "_repos/"
161165
├── repo1
162166
├── repo2
163167
├── repo3
164168
└── repo4
165169

166-
1. Copy the `gitlogg` folder and all its content to the indicated relative path to your local repositories (shown above).
167-
168-
2. Navigate to the `gitlogg` directory:
170+
1. Copy the all the repositories you wish to parse to `JSON` to the `_repos/` folder, as shown above.
169171

170-
$ cd path/to/the/folder/in/your/system/gitlogg/
172+
2. Granted that you are within the `gitlogg` folder (this repo's root), run:
171173

172-
3. Run it:
173-
174-
$ ./gitlogg.sh
174+
$ npm run gitlogg
175175

176176
#### Advanced Mode
177177

178178
To generate the `JSON` file based on repositories in any other location, you'll have to define the path to the folder that contains all your repositories.
179179

180-
1. Copy the `gitlogg` folder and all its content to a folder of your preference, it really doesn't matter where it is.
181-
182-
2. Open [`gitlogg-generate-log.sh`](https://github.com/dreamyguy/gitlogg/blob/master/gitlogg/gitlogg-generate-log.sh#L17) with an editor of your choice and edit the `yourpath` variable:
180+
1. Open [`gitlogg-generate-log.sh`](https://github.com/dreamyguy/gitlogg/blob/master/scripts/gitlogg-generate-log.sh#L4) with an editor of your choice and edit the `yourpath` variable:
183181

184182
# define the absolute path to the directory that contains all your repositories
185-
yourpath=~/path/to/directory/that/contains/all/your/repositories/
183+
yourpath=/absolute/system/path/to/directory/that/contains/all/your/repositories/
186184

187-
3. Navigate to the `gitlogg` directory:
185+
_**Tip:** drag the folder that contain your repositories to a terminal window, and you'll get the absolute system path to that folder._
188186

189-
$ cd path/to/the/folder/in/your/system/gitlogg/
187+
2. Granted that you are within the `gitlogg` folder (this repo's root), run:
190188

191-
4. Run it:
192-
193-
$ ./gitlogg.sh
189+
$ npm run gitlogg
194190

195191
## The parsed `JSON` file
196192

197-
> _Two files will be generated at the `gitlogg` folder: `gitlogg.tmp` and `gitlogg.json`._
193+
> Two files will be generated when running `npm run gitlogg`: **`_tmp/gitlogg.tmp`** and **`_output/gitlogg.json`**.
194+
195+
gitlogg/ <== This repository's root
196+
├── scripts/
197+
│   ├── gitlogg-generate-log.sh
198+
│   ├── gitlogg-parse-json.js
199+
│   └── gitlogg.sh
200+
├── _output/
201+
│   └── gitlogg.json <== The parsed 'JSON', what we're all after. It's parsed from 'gitlogg.tmp'
202+
└── _tmp/
203+
└── gitlogg.tmp <== The processed 'git log'
198204

199205
Two files were necessary because of the nature of the script, that loops through all subdirectories and outputs the `git log` for all valid `git` repositories. Once that loop is done, a valid `JSON` file (`gitlogg.json`) is generated out of `gitlogg.tmp`.
200206

201207
`gitlogg.tmp` is just a temporary file from which `gitlogg.json` bases itself on. In case the parsing fails `gitlogg.tmp` can come in handy for debugging.
202208

203209
## Further Notes
204210

211+
#### Debugging
212+
213+
I've created error messages with suggested solutions, to help you get past the most common issues.
214+
215+
However, `git log`'s output can break while it's being processed. That's most certainly caused by fields that allow user input, like _commit messages_. These fields may contain characters (like `\r`) that crash with those reserved for the generation of `gitlogg.tmp`, namely `\n`.
216+
217+
Efforts have been made to mitigate errors by sanitizing characters that have caused errors before, but it might still happen in some edge cases. If it does happen, have a look at the generated `gitlogg.tmp` and see if the expected structure (which is obvious) breaks. Once you have identified the line, have a closer look at the commit and look for an unusual character.
218+
219+
Post an issue with a link to a _gist_ containing your broken `gitlogg.tmp` and I will try to reproduce the error.
220+
205221
#### Documentation
206222

207223
Documentation is done either by:
@@ -227,22 +243,32 @@ It's certainly not harmful to your repositories and it won't change any data in
227243

228244
#### Release History
229245

230-
* 2016-11-19 [v0.1.6](https://github.com/dreamyguy/gitlogg/tree/v0.1.6)
246+
* 2016-11-21 [v0.1.7](https://github.com/dreamyguy/gitlogg/tree/v0.1.7) - [View Changes](https://github.com/dreamyguy/gitlogg/compare/v0.1.6...v0.1.7)
247+
* Better readability for 'Release History'
248+
* Correct url to logo, so it also renders outside Github
249+
* Rename sub-folder 'gitlogg' to 'scripts' to avoid confusion
250+
* Simplify initial setup and running of 'gitlogg'
251+
* Set vars instead of hardcoding values
252+
* Separate scripts from output files
253+
* Introduce 'Debugging' as a 'Further Notes' item
254+
* Tip on how to get the absolute system path to a directory
255+
* Introduce 'View Changes' links under 'Release History'
256+
* 2016-11-19 [v0.1.6](https://github.com/dreamyguy/gitlogg/tree/v0.1.6) - [View Changes](https://github.com/dreamyguy/gitlogg/compare/v0.1.5...v0.1.6)
231257
* Introduce `commit_nr`, a commit count within each repo
232258
* Show how many repos are about to be processed on console
233259
* Show what repo is being processed on console
234260
* Replace carriage return with space
235-
* 2016-06-12 [v0.1.5](https://github.com/dreamyguy/gitlogg/tree/v0.1.5)
261+
* 2016-06-12 [v0.1.5](https://github.com/dreamyguy/gitlogg/tree/v0.1.5) - [View Changes](https://github.com/dreamyguy/gitlogg/compare/v0.1.4...v0.1.5)
236262
* Introduce logo
237263
* Correct wrong reference to 'yourpath'
238264
* Output numbers instead of strings
239-
* 2016-05-23 [v0.1.4](https://github.com/dreamyguy/gitlogg/tree/v0.1.4)
265+
* 2016-05-23 [v0.1.4](https://github.com/dreamyguy/gitlogg/tree/v0.1.4) - [View Changes](https://github.com/dreamyguy/gitlogg/compare/v0.1.3...v0.1.4)
240266
* Fix a bug that would break the output in some rare cases
241-
* 2016-05-21 [v0.1.3](https://github.com/dreamyguy/gitlogg/tree/v0.1.3)
267+
* 2016-05-21 [v0.1.3](https://github.com/dreamyguy/gitlogg/tree/v0.1.3) - [View Changes](https://github.com/dreamyguy/gitlogg/compare/v0.1.2...v0.1.3)
242268
* Even better error handling
243-
* 2016-05-21 [v0.1.2](https://github.com/dreamyguy/gitlogg/tree/v0.1.2)
269+
* 2016-05-21 [v0.1.2](https://github.com/dreamyguy/gitlogg/tree/v0.1.2) - [View Changes](https://github.com/dreamyguy/gitlogg/compare/v0.1.1...v0.1.2)
244270
* Better error handling
245-
* 2016-05-21 [v0.1.1](https://github.com/dreamyguy/gitlogg/tree/v0.1.1)
271+
* 2016-05-21 [v0.1.1](https://github.com/dreamyguy/gitlogg/tree/v0.1.1) - [View Changes](https://github.com/dreamyguy/gitlogg/compare/v0.1.0...v0.1.1)
246272
* The 'gitlogg' release, the node-based JSON generation
247273
* 2016-05-20 [v0.1.0](https://github.com/dreamyguy/gitlogg/tree/v0.1.0)
248274
* The 'git-log-to-json' release, now considered legacy

package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "gitlogg",
3-
"version": "0.1.6",
3+
"version": "0.1.7",
44
"description": "Parse the 'git log' of one or several 'git' repositories into a sanitised and distributable 'JSON' file",
55
"keywords": [
66
"gitlog",
@@ -26,7 +26,11 @@
2626
"babel-preset-es2015": "^6.9.0",
2727
"chalk": "^1.1.3"
2828
},
29+
"scripts": {
30+
"setup": "npm install babel-cli -g && npm install && mkdir -p _output && mkdir -p _repos && mkdir -p _tmp",
31+
"gitlogg": "./scripts/gitlogg.sh"
32+
},
2933
"engines": {
30-
"node": ">=4.0.3"
34+
"node": ">=4.3.0"
3135
}
3236
}
File renamed without changes.

gitlogg/gitlogg-generate-log.sh renamed to scripts/gitlogg-generate-log.sh

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,26 @@
11
#!/bin/bash
22

3+
my_dir="$(dirname "$0")"
4+
cd $my_dir
5+
36
source "colors.sh"
47

8+
cd ..
9+
pwd
10+
11+
# define the absolute path to the directory that contains all your repositories.
12+
yourpath='./_repos/'
13+
14+
# define temporary 'git log' output file that will be parsed to 'json'
15+
tempOutputFile='_tmp/gitlogg.tmp'
16+
17+
# name and path to this very script, for output message purposes
18+
thisFile='./scripts/gitlogg-generate-log.sh'
19+
20+
# define path to 'json' parser
21+
jsonParser='./scripts/gitlogg-parse-json.js'
22+
23+
524
# Display system usage and exit
625
usage()
726
{
@@ -22,9 +41,6 @@ test $NUM_THREADS -lt 1 && NUM_THREADS=1
2241
test "$1" = "-n" && NUM_THREADS=$2
2342
echo -e "${Blu}Info: Calculating in $NUM_THREADS thread(s)${RCol}"
2443

25-
# define the absolute path to the directory that contains all your repositories.
26-
yourpath=../repos/
27-
2844
# ensure there's always a '/' at the end of the 'yourpath' variable, since its value can be changed by user.
2945
case "$yourpath" in
3046
*/)
@@ -67,15 +83,15 @@ SECONDS=0
6783
if [ -d "${yourpathSanitized}" ] && [ "$(ls $yourpathSanitized)" ]; then
6884
echo -e "${Yel}Generating ${Pur}git log ${Yel}for ${reporef} located at ${Red}'${thepath}'${Yel}. ${Blu}This might take a while!${RCol}"
6985
dirs=$(ls -d $thepath)
70-
echo $dirs | xargs -n 1 -P $NUM_THREADS ./output-intermediate-gitlog.sh > gitlogg.tmp
71-
echo -e "${Gre}The file ${Blu}./gitlogg.tmp ${Gre}generated in${RCol}: ${SECONDS}s" &&
72-
babel gitlogg-parse-json.js | node # only parse JSON if we have a source to parse it from
86+
echo $dirs | xargs -n 1 -P $NUM_THREADS ./output-intermediate-gitlog.sh > ${tempOutputFile}
87+
echo -e "${Gre}The file ${Blu}${tempOutputFile} ${Gre}generated in${RCol}: ${SECONDS}s" &&
88+
babel "${jsonParser}" | node # only parse JSON if we have a source to parse it from
7389
# if the path exists but is empty
7490
elif [ -d "${yourpathSanitized}" ] && [ ! "$(ls $yourpathSanitized)" ]; then
75-
echo -e "${Whi}[ERROR 002]: ${Yel}The path to the local repositories ${Red}'${yourpath}'${Yel}, which is set on the file ${Blu}'gitlogg-generate-log.sh' ${UYel}exists, but is empty!${RCol}"
91+
echo -e "${Whi}[ERROR 002]: ${Yel}The path to the local repositories ${Red}'${yourpath}'${Yel}, which is set on the file ${Blu}'${thisFile}' ${UYel}exists, but is empty!${RCol}"
7692
echo -e "${Yel}Please move the repos to ${Red}'${yourpath}'${Yel} or update the variable ${Pur}'yourpath'${Yel} to reflect the absolute path to the directory where the repos are located.${RCol}"
7793
# if the path does not exists
7894
elif [ ! -d "${yourpathSanitized}" ]; then
79-
echo -e "${Whi}[ERROR 001]: ${Yel}The path to the local repositories ${Red}'${yourpath}'${Yel}, which is set on the file ${Blu}'gitlogg-generate-log.sh' ${UYel}does not exist!${RCol}"
95+
echo -e "${Whi}[ERROR 001]: ${Yel}The path to the local repositories ${Red}'${yourpath}'${Yel}, which is set on the file ${Blu}'${thisFile}' ${UYel}does not exist!${RCol}"
8096
echo -e "${Yel}Please create ${Red}'${yourpath}'${Yel} and move the repos under it, or update the variable ${Pur}'yourpath'${Yel} to reflect the absolute path to the directory where the repos are located.${RCol}"
8197
fi

gitlogg/gitlogg-parse-json.js renamed to scripts/gitlogg-parse-json.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
var fs = require('fs'),
22
path = require('path'),
33
chalk = require('chalk'),
4-
output_file = './gitlogg.json';
4+
output_file_temp = '_tmp/gitlogg.tmp',
5+
output_file = '_output/gitlogg.json';
56

67
console.log(chalk.yellow('Generating JSON output...'));
78

@@ -16,7 +17,7 @@ var changes = function(data, index) {
1617

1718
console.time(chalk.green('JSON output generated in'));
1819

19-
var output = fs.readFileSync('gitlogg.tmp', 'utf8')
20+
var output = fs.readFileSync(output_file_temp, 'utf8')
2021
.trim()
2122
.split('\n')
2223
.map(line => line.split('\\t'))
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
#!/bin/bash
22

3+
my_dir="$(dirname "$0")"
4+
cd $my_dir
5+
36
bash gitlogg-generate-log.sh $@

0 commit comments

Comments
 (0)