Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions internal/gitengine/lanes.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ type interval struct {
span int
}

const MaxHemisphereLanes = 4

// AssignLanes performs deterministic interval packing independently for
// the upper (Remote/PR) and lower (Local/Unpushed) hemispheres.
// Shorter spans are placed on inner lanes closest to the central spine (Lane = 1)
Expand Down Expand Up @@ -92,8 +94,13 @@ func assignHemisphereLanes(branches []model.BranchArc, hemisphere string) {
}
}
if !placed {
laneRanges = append(laneRanges, []spanRange{{s: it.start, e: it.end}})
branches[it.idx].Lane = len(laneRanges)
if len(laneRanges) < MaxHemisphereLanes {
laneRanges = append(laneRanges, []spanRange{{s: it.start, e: it.end}})
branches[it.idx].Lane = len(laneRanges)
} else {
// Dikey kule oluşmasını engellemek için tavan şeride sınırla
branches[it.idx].Lane = MaxHemisphereLanes
}
}
}
}
37 changes: 37 additions & 0 deletions internal/gitengine/simulation.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,43 @@ func (m *Manager) repoOptionsLocked() []model.RepoOption {
return opts
}

// QuickRepoSignature returns an ultra-fast filesystem-based signature of the active repository
// (.git/HEAD and .git/index mtime) without running heavy git commands or parsing the graph.
func (m *Manager) QuickRepoSignature() string {
m.mu.RLock()
defer m.mu.RUnlock()

active := m.activeRepoID
var live *repoEntry
for i := range m.liveRepos {
if m.liveRepos[i].id == active {
entry := m.liveRepos[i]
live = &entry
break
}
}
if live == nil || !isGitDir(live.path) {
return fmt.Sprintf("sim-%d", m.logSeq)
}

gitDir := filepath.Join(live.path, ".git")
headPath := filepath.Join(gitDir, "HEAD")
headInfo, err := os.Stat(headPath)
var headMod int64
if err == nil {
headMod = headInfo.ModTime().UnixNano()
}

indexPath := filepath.Join(gitDir, "index")
indexInfo, err := os.Stat(indexPath)
var indexMod int64
if err == nil {
indexMod = indexInfo.ModTime().UnixNano()
}

return fmt.Sprintf("%s:%d:%d", live.id, headMod, indexMod)
}

// Snapshot returns the current CockpitSnapshot for the active repository.
func (m *Manager) Snapshot() (model.CockpitSnapshot, error) {
m.mu.RLock()
Expand Down
12 changes: 12 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ func (a *App) routes() http.Handler {
mux.HandleFunc("/api/system/update-check", a.guard(a.handleUpdateCheck))
mux.HandleFunc("/api/repo/protect", a.guard(a.handleProtectBranch))
mux.HandleFunc("/api/system/choose-folder", a.guard(a.handleChooseFolder))
mux.HandleFunc("/api/system/git-status-ping", a.guard(a.handleGitStatusPing))
mux.HandleFunc("/api/simulation/reset", a.guard(a.handleResetSimulation))
mux.HandleFunc("/api/reset", a.guard(a.handleResetSimulation))
mux.HandleFunc("/api/test/run", a.guard(a.handleRunLocalTest))
Expand Down Expand Up @@ -306,6 +307,17 @@ func (a *App) handleChooseFolder(w http.ResponseWriter, r *http.Request) {
})
}

func (a *App) handleGitStatusPing(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodGet {
writeJSONError(w, http.StatusMethodNotAllowed, "GET bekleniyor")
return
}
sig := a.mgr.QuickRepoSignature()
writeJSON(w, http.StatusOK, map[string]string{
"sig": sig,
})
}

func (a *App) handleDiscardWorkingTree(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPost {
writeJSONError(w, http.StatusMethodNotAllowed, "POST bekleniyor")
Expand Down
16 changes: 16 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,20 @@ func TestSecurityGuardsAndAPIFlow(t *testing.T) {
if rec := doPost("/api/repo/add", `{"path":""}`); rec.Code != http.StatusBadRequest {
t.Fatalf("expected 400 for empty path, got %d", rec.Code)
}

// 10. Git status ping (zero-overhead change detection)
reqPing := httptest.NewRequest(http.MethodGet, "http://"+host+"/api/system/git-status-ping", nil)
reqPing.Host = host
reqPing.AddCookie(sessionCookie)
recPing := httptest.NewRecorder()
h.ServeHTTP(recPing, reqPing)
if recPing.Code != http.StatusOK {
t.Fatalf("git-status-ping failed: %d %s", recPing.Code, recPing.Body.String())
}
var pingRes struct {
Sig string `json:"sig"`
}
if err := json.Unmarshal(recPing.Body.Bytes(), &pingRes); err != nil || pingRes.Sig == "" {
t.Fatalf("invalid ping response: %s", recPing.Body.String())
}
}
22 changes: 20 additions & 2 deletions web/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -511,21 +511,39 @@ async function bootstrap() {
}
}

// 4-second live silent polling
// Smart Git FS Event Listener / Lightweight Ping
// Diskte .git/HEAD veya .git/index mtime değişmedikçe ağır snapshot çağrılmaz, sıfır zıplama!
let lastGitSig = '';
setInterval(async () => {
if (state.offlineMode || state.drag || state.panning) return;
if (el.modal && !el.modal.hidden) return;
if (el.conflictStudioModal && !el.conflictStudioModal.hidden) return;
if (state.selectedBranchId || state.selectedNodeSha) return; // Kullanıcı bir öğeyi incelerken tuvali zıplatma!
const tag = document.activeElement?.tagName;
if (tag === 'INPUT' || tag === 'TEXTAREA' || tag === 'SELECT') return;

try {
const ping = await apiCall('/api/system/git-status-ping', 'GET');
if (ping && ping.sig) {
if (!lastGitSig) {
lastGitSig = ping.sig;
return;
}
if (ping.sig === lastGitSig) {
// Git deposunda hiçbir dosya/dal/commit değişmemiş: Sıfır işlem, sıfır zıplama!
return;
}
lastGitSig = ping.sig;
}

// Sadece gerçek bir Git değişikliği algılandığında snapshot çek:
const nextSnap = await apiCall('/api/snapshot');
const sig = snapshotSignature(nextSnap);
if (sig && sig !== state.lastSig) {
applySnapshot(nextSnap);
}
} catch {}
}, 4000);
}, 2500);
}

// Start Application on DOM Ready
Expand Down
10 changes: 8 additions & 2 deletions web/fallback.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,14 @@
}
}
if (!placed) {
lanes.push([{ s: it.s, e: it.e }]);
branches[it.idx].lane = lanes.length;
if (lanes.length < 4) {
lanes.push([{ s: it.s, e: it.e }]);
branches[it.idx].lane = lanes.length;
} else {
// Cap at lane 4 to prevent vertical tower explosion (Tri-Mode Parity)
lanes[3].push({ s: it.s, e: it.e });
branches[it.idx].lane = 4;
}
}
});
});
Expand Down
49 changes: 35 additions & 14 deletions web/modules/canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export function xOfSpine(idx) {
}

export function yOfLane(hemisphere, lane, isMerged = false) {
const l = Math.max(1, lane || 1);
const offset = isMerged ? (84 + (l - 1) * 56) : (LANE_BASE_OFFSET + (l - 1) * LANE_STEP_Y);
const l = Math.min(4, Math.max(1, lane || 1));
const offset = isMerged ? (54 + (l - 1) * 32) : (LANE_BASE_OFFSET + (l - 1) * LANE_STEP_Y);
return hemisphere === 'lower' ? MAIN_Y + offset : MAIN_Y - offset;
}

Expand Down Expand Up @@ -51,10 +51,18 @@ export function computeBranchGeometry(b, tipXOverride = null, tipYOverride = nul

if (isMerged && tipXOverride === null) {
const endX = xOfSpine(Math.max(b.startSpineIndex + 1, b.endSpineIndex));
const spanX = Math.max(SPINE_STEP_X, endX - startX);
const apexX = (startX + endX) / 2;
const apexY = laneY;
const cp1X = startX + (apexX - startX) * 0.55;
const cp2X = apexX + (endX - apexX) * 0.45;

// Geniş açılı tepe yüksekliği: Mesafe daraldıkça tepeyi dikleştirmek yerine yatık ve zarif tut
const maxApexOffset = Math.min(160, Math.max(45, spanX * 0.40));
const baseLaneOffset = 50 + (Math.min(4, b.lane || 1) - 1) * 28;
const actualOffset = Math.min(baseLaneOffset, maxApexOffset);
const apexY = b.hemisphere === 'lower' ? MAIN_Y + actualOffset : MAIN_Y - actualOffset;

// Geniş açılı yatık Bezier gerilimi (dikey dikilme yerine tatlı yayvan kavis):
const cp1X = startX + (apexX - startX) * 0.65;
const cp2X = apexX + (endX - apexX) * 0.35;
const openD = `M ${startX} ${MAIN_Y} C ${cp1X} ${MAIN_Y}, ${cp1X} ${apexY}, ${apexX} ${apexY}`;
const closeD = `M ${apexX} ${apexY} C ${cp2X} ${apexY}, ${cp2X} ${MAIN_Y}, ${endX} ${MAIN_Y}`;
const areaD = `${openD} C ${cp2X} ${apexY}, ${cp2X} ${MAIN_Y}, ${endX} ${MAIN_Y} Z`;
Expand Down Expand Up @@ -513,15 +521,28 @@ export function renderSVG(callbacks = {}) {

const nodes = snap.nodes || [];
const branches = snap.branches || [];
const visibleBranches = branches.filter((b) => state.showMergedArches || b.state !== 'merged');

// Akıllı Katlama: Kalabalık mega-repolarda dikey kuleyi önlemek için en güncel son 8 birleşmiş dalı aç
const mergedBranches = branches.filter((b) => b.state === 'merged');
const maxMergedArches = 8;
const recentMergedIds = new Set(
mergedBranches.slice(-maxMergedArches).map((b) => b.id)
);

const visibleBranches = branches.filter((b) => {
if (b.state !== 'merged') return true;
if (!state.showMergedArches) return false;
return recentMergedIds.has(b.id);
});

const apexLayout = layoutOpenApexPositions(visibleBranches);
state.apexLayout = apexLayout;

const maxSpineIdx = Math.max(nodes.length - 1, ...visibleBranches.map((b) => b.endSpineIndex || 0), 6);
const maxMergedUpperLane = Math.max(1, ...visibleBranches.filter((b) => b.hemisphere === 'upper' && b.state === 'merged').map((b) => b.lane || 1));
const maxApexX = Math.max(0, ...Array.from(apexLayout.values()).map((v) => v.apexX));

// Dinamik dikey sınır hesaplama (ferah ve dengeli tuval):
// Dinamik dikey sınır hesaplama (ferah ve kuleyi önleyen tavanlı tuval):
const upperBranches = visibleBranches.filter((b) => b.hemisphere === 'upper');
const lowerBranches = visibleBranches.filter((b) => b.hemisphere === 'lower');

Expand All @@ -531,9 +552,9 @@ export function renderSVG(callbacks = {}) {
const geom = computeBranchGeometry(b, null, null, apexLayout);
return geom.apexY;
}));
calcMinY = Math.min(calcMinY, highestUpperY - 70);
calcMinY = Math.max(MAIN_Y - 220, Math.min(calcMinY, highestUpperY - 60));
} else {
calcMinY = MAIN_Y - 100;
calcMinY = MAIN_Y - 90;
}

let calcMaxY = MAIN_Y + 80;
Expand All @@ -542,15 +563,15 @@ export function renderSVG(callbacks = {}) {
const geom = computeBranchGeometry(b, null, null, apexLayout);
return geom.apexY;
}));
calcMaxY = Math.max(calcMaxY, lowestLowerY + 125);
calcMaxY = Math.min(MAIN_Y + 220, Math.max(calcMaxY, lowestLowerY + 110));
} else {
calcMaxY = MAIN_Y + 100;
calcMaxY = MAIN_Y + 90;
}

const minY = calcMinY - 30;
const maxY = calcMaxY + 40;
const minY = calcMinY - 25;
const maxY = calcMaxY + 30;
const sceneW = Math.max(1280, SPINE_START_X + (maxSpineIdx + 2) * SPINE_STEP_X + 140, maxApexX + 200);
const sceneH = Math.max(340, maxY - minY);
const sceneH = Math.min(460, Math.max(300, maxY - minY));

const viewW = sceneW / state.zoom;
const viewH = sceneH / state.zoom;
Expand Down
Loading