ksj09406 7719094edf 최초 커밋: MergeHub (사내 Git Merge/Diff 도구)
UbisamBase 플랫폼 위에서 도는 플러그인. 지금까지 만든 것을 그대로 담는다.
- 폴더 비교 / 파일 비교(부분 수용·워드랩·찾기) / 3-Way 병합 / Git 조작
- 비교 엔진: histogram 정렬 · 이동 블록 감지 · 무시 규칙 · 13개 언어 토크나이저
- doc/ 에 작업 지시서와 진행 기록

빌드 산출물(bin/obj)은 추적하지 않는다 - 플랫폼 런타임이 빌드 때마다
D:\UbisamPlatform\bin 에서 복사되어 들어오므로 저장소에 담을 이유가 없다.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-08 10:13:27 +09:00

91 lines
3.1 KiB
C#

using System;
using System.IO;
namespace MergeHub.Services
{
/// <summary>
/// 머지로 반영한 줄에 남기는 주석을 만든다.
///
/// 원칙 두 가지:
/// 1. 설명(사용자 입력)은 선택이지만, **누가·언제 반영했는지는 항상 들어간다.**
/// 2. 줄 "위"가 아니라 "끝"에 붙인다 - BASE/LOCAL 을 같은 줄 번호로 나란히 보여주는 구조라
/// 줄을 새로 끼워 넣으면 두 패널의 정렬이 통째로 어긋난다.
/// </summary>
public static class MergeNote
{
/// <summary>코드와 주석 사이 간격.</summary>
private const string Gap = " ";
/// <summary>
/// 주석 한 조각을 만든다. 구성은 딱 세 가지 - [사용자] 날짜 설명.
/// 설명이 비어 있어도 [사용자]와 날짜는 항상 남는다.
/// </summary>
public static string Build(string? author, DateTime when, string? comment, string? path)
{
var who = string.IsNullOrWhiteSpace(author) ? Environment.UserName : author!.Trim();
var body = $"[{who}] {when:yyyy-MM-dd}";
var note = comment?.Trim();
if (!string.IsNullOrEmpty(note)) body += $" {note}";
var (open, close) = CommentTokensFor(path);
return close is null ? $"{open} {body}" : $"{open} {body} {close}";
}
/// <summary>코드 줄 끝에 주석을 붙인다. 줄 끝 공백은 정리한다.</summary>
public static string Append(string line, string note)
{
if (string.IsNullOrEmpty(note)) return line;
return line.TrimEnd() + Gap + note;
}
/// <summary>확장자에 맞는 주석 기호. 모르는 확장자는 C 계열(//)로 본다.</summary>
public static (string Open, string? Close) CommentTokensFor(string? path)
{
var ext = string.IsNullOrEmpty(path)
? string.Empty
: Path.GetExtension(path).ToLowerInvariant();
switch (ext)
{
case ".py":
case ".sh":
case ".ps1":
case ".psm1":
case ".yml":
case ".yaml":
case ".toml":
case ".ini":
return ("#", null);
case ".xml":
case ".xaml":
case ".html":
case ".htm":
case ".csproj":
case ".vbproj":
case ".config":
case ".svg":
case ".resx":
return ("<!--", "-->");
case ".sql":
case ".lua":
return ("--", null);
case ".vb":
return ("'", null);
case ".bat":
case ".cmd":
return ("REM", null);
default:
// .cs .cpp .h .hpp .c .java .js .ts .json5 등 C 계열
return ("//", null);
}
}
}
}