From b54a15023ce1323e208fd520866c4ed2767ccab0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A8=8B=E5=B9=BF?= Date: Mon, 3 Mar 2025 16:48:00 +0800 Subject: [PATCH 1/3] add icon and fix git service --- media/commit-fill.svg | 10 ++++++++++ media/commit.png | Bin 0 -> 4423 bytes package.json | 5 +++-- src/GitService.ts | 1 + 4 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 media/commit-fill.svg create mode 100644 media/commit.png diff --git a/media/commit-fill.svg b/media/commit-fill.svg new file mode 100644 index 0000000..9501536 --- /dev/null +++ b/media/commit-fill.svg @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/media/commit.png b/media/commit.png new file mode 100644 index 0000000000000000000000000000000000000000..0bbdee6333d0bd75cbc2b4e0b7cf7ac02806630d GIT binary patch literal 4423 zcmb7I_d6Tj7fw(Td&gdltxD`sTZPtaR4Acp6s1b})E>2W5u^6ryLRjvja8~twTRWK zs99o^Z~7;E@AKUIKKGY%&pqck?>WyKYht8FL&-r2003z8;W}nS4E?u3*T6n@zDNZ~Fh>ng6cLDMi($U{BKxWig*skGFpJqN*FYq7%qO53Gr z4*j7(uWv6#KbY!q3;sR-lcr6pq;s+o60#U{`rYwjw>{IU)ipLgWS!^!j^6UqqaL#!?8P>sPn_iy`6+Xl;+}t=>dVZR$ z9ZidV7jzo97UX*KX?q7HxqNg;;xr3G1!&29~LdNA~pv2IESZ0+hP2UF-U}fE`v9rKVw*|Qn&t?%G zxm}`{eA4o_ZOJ1IHxxZy*S;*Kuo8H*!U));<5K)6{&$e-cKXq@y6u$8o~qIXzNJS{ z(@5>iVf%AUCjQ+gBeNcVA2{DH9ixTOUR*o-ENJkZiuqNY8D?7TVr&>vXguG*XA9e&y8@LMGR4dNp&l;Z zFOO%Np6C@6u31?#_s)O#Ikp9;?BXtJE_|^*f&w@6U3C@womM?cP`Ivo2UxK7PHYF1 zhUh~o;s7EAvasZoEC)2|)1{|-D@=LNG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2;yWGKzThQw@n6G!sNH&E-bE{6CL zq`{D5&kHCNj`4E{T!(jMWF3GNlA!KEE`(dY?FZDMOKm)B#r`2-%68&UI|`HY+iux= zO~}UyUPKGV)D3oda8og4on@W1KIi7-F#M?^0b22E#5%EKg0%rS0W8~g@%O_GBcdp< z`%epaPo?0GiW#gtoEb5K#Y%AFIB<{f!wo@4PbXA9tBAc$j~tpTxn3{!^}}2&+03b@ zWEQ!})l#IRlV6(N3H!x~E#cpwYv0;kxA5E{cwP`#IP6E-lWbX07mr@;^;y5v`*<~l z?N9<*VScs^@Yn1VABxj*xXH1GcPAT}Jh%$O3TrC%1ZWYK#`eFWa6LXl&gS0p{n;&r z!ug9!W4e*$8De#auVgMP`EER@A-7%CkpELz_$NiA=n`%_{k)BzC9TB~KMv5>HPWfq HvJ3wo-5ftc literal 0 HcmV?d00001 diff --git a/package.json b/package.json index 10b17cb..30bc38f 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,8 @@ "ui", "workspace" ], - "publisher": "elf.cheng", + "icon": "media/commit.png", + "publisher": "elfcheng", "extensionDependencies": [ "vscode.git" ], @@ -25,7 +26,7 @@ { "id": "gitCommitFilterView", "title": "Git Commits", - "icon": "media/icon.svg" + "icon": "media/commit-fill.svg" } ] }, diff --git a/src/GitService.ts b/src/GitService.ts index 4dc12b0..45298ef 100644 --- a/src/GitService.ts +++ b/src/GitService.ts @@ -109,6 +109,7 @@ export class GitService { if(commit){ commits.push(commit); } + lines = []; } else if (nline.trim() !== "") { lines.push(nline); } From 7195a21d059a1cdd4976fda60359e1666cff291e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A8=8B=E5=B9=BF?= Date: Mon, 3 Mar 2025 17:12:32 +0800 Subject: [PATCH 2/3] 0.0.2 --- package-lock.json | 4 ++-- package.json | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/package-lock.json b/package-lock.json index b5e2b34..d081b5a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "gitcommitfilter", - "version": "0.0.1", + "version": "0.0.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "gitcommitfilter", - "version": "0.0.1", + "version": "0.0.2", "devDependencies": { "@types/mocha": "^10.0.10", "@types/node": "20.x", diff --git a/package.json b/package.json index 30bc38f..a9a6a06 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "gitcommitfilter", "displayName": "gitcommitfilter", "description": "过滤显示当前git分支的commit", - "version": "0.0.1", + "version": "0.0.2", "engines": { "vscode": "^1.97.0" }, @@ -10,14 +10,14 @@ "Other" ], "extensionKind": [ - "ui", - "workspace" - ], + "ui", + "workspace" + ], "icon": "media/commit.png", "publisher": "elfcheng", "extensionDependencies": [ "vscode.git" -], + ], "activationEvents": [], "main": "./dist/extension.js", "contributes": { @@ -72,4 +72,4 @@ "type": "git", "url": "https://git.pyer.club/kingecg/gitcommitfilter.git" } -} \ No newline at end of file +} From f94358b38118db4b54a3289655d6730a32096cf4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A8=8B=E5=B9=BF?= Date: Mon, 3 Mar 2025 17:58:50 +0800 Subject: [PATCH 3/3] fix git parse --- src/GitService.ts | 27 ++++++++++++++++++--------- src/extension.ts | 7 ++++--- src/view.provider.ts | 4 +++- 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/src/GitService.ts b/src/GitService.ts index 45298ef..e333238 100644 --- a/src/GitService.ts +++ b/src/GitService.ts @@ -18,7 +18,7 @@ export interface GitCommit { export class GitService { private _repoPath: string; - constructor(private gitPath: string) { + constructor(private gitPath: string, private logger: vscode.LogOutputChannel) { const workspaceFolders = vscode.workspace.workspaceFolders; if (!workspaceFolders || workspaceFolders.length === 0) { throw new Error("No workspace folder opened"); @@ -52,17 +52,19 @@ export class GitService { "--name-only", ]; - + const that = this; return new Promise((resolve, reject) => { let lines: string[] = []; let commits: GitCommit[] = []; + function makeCommit(lines: any[]): GitCommit | undefined { try { if(lines.length === 1) { return undefined; } const commitLine = lines[0]; - console.log(commitLine); + that.logger.info('add commit',commitLine); + const commit: GitCommit = JSON.parse(lines[0]); commit.files = []; for (let i = 1; i < lines.length; i++) { @@ -93,11 +95,14 @@ export class GitService { gitProcess.stdout.on("data", (data) => { const nlines = data.split("\n").filter((l:string) => l.trim() !== ""); for (let nline of nlines) { + that.logger.info('process line 1',nline); if (nline.startsWith("{")) { if(lines.length > 0){ const commit = makeCommit(lines); if(commit){ + that.logger.info('push commit', commit.hash) commits.push(commit); + } } lines = []; @@ -107,6 +112,7 @@ export class GitService { }else if( nline.trim() === ""){ const commit = makeCommit(lines); if(commit){ + that.logger.info('push commit 2', commit.hash) commits.push(commit); } lines = []; @@ -114,15 +120,18 @@ export class GitService { lines.push(nline); } } - if(lines.length > 0){ - const commit = makeCommit(lines); - if(commit){ - commits.push(commit); - } - } + }); gitProcess.on("exit",(code,signal)=>{ if(code === 0){ + if(lines.length > 0){ + const commit = makeCommit(lines); + if(commit){ + + that.logger.info('push commit 3', commit.hash) + commits.push(commit); + } + } resolve(commits); }else{ reject(new Error(`git log exited with code ${code}`)); diff --git a/src/extension.ts b/src/extension.ts index 8a991d9..d255c0c 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -4,6 +4,7 @@ import { GitService } from './GitService'; import { GViewProvider } from './view.provider'; function getGitApi(){ + const gitExtension = vscode.extensions.getExtension<'vscode.git'>('vscode.git'); if(gitExtension && gitExtension.isActive){ const api = (gitExtension.exports as any).getAPI(1); @@ -20,10 +21,10 @@ export async function activate(context: vscode.ExtensionContext) { vscode.window.showErrorMessage('No Git avaliable'); return; } - - const gitService = new GitService(gitPath); + const logger = vscode.window.createOutputChannel('GitCommitFilter',{log: true}); + const gitService = new GitService(gitPath,logger); - const viewProvider = new GViewProvider(context, gitService); + const viewProvider = new GViewProvider(context, gitService,logger); const activityBarIcon = vscode.window.registerWebviewViewProvider(GViewProvider.viewType, viewProvider); diff --git a/src/view.provider.ts b/src/view.provider.ts index bdb28e8..07c94f1 100644 --- a/src/view.provider.ts +++ b/src/view.provider.ts @@ -9,7 +9,8 @@ export class GViewProvider implements vscode.WebviewViewProvider { constructor( private context: vscode.ExtensionContext, - private readonly _gitService: GitService + private readonly _gitService: GitService, + private readonly _logger: vscode.LogOutputChannel ) {} public resolveWebviewView( @@ -283,6 +284,7 @@ private async openDiff(commitId: string, filePath: string) { private async filterCommits(filterText: string) { if (this._view) { const commits = await this._gitService.getCommits(filterText); + this._logger.info(`filteredCommits:, ${JSON.stringify(commits)}"`); this._view.webview.postMessage({ command: "updateCommits", commits