feat: Add patchset history and diff support with cvsps integration
- Add cvsps package to Docker dependencies - Implement patchset retrieval and diff endpoints in API - Add _run_cvsps_command() helper for cvsps integration - Enhance file history parsing with log message extraction - Improve UI with enhanced styling and patchset functionality
This commit is contained in:
parent
c263092c10
commit
d3b40ae93f
9 changed files with 660 additions and 26 deletions
19
ui/api.js
19
ui/api.js
|
|
@ -99,6 +99,25 @@ class CVSProxyAPI {
|
|||
return this.request(`/diff?${params.toString()}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get repository patchset history
|
||||
* @returns {Promise<Array>} Array of patchset objects
|
||||
*/
|
||||
async getPatchsets() {
|
||||
return this.request('/patchsets');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get diff for a specific patchset
|
||||
* @param {string} patchset - Patchset number
|
||||
* @returns {Promise<object>} Diff object with diff property
|
||||
*/
|
||||
async getPatchsetDiff(patchset) {
|
||||
const params = new URLSearchParams();
|
||||
params.append('patchset', patchset);
|
||||
return this.request(`/patchset-diff?${params.toString()}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check API health
|
||||
* @returns {Promise<object>} Health status
|
||||
|
|
|
|||
43
ui/app.js
43
ui/app.js
|
|
@ -158,6 +158,38 @@ class CVSRepositoryBrowser {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Show patchsets view
|
||||
*/
|
||||
async showPatchsets() {
|
||||
try {
|
||||
ui.patchsetContent.innerHTML = '<div class="loading">Loading patchsets...</div>';
|
||||
const patchsets = await api.getPatchsets();
|
||||
ui.displayPatchsets(patchsets);
|
||||
} catch (error) {
|
||||
console.error('Error showing patchsets:', error);
|
||||
ui.patchsetContent.innerHTML = `<div class="loading" style="color: #991b1b;">Error loading patchsets: ${error.message}</div>`;
|
||||
ui.showView(ui.patchsetView);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Show patchset diff
|
||||
* @param {string} patchset - Patchset number
|
||||
*/
|
||||
async showPatchsetDiff(patchset) {
|
||||
try {
|
||||
ui.patchsetDiffContent.innerHTML = '<div class="loading">Loading patchset diff...</div>';
|
||||
const diffResult = await api.getPatchsetDiff(patchset);
|
||||
const diffText = diffResult.diff || diffResult;
|
||||
ui.displayPatchsetDiff(diffText);
|
||||
} catch (error) {
|
||||
console.error('Error showing patchset diff:', error);
|
||||
ui.patchsetDiffContent.innerHTML = `<div class="loading" style="color: #991b1b;">Error loading patchset diff: ${error.message}</div>`;
|
||||
ui.showView(ui.patchsetDiffView);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup event listeners
|
||||
*/
|
||||
|
|
@ -176,6 +208,17 @@ class CVSRepositoryBrowser {
|
|||
ui.backFromDiffBtn.addEventListener('click', () => {
|
||||
ui.showView(ui.fileView);
|
||||
});
|
||||
|
||||
// Patchset view buttons
|
||||
ui.patchsetsBtn.addEventListener('click', () => this.showPatchsets());
|
||||
ui.backFromPatchsetBtn.addEventListener('click', () => {
|
||||
ui.showView(ui.welcomeView);
|
||||
});
|
||||
|
||||
// Patchset diff view back button
|
||||
ui.backFromPatchsetDiffBtn.addEventListener('click', () => {
|
||||
ui.showView(ui.patchsetView);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -14,6 +14,9 @@
|
|||
<header>
|
||||
<h1>CVS Repository Browser</h1>
|
||||
<div class="header-info">
|
||||
<button id="patchsetsBtn" class="btn btn-primary" title="View repository patchset history">
|
||||
📦 Patchsets
|
||||
</button>
|
||||
<button id="themeToggleBtn" class="btn-icon" title="Toggle dark mode">🌙</button>
|
||||
<span id="status" class="status">Connecting...</span>
|
||||
</div>
|
||||
|
|
@ -87,6 +90,28 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Patchset View -->
|
||||
<div id="patchsetView" class="view hidden">
|
||||
<div class="view-header">
|
||||
<button id="backFromPatchsetBtn" class="btn btn-secondary">← Back</button>
|
||||
<h2>Repository Patchsets</h2>
|
||||
</div>
|
||||
<div id="patchsetContent" class="patchset-content">
|
||||
<div class="loading">Loading patchsets...</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Patchset Diff View -->
|
||||
<div id="patchsetDiffView" class="view hidden">
|
||||
<div class="view-header">
|
||||
<button id="backFromPatchsetDiffBtn" class="btn btn-secondary">← Back to Patchsets</button>
|
||||
<h2>Patchset Diff</h2>
|
||||
</div>
|
||||
<div id="patchsetDiffContent" class="diff-content">
|
||||
<div class="loading">Loading patchset diff...</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Welcome View -->
|
||||
<div id="welcomeView" class="view">
|
||||
<div class="welcome-content">
|
||||
|
|
@ -99,6 +124,7 @@
|
|||
<li>📄 View file contents</li>
|
||||
<li>📋 Check revision history</li>
|
||||
<li>🔀 Compare file versions</li>
|
||||
<li>📦 View repository patchsets</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
226
ui/styles.css
226
ui/styles.css
|
|
@ -283,59 +283,257 @@ main {
|
|||
.history-item {
|
||||
background-color: var(--surface-color);
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: 0.5rem;
|
||||
padding: 1rem;
|
||||
margin-bottom: 1rem;
|
||||
border-radius: 0.375rem;
|
||||
padding: 0.625rem 0.75rem;
|
||||
margin-bottom: 0.5rem;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s;
|
||||
display: grid;
|
||||
grid-template-columns: 80px 1fr 150px 120px;
|
||||
gap: 0.75rem;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.history-item:hover {
|
||||
box-shadow: var(--shadow-lg);
|
||||
box-shadow: var(--shadow);
|
||||
border-color: var(--primary-color);
|
||||
background-color: var(--bg-color);
|
||||
}
|
||||
|
||||
.history-item.active {
|
||||
background-color: var(--primary-color);
|
||||
color: white;
|
||||
border-color: var(--primary-color);
|
||||
}
|
||||
|
||||
.history-item.active .history-revision,
|
||||
.history-item.active .history-date,
|
||||
.history-item.active .history-author,
|
||||
.history-item.active .history-state,
|
||||
.history-item.active .history-log {
|
||||
color: white;
|
||||
}
|
||||
|
||||
.history-item-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 0.5rem;
|
||||
display: contents;
|
||||
}
|
||||
|
||||
.history-revision {
|
||||
font-weight: 600;
|
||||
color: var(--primary-color);
|
||||
font-family: 'Monaco', 'Courier New', monospace;
|
||||
font-size: 0.875rem;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.history-item.active .history-revision {
|
||||
color: white;
|
||||
}
|
||||
|
||||
.history-date {
|
||||
color: var(--text-secondary);
|
||||
font-size: 0.875rem;
|
||||
font-size: 0.75rem;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.history-item.active .history-date {
|
||||
color: rgba(255, 255, 255, 0.8);
|
||||
}
|
||||
|
||||
.history-author {
|
||||
color: var(--text-secondary);
|
||||
font-size: 0.875rem;
|
||||
margin-bottom: 0.5rem;
|
||||
font-size: 0.75rem;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.history-item.active .history-author {
|
||||
color: rgba(255, 255, 255, 0.9);
|
||||
}
|
||||
|
||||
.history-state {
|
||||
display: inline-block;
|
||||
padding: 0.25rem 0.75rem;
|
||||
padding: 0.125rem 0.5rem;
|
||||
border-radius: 0.25rem;
|
||||
font-size: 0.75rem;
|
||||
font-size: 0.65rem;
|
||||
font-weight: 600;
|
||||
background-color: var(--bg-color);
|
||||
color: var(--text-secondary);
|
||||
text-align: center;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
margin-left: 0.5rem;
|
||||
}
|
||||
|
||||
.history-item.active .history-state {
|
||||
background-color: rgba(255, 255, 255, 0.2);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.history-lines {
|
||||
color: var(--text-secondary);
|
||||
font-size: 0.75rem;
|
||||
}
|
||||
|
||||
.history-item.active .history-lines {
|
||||
color: rgba(255, 255, 255, 0.9);
|
||||
}
|
||||
|
||||
.history-log-section {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.history-log {
|
||||
color: var(--text-secondary);
|
||||
font-size: 0.75rem;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
font-style: italic;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.history-item.active .history-log {
|
||||
color: rgba(255, 255, 255, 0.9);
|
||||
}
|
||||
|
||||
/* Patchset View */
|
||||
.patchset-content {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
padding: 1.5rem;
|
||||
}
|
||||
|
||||
.patchset-item {
|
||||
background-color: var(--surface-color);
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: 0.375rem;
|
||||
padding: 0.625rem 0.75rem;
|
||||
margin-bottom: 0.5rem;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s;
|
||||
display: grid;
|
||||
grid-template-columns: 100px 1fr 150px 120px;
|
||||
gap: 0.75rem;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.patchset-item:hover {
|
||||
box-shadow: var(--shadow);
|
||||
border-color: var(--primary-color);
|
||||
background-color: var(--bg-color);
|
||||
}
|
||||
|
||||
.patchset-item.active {
|
||||
background-color: var(--primary-color);
|
||||
color: white;
|
||||
border-color: var(--primary-color);
|
||||
}
|
||||
|
||||
.patchset-item.active .patchset-number,
|
||||
.patchset-item.active .patchset-date,
|
||||
.patchset-item.active .patchset-author,
|
||||
.patchset-item.active .patchset-tag,
|
||||
.patchset-item.active .patchset-log {
|
||||
color: white;
|
||||
}
|
||||
|
||||
.patchset-item-header {
|
||||
display: contents;
|
||||
}
|
||||
|
||||
.patchset-number {
|
||||
font-weight: 600;
|
||||
color: var(--primary-color);
|
||||
font-family: 'Monaco', 'Courier New', monospace;
|
||||
font-size: 0.875rem;
|
||||
margin-top: 0.5rem;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.patchset-item.active .patchset-number {
|
||||
color: white;
|
||||
}
|
||||
|
||||
.patchset-date {
|
||||
color: var(--text-secondary);
|
||||
font-size: 0.75rem;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.patchset-item.active .patchset-date {
|
||||
color: rgba(255, 255, 255, 0.8);
|
||||
}
|
||||
|
||||
.patchset-author {
|
||||
color: var(--text-secondary);
|
||||
font-size: 0.75rem;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.patchset-item.active .patchset-author {
|
||||
color: rgba(255, 255, 255, 0.9);
|
||||
}
|
||||
|
||||
.patchset-tag {
|
||||
display: inline-block;
|
||||
padding: 0.125rem 0.5rem;
|
||||
border-radius: 0.25rem;
|
||||
font-size: 0.65rem;
|
||||
font-weight: 600;
|
||||
background-color: var(--bg-color);
|
||||
color: var(--text-secondary);
|
||||
text-align: center;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
margin-left: 0.5rem;
|
||||
}
|
||||
|
||||
.patchset-item.active .patchset-tag {
|
||||
background-color: rgba(255, 255, 255, 0.2);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.patchset-log-section {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.patchset-log {
|
||||
color: var(--text-secondary);
|
||||
font-size: 0.75rem;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
font-style: italic;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.patchset-item.active .patchset-log {
|
||||
color: rgba(255, 255, 255, 0.9);
|
||||
}
|
||||
|
||||
/* Diff View */
|
||||
|
||||
.view-header {
|
||||
padding: 1.5rem;
|
||||
border-bottom: 1px solid var(--border-color);
|
||||
|
|
|
|||
125
ui/ui.js
125
ui/ui.js
|
|
@ -11,12 +11,41 @@ class UIManager {
|
|||
this.initializeTheme();
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a date string to relative format (e.g., "2 hours ago")
|
||||
* @param {string} dateStr - Date string in format "YYYY/MM/DD HH:MM:SS"
|
||||
* @returns {string} Relative date string
|
||||
*/
|
||||
getRelativeDate(dateStr) {
|
||||
try {
|
||||
// Parse the date string (format: "YYYY/MM/DD HH:MM:SS")
|
||||
const parts = dateStr.match(/(\d{4})\/(\d{2})\/(\d{2})\s+(\d{2}):(\d{2}):(\d{2})/);
|
||||
if (!parts) return dateStr;
|
||||
|
||||
const date = new Date(parts[1], parts[2] - 1, parts[3], parts[4], parts[5], parts[6]);
|
||||
const now = new Date();
|
||||
const seconds = Math.floor((now - date) / 1000);
|
||||
|
||||
if (seconds < 60) return 'just now';
|
||||
if (seconds < 3600) return `${Math.floor(seconds / 60)} minute${Math.floor(seconds / 60) > 1 ? 's' : ''} ago`;
|
||||
if (seconds < 86400) return `${Math.floor(seconds / 3600)} hour${Math.floor(seconds / 3600) > 1 ? 's' : ''} ago`;
|
||||
if (seconds < 604800) return `${Math.floor(seconds / 86400)} day${Math.floor(seconds / 86400) > 1 ? 's' : ''} ago`;
|
||||
if (seconds < 2592000) return `${Math.floor(seconds / 604800)} week${Math.floor(seconds / 604800) > 1 ? 's' : ''} ago`;
|
||||
if (seconds < 31536000) return `${Math.floor(seconds / 2592000)} month${Math.floor(seconds / 2592000) > 1 ? 's' : ''} ago`;
|
||||
return `${Math.floor(seconds / 31536000)} year${Math.floor(seconds / 31536000) > 1 ? 's' : ''} ago`;
|
||||
} catch (e) {
|
||||
return dateStr;
|
||||
}
|
||||
}
|
||||
|
||||
initializeElements() {
|
||||
// Views
|
||||
this.welcomeView = document.getElementById('welcomeView');
|
||||
this.fileView = document.getElementById('fileView');
|
||||
this.historyView = document.getElementById('historyView');
|
||||
this.diffView = document.getElementById('diffView');
|
||||
this.patchsetView = document.getElementById('patchsetView');
|
||||
this.patchsetDiffView = document.getElementById('patchsetDiffView');
|
||||
|
||||
// File view elements
|
||||
this.fileName = document.getElementById('fileName');
|
||||
|
|
@ -36,6 +65,15 @@ class UIManager {
|
|||
this.diffContent = document.getElementById('diffContent');
|
||||
this.backFromDiffBtn = document.getElementById('backFromDiffBtn');
|
||||
|
||||
// Patchset view elements
|
||||
this.patchsetContent = document.getElementById('patchsetContent');
|
||||
this.backFromPatchsetBtn = document.getElementById('backFromPatchsetBtn');
|
||||
this.patchsetsBtn = document.getElementById('patchsetsBtn');
|
||||
|
||||
// Patchset diff view elements
|
||||
this.patchsetDiffContent = document.getElementById('patchsetDiffContent');
|
||||
this.backFromPatchsetDiffBtn = document.getElementById('backFromPatchsetDiffBtn');
|
||||
|
||||
// Tree elements
|
||||
this.treeContainer = document.getElementById('treeContainer');
|
||||
|
||||
|
|
@ -122,7 +160,7 @@ class UIManager {
|
|||
* @param {HTMLElement} view - View to show
|
||||
*/
|
||||
showView(view) {
|
||||
[this.welcomeView, this.fileView, this.historyView, this.diffView].forEach(v => {
|
||||
[this.welcomeView, this.fileView, this.historyView, this.diffView, this.patchsetView, this.patchsetDiffView].forEach(v => {
|
||||
if (v) v.classList.add('hidden');
|
||||
});
|
||||
if (view) view.classList.remove('hidden');
|
||||
|
|
@ -202,13 +240,13 @@ class UIManager {
|
|||
|
||||
const historyHTML = history.map(revision => `
|
||||
<div class="history-item" data-revision="${revision.revision}">
|
||||
<div class="history-item-header">
|
||||
<span class="history-revision">${revision.revision}</span>
|
||||
<span class="history-date">${revision.date || 'N/A'}</span>
|
||||
<div class="history-revision">${revision.revision}</div>
|
||||
<div class="history-log-section">
|
||||
<div class="history-log">${revision.log ? this.escapeHtml(revision.log) : ''}</div>
|
||||
${revision.state && revision.state !== 'Exp' ? `<span class="history-state">${revision.state}</span>` : ''}
|
||||
</div>
|
||||
<div class="history-author">Author: <strong>${revision.author || 'Unknown'}</strong></div>
|
||||
<span class="history-state">${revision.state || 'Exp'}</span>
|
||||
<div class="history-lines">${revision.lines_changed || 'N/A'}</div>
|
||||
<div class="history-author">${revision.author || 'Unknown'}</div>
|
||||
<div class="history-date" title="${revision.date || 'N/A'}">${this.getRelativeDate(revision.date) || 'N/A'}</div>
|
||||
</div>
|
||||
`).join('');
|
||||
|
||||
|
|
@ -218,6 +256,10 @@ class UIManager {
|
|||
// Add click handlers to history items
|
||||
this.historyContent.querySelectorAll('.history-item').forEach(item => {
|
||||
item.addEventListener('click', () => {
|
||||
// Remove active class from all items
|
||||
this.historyContent.querySelectorAll('.history-item').forEach(i => i.classList.remove('active'));
|
||||
// Add active class to clicked item
|
||||
item.classList.add('active');
|
||||
const revision = item.dataset.revision;
|
||||
window.app.loadFileAtRevision(this.currentFile, revision);
|
||||
});
|
||||
|
|
@ -450,6 +492,75 @@ class UIManager {
|
|||
item.classList.remove('active');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Display patchsets
|
||||
* @param {Array} patchsets - Array of patchset objects
|
||||
*/
|
||||
displayPatchsets(patchsets) {
|
||||
if (!patchsets || patchsets.length === 0) {
|
||||
this.patchsetContent.innerHTML = '<div class="loading">No patchsets available</div>';
|
||||
this.showView(this.patchsetView);
|
||||
return;
|
||||
}
|
||||
|
||||
const patchsetHTML = patchsets.map(ps => `
|
||||
<div class="patchset-item" data-patchset="${ps.patchset}">
|
||||
<div class="patchset-number">PatchSet #${ps.patchset}</div>
|
||||
<div class="patchset-log-section">
|
||||
<div class="patchset-log">${ps.log ? this.escapeHtml(ps.log) : ''}</div>
|
||||
${ps.tag && ps.tag !== 'N/A' ? `<span class="patchset-tag">${ps.tag}</span>` : ''}
|
||||
</div>
|
||||
<div class="patchset-author">${ps.author || 'Unknown'}</div>
|
||||
<div class="patchset-date" title="${ps.date || 'N/A'}">${this.getRelativeDate(ps.date) || 'N/A'}</div>
|
||||
</div>
|
||||
`).join('');
|
||||
|
||||
this.patchsetContent.innerHTML = patchsetHTML;
|
||||
this.showView(this.patchsetView);
|
||||
|
||||
// Add click handlers to patchset items
|
||||
this.patchsetContent.querySelectorAll('.patchset-item').forEach(item => {
|
||||
item.addEventListener('click', () => {
|
||||
// Remove active class from all items
|
||||
this.patchsetContent.querySelectorAll('.patchset-item').forEach(i => i.classList.remove('active'));
|
||||
// Add active class to clicked item
|
||||
item.classList.add('active');
|
||||
const patchset = item.dataset.patchset;
|
||||
window.app.showPatchsetDiff(patchset);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Display patchset diff
|
||||
* @param {string} diffText - Diff content
|
||||
*/
|
||||
displayPatchsetDiff(diffText) {
|
||||
if (!diffText) {
|
||||
this.patchsetDiffContent.innerHTML = '<div class="loading">No diff available</div>';
|
||||
this.showView(this.patchsetDiffView);
|
||||
return;
|
||||
}
|
||||
|
||||
// Create code element with diff language class
|
||||
const codeElement = document.createElement('code');
|
||||
codeElement.className = 'language-diff';
|
||||
codeElement.textContent = diffText;
|
||||
|
||||
const preElement = document.createElement('pre');
|
||||
preElement.appendChild(codeElement);
|
||||
|
||||
this.patchsetDiffContent.innerHTML = '';
|
||||
this.patchsetDiffContent.appendChild(preElement);
|
||||
|
||||
// Apply syntax highlighting
|
||||
if (window.hljs) {
|
||||
hljs.highlightElement(codeElement);
|
||||
}
|
||||
|
||||
this.showView(this.patchsetDiffView);
|
||||
}
|
||||
}
|
||||
|
||||
// Create global UI manager instance
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue