Skip to content

Commit e456a88

Browse files
committed
docs: JSDoc 자동 문서화 설정
1 parent 25a6459 commit e456a88

38 files changed

+14158
-7
lines changed

docs/commands_catFile.js.html

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<title>JSDoc: Source: commands/catFile.js</title>
6+
7+
<script src="scripts/prettify/prettify.js"> </script>
8+
<script src="scripts/prettify/lang-css.js"> </script>
9+
<!--[if lt IE 9]>
10+
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
11+
<![endif]-->
12+
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
13+
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
14+
</head>
15+
16+
<body>
17+
18+
<div id="main">
19+
20+
<h1 class="page-title">Source: commands/catFile.js</h1>
21+
22+
23+
24+
25+
26+
27+
<section>
28+
<article>
29+
<pre class="prettyprint source linenums"><code>const fs = require('fs');
30+
const zlib = require('zlib');
31+
const { getObjectPath } = require('@utils/path');
32+
33+
/**
34+
* Git 객체 내용을 출력합니다 (blob/tree/commit 지원).
35+
* @param {string} hash SHA-1 해시
36+
* @param {string} gitDir .git 디렉토리 경로
37+
*/
38+
function catFile(hash, gitDir) {
39+
const { objectPath } = getObjectPath(gitDir, hash);
40+
41+
if (!fs.existsSync(objectPath)) {
42+
console.error(`fatal: 객체를 찾을 수 없습니다: ${hash}`);
43+
return;
44+
}
45+
46+
const content = decompress(fs.readFileSync(objectPath));
47+
const { type, body } = parseGitObject(content);
48+
49+
const handler = GitObjectPrinter[type];
50+
if (!handler) {
51+
console.error(`fatal: 알 수 없는 객체 타입: '${type}'`);
52+
return;
53+
}
54+
55+
handler(body);
56+
}
57+
58+
function decompress(buffer) {
59+
return zlib.inflateSync(buffer);
60+
}
61+
62+
function parseGitObject(buffer) {
63+
const nullIndex = buffer.indexOf(0);
64+
const header = buffer.slice(0, nullIndex).toString('utf-8');
65+
const type = header.split(' ')[0];
66+
const body = buffer.slice(nullIndex + 1);
67+
return { type, body };
68+
}
69+
70+
const GitObjectPrinter = {
71+
blob: (body) => console.log(body.toString('utf-8')),
72+
commit: (body) => console.log(body.toString('utf-8')),
73+
tree: (body) => {
74+
let i = 0;
75+
while (i &lt; body.length) {
76+
const modeEnd = body.indexOf(32, i);
77+
const mode = body.slice(i, modeEnd).toString();
78+
i = modeEnd + 1;
79+
80+
const nameEnd = body.indexOf(0, i);
81+
const name = body.slice(i, nameEnd).toString();
82+
i = nameEnd + 1;
83+
84+
const hash = body.slice(i, i + 20).toString('hex');
85+
i += 20;
86+
87+
console.log(`${mode} ${name} ${hash}`);
88+
}
89+
},
90+
};
91+
92+
module.exports = catFile;
93+
</code></pre>
94+
</article>
95+
</section>
96+
97+
98+
99+
100+
</div>
101+
102+
<nav>
103+
<h2><a href="index.html">Home</a></h2><h3>Global</h3><ul><li><a href="global.html#catFile">catFile</a></li><li><a href="global.html#formatGitDate">formatGitDate</a></li><li><a href="global.html#getCurrentCommitHash">getCurrentCommitHash</a></li><li><a href="global.html#parseCommitObject">parseCommitObject</a></li><li><a href="global.html#readHead">readHead</a></li><li><a href="global.html#readObject">readObject</a></li><li><a href="global.html#writeGitObject">writeGitObject</a></li></ul>
104+
</nav>
105+
106+
<br class="clear">
107+
108+
<footer>
109+
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.4</a> on Sun Jun 01 2025 11:31:26 GMT+0900 (대한민국 표준시)
110+
</footer>
111+
112+
<script> prettyPrint(); </script>
113+
<script src="scripts/linenumber.js"> </script>
114+
</body>
115+
</html>

docs/core_writeGitObject.js.html

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<title>JSDoc: Source: core/writeGitObject.js</title>
6+
7+
<script src="scripts/prettify/prettify.js"> </script>
8+
<script src="scripts/prettify/lang-css.js"> </script>
9+
<!--[if lt IE 9]>
10+
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
11+
<![endif]-->
12+
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
13+
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
14+
</head>
15+
16+
<body>
17+
18+
<div id="main">
19+
20+
<h1 class="page-title">Source: core/writeGitObject.js</h1>
21+
22+
23+
24+
25+
26+
27+
<section>
28+
<article>
29+
<pre class="prettyprint source linenums"><code>const crypto = require('crypto');
30+
const fs = require('fs');
31+
const zlib = require('zlib');
32+
const { getObjectPath } = require('@utils/path');
33+
34+
/**
35+
* Git 객체를 생성하고 저장합니다.
36+
* @param {'blob' | 'tree' | 'commit'} type
37+
* @param {Buffer|string} content
38+
* @param {string} gitDir
39+
* @returns {string} SHA-1 해시
40+
*/
41+
42+
function writeGitObject(type, content, gitDir) {
43+
const buffer = Buffer.isBuffer(content)
44+
? content
45+
: Buffer.from(content, 'utf-8');
46+
const header = `${type} ${buffer.length}\0`;
47+
const headerBuffer = Buffer.from(header, 'utf-8');
48+
const store = Buffer.concat([headerBuffer, buffer]);
49+
50+
const hash = crypto.createHash('sha1').update(store).digest('hex');
51+
const { objectDir, objectPath } = getObjectPath(gitDir, hash);
52+
53+
if (!fs.existsSync(objectDir)) {
54+
fs.mkdirSync(objectDir, { recursive: true });
55+
}
56+
57+
const compressed = zlib.deflateSync(store);
58+
fs.writeFileSync(objectPath, compressed);
59+
return hash;
60+
}
61+
62+
module.exports = writeGitObject;
63+
</code></pre>
64+
</article>
65+
</section>
66+
67+
68+
69+
70+
</div>
71+
72+
<nav>
73+
<h2><a href="index.html">Home</a></h2><h3>Global</h3><ul><li><a href="global.html#catFile">catFile</a></li><li><a href="global.html#formatGitDate">formatGitDate</a></li><li><a href="global.html#getCurrentCommitHash">getCurrentCommitHash</a></li><li><a href="global.html#parseCommitObject">parseCommitObject</a></li><li><a href="global.html#readHead">readHead</a></li><li><a href="global.html#readObject">readObject</a></li><li><a href="global.html#writeGitObject">writeGitObject</a></li></ul>
74+
</nav>
75+
76+
<br class="clear">
77+
78+
<footer>
79+
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.4</a> on Sun Jun 01 2025 11:31:26 GMT+0900 (대한민국 표준시)
80+
</footer>
81+
82+
<script> prettyPrint(); </script>
83+
<script src="scripts/linenumber.js"> </script>
84+
</body>
85+
</html>
19.1 KB
Binary file not shown.

0 commit comments

Comments
 (0)