1
1
mirror of https://github.com/kahole/edamagit.git synced 2024-10-26 09:00:54 +03:00

feat: implement commit log for single file/path

Implement command and fill in stub for file popup menu. Use --follow
to show history across file renames and exclude --graph.

Showing the commit log for all files within a directory tree also works
when using https://github.com/shirou/vscode-dired because it properly
sets file URIs for directories.
This commit is contained in:
Nam Nguyen 2021-08-24 22:28:52 -07:00
parent a2d26863da
commit ef8e38df5d
4 changed files with 25 additions and 8 deletions

View File

@ -63,11 +63,12 @@
"onCommand:magit.process-log",
"onCommand:magit.file-popup",
"onCommand:magit.blame-file",
"onCommand:magit.diff-file",
"onCommand:magit.log-file",
"onCommand:magit.stage-file",
"onCommand:magit.stage-all",
"onCommand:magit.unstage-file",
"onCommand:magit.unstage-all",
"onCommand:magit.diff-file",
"onCommand:magit.save-and-close-editor",
"onCommand:magit.clear-and-abort-editor"
],
@ -214,6 +215,10 @@
"command": "magit.diff-file",
"title": "Magit Diff File"
},
{
"command": "magit.log-file",
"title": "Magit Log File"
},
{
"command": "magit.stage-file",
"title": "Magit Stage File"

View File

@ -5,6 +5,7 @@ import * as Commit from './commitCommands';
import * as Staging from './stagingCommands';
import * as Blaming from './blamingCommands';
import * as Diffing from './diffingCommands';
import * as Logging from './loggingCommands';
const filePopupMenu = {
title: 'File Actions',
@ -15,7 +16,7 @@ const filePopupMenu = {
// { label: 'D', description: 'Diff...', action: () => { } },
{ label: 'd', description: 'Diff', action: ({ repository, data }: MenuState) => Diffing.diffFile(repository, data as Uri) },
// { label: 'L', description: 'Log...', action: () => { } },
// { label: 'l', description: 'log', action: ({ repository, data }: MenuState) => logFile(repository, data as Uri) },
{ label: 'l', description: 'log', action: ({ repository, data }: MenuState) => Logging.logFile(repository, data as Uri) },
// { label: 't', description: 'trace', action: () => { } },
// { label: 'B', description: 'Blame...', action: () => { } },
{ label: 'b', description: 'Blame', action: ({ repository, data }: MenuState) => Blaming.blameFile(repository, data as Uri) },
@ -26,4 +27,4 @@ const filePopupMenu = {
export async function filePopup(repository: MagitRepository, fileUri: Uri) {
return MenuUtil.showMenu(filePopupMenu, { repository, data: fileUri });
}
}

View File

@ -1,4 +1,4 @@
import { window } from 'vscode';
import { Uri, window } from 'vscode';
import { StatusMessageDisplayTimeout } from '../common/constants';
import { MenuState, MenuUtil, Switch, Option } from '../menu/menu';
import { MagitBranch } from '../models/magitBranch';
@ -82,8 +82,18 @@ async function logReferences(repository: MagitRepository, head: MagitBranch, swi
await log(repository, args, revs);
}
async function log(repository: MagitRepository, args: string[], revs: string[]) {
const output = await gitRun(repository.gitRepository, args.concat(revs), {}, LogLevel.Error);
export async function logFile(repository: MagitRepository, fileUri: Uri) {
const incompatible_switch_keys = ['-g'];
const compatible_switches = switches.map(x => (
incompatible_switch_keys.includes(x.key) ? {...x, activated: false} : {...x}
));
let args = createLogArgs(compatible_switches, options);
args.push('--follow');
await log(repository, args, ['HEAD'], [fileUri.fsPath]);
}
async function log(repository: MagitRepository, args: string[], revs: string[], paths: string[] = []) {
const output = await gitRun(repository.gitRepository, args.concat(revs, ['--'], paths), {}, LogLevel.Error);
const logEntries = parseLog(output.stdout);
const revName = revs.join(' ');
const uri = LogView.encodeLocation(repository);
@ -164,4 +174,4 @@ function parseLog(stdout: string): MagitLogEntry[] {
}
});
return commits;
}
}

View File

@ -24,7 +24,7 @@ import { merging } from './commands/mergingCommands';
import { rebasing } from './commands/rebasingCommands';
import { filePopup } from './commands/filePopupCommands';
import { remoting } from './commands/remotingCommands';
import { logging } from './commands/loggingCommands';
import { logging, logFile } from './commands/loggingCommands';
import { MagitProcessLogEntry } from './models/magitProcessLogEntry';
import { processView } from './commands/processCommands';
import { resetting, resetMixed, resetHard } from './commands/resettingCommands';
@ -155,6 +155,7 @@ export function activate(context: ExtensionContext) {
commands.registerTextEditorCommand('magit.file-popup', CommandPrimer.primeFileCommand(filePopup, false)),
commands.registerTextEditorCommand('magit.blame-file', CommandPrimer.primeFileCommand(blameFile, false)),
commands.registerTextEditorCommand('magit.diff-file', CommandPrimer.primeFileCommand(diffFile, false)),
commands.registerTextEditorCommand('magit.log-file', CommandPrimer.primeFileCommand(logFile, false)),
commands.registerTextEditorCommand('magit.stage-file', CommandPrimer.primeFileCommand(stageFile)),
commands.registerTextEditorCommand('magit.unstage-file', CommandPrimer.primeFileCommand(unstageFile)),