-
Notifications
You must be signed in to change notification settings - Fork 105
refactor(engine): CSM 코드 구조 및 가독성 개선 #915
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
Changes from 1 commit
82da399
c32a522
b1ab100
478ef82
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| /** Index of the second parent (starting point of merged branch) in a merge commit */ | ||
| export const MERGE_PARENT_INDEX = 1; | ||
|
|
||
| /** Index of the first parent (main branch) in a commit */ | ||
| export const FIRST_PARENT_INDEX = 0; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| import { MERGE_PARENT_INDEX } from "./csm.const"; | ||
| import type { CommitDict, CommitNode, Stem } from "./types"; | ||
|
|
||
| /** Gets the second parent (starting point of merged branch) of a merge commit. */ | ||
| export const getMergeParentCommit = (baseCommitNode: CommitNode, commitDict: CommitDict): CommitNode | undefined => { | ||
|
Contributor
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. 이게 정확하게는 git domain에서 사용하는 용어가 function 이름에도 반영해주시면 감사하겠습니다!
Contributor
Author
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. 반영했습니다! 확인 감사합니다ㅎㅎ 상수도 이름 변경했습니다! |
||
| return commitDict.get(baseCommitNode.commit.parents[MERGE_PARENT_INDEX]); | ||
| }; | ||
|
|
||
| /** Finds the index of a specific commit node in a stem. */ | ||
| export const findSquashStartNodeIndex = (stem: Stem, commitId: string): number => { | ||
| return stem.nodes.findIndex(({ commit: { id } }) => id === commitId); | ||
| }; | ||
|
|
||
| /** | ||
| * Finds the end index for squash collection. | ||
| * Collects until the next mergedIntoStem node appears or until the end of the stem. | ||
| */ | ||
| export const findSquashEndIndex = (stem: Stem, startIndex: number): number => { | ||
| let endIndex = stem.nodes.length - 1; | ||
|
|
||
| for (let i = startIndex + 1; i < stem.nodes.length; i++) { | ||
| if (stem.nodes[i].mergedIntoStem) { | ||
| endIndex = i - 1; | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| return endIndex; | ||
| }; | ||
|
|
||
| /** | ||
| * Collects nodes from start index to end index in a stem and removes them. | ||
| * | ||
| * @param stem - Target stem | ||
| * @param startIndex - Start index | ||
| * @param endIndex - End index | ||
| * @returns Array of collected commit nodes | ||
| */ | ||
| export const collectSquashNodes = (stem: Stem, startIndex: number, endIndex: number): CommitNode[] => { | ||
| const nodesToCollect: CommitNode[] = []; | ||
|
|
||
| for (let i = startIndex; i <= endIndex; i++) { | ||
| nodesToCollect.push(stem.nodes[i]); | ||
| } | ||
|
|
||
| // Remove collected nodes from stem | ||
| stem.nodes.splice(startIndex, nodesToCollect.length); | ||
|
|
||
| return nodesToCollect; | ||
| }; | ||
|
|
||
| /** | ||
| * Extracts parent commits of nested merges from squashed nodes. | ||
| * Returns parent commits that do not belong to the base stem or current squash stem. | ||
| */ | ||
| export const extractNestedMergeParents = ( | ||
| squashedNodes: CommitNode[], | ||
| commitDict: CommitDict, | ||
| baseStemId: string, | ||
| currentSquashStemId: string | ||
| ): CommitNode[] => { | ||
| // Collect all parent commit IDs from merge commits | ||
| const nestedMergeParentCommitIds = squashedNodes | ||
| .filter((node) => node.commit.parents.length > 1) | ||
| .map((node) => node.commit.parents) | ||
| .reduce((pCommitIds, parents) => [...pCommitIds, ...parents], []); | ||
|
|
||
| return nestedMergeParentCommitIds | ||
| .map((commitId) => commitDict.get(commitId)) | ||
| .filter((node): node is CommitNode => node !== undefined) | ||
| .filter((node) => node.stemId !== baseStemId && node.stemId !== currentSquashStemId); | ||
| }; | ||
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.
오우 function document 도 넘 좋습니다!!! 주석이라면(?) 이 정도는 되어야 주석이죠!!