-
Notifications
You must be signed in to change notification settings - Fork 83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[engine] feature/712 브랜치에서 작업한 내용을 main 브랜치에 반영 #766
Changes from 20 commits
42963dd
2f913fb
b8ae0a3
3b1da9c
8eade2e
861c262
1707efe
a739c3f
ed7ed3b
bfaee30
d5536b3
632560d
a18fb5a
7952cd0
be3931a
3ffabfb
cb8480b
7b7ff09
4488e5d
e9ad183
883453d
15a87ef
fb7975a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
import { COMMIT_SEPARATOR, GIT_LOG_SEPARATOR } from "@githru-vscode-ext/analysis-engine"; | ||
import * as cp from "child_process"; | ||
import * as fs from "fs"; | ||
import os from 'os'; | ||
import * as path from "path"; | ||
import { Worker } from 'worker_threads'; | ||
|
||
|
||
|
||
export interface GitExecutable { | ||
readonly path: string; | ||
|
@@ -112,7 +116,7 @@ | |
if (await isExecutable(file)) { | ||
try { | ||
return await getGitExecutable(file); | ||
} catch (_) {} | ||
} | ||
} | ||
return Promise.reject<GitExecutable>(); | ||
|
@@ -148,7 +152,7 @@ | |
for (let i = 0; i < paths.length; i++) { | ||
try { | ||
return await getGitExecutable(paths[i]); | ||
} catch (_) {} | ||
} | ||
throw new Error("None of the provided paths are a Git executable"); | ||
} | ||
|
@@ -170,6 +174,7 @@ | |
"%B", // commit message (subject and body) | ||
].join(GIT_LOG_SEPARATOR) + | ||
GIT_LOG_SEPARATOR; | ||
|
||
const args = [ | ||
"--no-pager", | ||
"log", | ||
|
@@ -198,6 +203,80 @@ | |
}); | ||
} | ||
|
||
export async function getLogCount(gitPath: string, currentWorkspacePath: string): Promise<number> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 드뎌 메인으로 들어오는군요 : ) |
||
const BASE_10 = 10; | ||
return new Promise((resolve, reject) => { | ||
const args = [ | ||
"rev-list", | ||
"--count", | ||
"--all", | ||
]; | ||
|
||
resolveSpawnOutput( | ||
cp.spawn(gitPath, args, { | ||
cwd: currentWorkspacePath, | ||
env: Object.assign({}, process.env), | ||
}) | ||
).then(([status, stdout, stderr]) => { | ||
const { code, error } = status; | ||
|
||
if (code === 0 && !error) { | ||
const commitCount = parseInt(stdout.toString().trim(), BASE_10); // Buffer를 문자열로 변환 후 숫자로 변환 | ||
resolve(commitCount); // 숫자를 반환 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 한글 주석은 영어로 변경하거나, |
||
} else { | ||
reject(stderr); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
|
||
export async function fetchGitLogInParallel(gitPath: string, currentWorkspacePath: string): Promise<string> { | ||
const numCores = os.cpus().length; | ||
|
||
const totalCnt = await getLogCount(gitPath, currentWorkspacePath); | ||
let numberOfThreads = 1; | ||
|
||
const taskThreshold = 1000; | ||
const coreCountThreshold = 4; | ||
|
||
if (totalCnt > taskThreshold) { | ||
if (numCores < coreCountThreshold) numberOfThreads = 2; | ||
else numberOfThreads = 3; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ? indentation 이 뭔가 안 맞는 느낌이네용? |
||
|
||
const chunkSize = Math.ceil(totalCnt/ numberOfThreads); | ||
const promises: Promise<string>[] = []; | ||
|
||
for (let i = 0; i < numberOfThreads; i++) { | ||
const skipCount = i * chunkSize; | ||
const limitCount = chunkSize; | ||
|
||
console.log('__dirname:', __dirname); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 정리하는 김에 console log도 정리해주면 좋을 것 같습니다. |
||
const worker = new Worker(path.resolve(__dirname, './worker.js'), { | ||
workerData: { | ||
gitPath, | ||
currentWorkspacePath, | ||
skipCount, | ||
limitCount, | ||
COMMIT_SEPARATOR, | ||
GIT_LOG_SEPARATOR | ||
}, | ||
}); | ||
|
||
promises.push( | ||
new Promise((resolve, reject) => { | ||
worker.on('message', resolve); | ||
worker.on('error', reject); | ||
}) | ||
); | ||
} | ||
|
||
return Promise.all(promises).then((logs) => logs.join('\n')); | ||
} | ||
|
||
|
||
|
||
export async function getGitConfig( | ||
gitPath: string, | ||
currentWorkspacePath: string, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import * as cp from 'child_process'; | ||
import { parentPort, workerData } from 'worker_threads'; | ||
|
||
import { resolveSpawnOutput } from './git.util' | ||
|
||
const { gitPath, currentWorkspacePath, skipCount, limitCount,COMMIT_SEPARATOR,GIT_LOG_SEPARATOR } = workerData; | ||
|
||
|
||
|
||
|
||
async function getPartialGitLog() { | ||
const gitLogFormat = | ||
COMMIT_SEPARATOR + | ||
[ | ||
"%H", // commit hash (id) | ||
"%P", // parent hashes | ||
"%D", // ref names (branches, tags) | ||
"%an", // author name | ||
"%ae", // author email | ||
"%ad", // author date | ||
"%cn", | ||
"%ce", | ||
"%cd", // committer name, committer email and committer date | ||
"%B", // commit message (subject and body) | ||
].join(GIT_LOG_SEPARATOR) + | ||
GIT_LOG_SEPARATOR; | ||
|
||
const args = [ | ||
'--no-pager', | ||
'log', | ||
'--all', | ||
'--parents', | ||
'--numstat', | ||
'--date-order', | ||
`--pretty=format:${gitLogFormat}`, | ||
'--decorate', | ||
'-c', | ||
`--skip=${skipCount}`, | ||
`-n ${limitCount}`, | ||
]; | ||
|
||
resolveSpawnOutput( | ||
cp.spawn(gitPath, args, { | ||
cwd: currentWorkspacePath, | ||
env: Object.assign({}, process.env), | ||
}) | ||
).then(([status, stdout, stderr]) => { | ||
const { code, error } = status; | ||
|
||
if (code === 0 && !error && parentPort !== null) { | ||
parentPort.postMessage(stdout.toString()); | ||
} else { | ||
if (parentPort !== null) parentPort.postMessage(stderr); | ||
} | ||
}).catch(error => { | ||
console.error('Spawn Error:', error); | ||
}); | ||
} | ||
|
||
getPartialGitLog(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,11 +12,14 @@ const extensionConfig = { | |
target: "node", // vscode extensions run in a Node.js-context 📖 -> https://webpack.js.org/configuration/node/ | ||
mode: "none", // this leaves the source code as close as possible to the original (when packaging we set this to 'production') | ||
|
||
entry: "./src/extension.ts", // the entry point of this extension, 📖 -> https://webpack.js.org/configuration/entry-context/ | ||
entry: { | ||
extension: "./src/extension.ts", // the entry point of this extension, 📖 -> https://webpack.js.org/configuration/entry-context/ | ||
worker: "./src/utils/git.worker.ts" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 여기서 |
||
}, | ||
output: { | ||
// the bundle is stored in the 'dist' folder (check package.json), 📖 -> https://webpack.js.org/configuration/output/ | ||
path: path.resolve(__dirname, "dist"), | ||
filename: "extension.js", | ||
filename: "[name].js", | ||
libraryTarget: "commonjs2", | ||
}, | ||
externals: { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unused는 추후에 삭제 해주시면 좋겠습니다!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
넵!