mirror of
https://github.com/kahole/edamagit.git
synced 2024-10-26 09:00:54 +03:00
Merge pull request #271 from evannjohnson/conciseLogDecorate
Concise log decorate
This commit is contained in:
commit
7308619938
16
package.json
16
package.json
@ -469,6 +469,16 @@
|
||||
"superType": "label",
|
||||
"description": "Name of a git ref from a remote."
|
||||
},
|
||||
{
|
||||
"id": "magit-head-name",
|
||||
"superType": "label",
|
||||
"description": "Name of the (local) HEAD git ref."
|
||||
},
|
||||
{
|
||||
"id": "magit-remote-head-name",
|
||||
"superType": "label",
|
||||
"description": "Name of a HEAD git ref on a remote repo."
|
||||
},
|
||||
{
|
||||
"id": "magit-tag-name",
|
||||
"superType": "label",
|
||||
@ -484,6 +494,12 @@
|
||||
"magit-remote-ref-name": [
|
||||
"variable.other.constant"
|
||||
],
|
||||
"magit-head-name": [
|
||||
"entity.name.tag"
|
||||
],
|
||||
"magit-remote-head-name": [
|
||||
"variable.object.property"
|
||||
],
|
||||
"magit-tag-name": [
|
||||
"string.highlight"
|
||||
]
|
||||
|
@ -99,7 +99,16 @@ async function log(repository: MagitRepository, args: string[], revs: string[],
|
||||
const logEntries = parseLog(output.stdout);
|
||||
const revName = revs.join(' ');
|
||||
const uri = LogView.encodeLocation(repository);
|
||||
return ViewUtils.showView(uri, new LogView(uri, { entries: logEntries, revName }));
|
||||
|
||||
let defaultBranches: { [remoteName: string]: string } = {};
|
||||
for await (const remote of repository.remotes) {
|
||||
try {
|
||||
let defaultBranch = await gitRun(repository.gitRepository, ['symbolic-ref', `refs/remotes/${remote.name}/HEAD`], undefined, LogLevel.Error);
|
||||
defaultBranches[remote.name] = defaultBranch.stdout.replace(`refs/remotes/${remote.name}/`, '').trimEnd();
|
||||
} catch { } // gitRun will throw an error if remote/HEAD doesn't exist - we do not need to do anything in this case
|
||||
}
|
||||
|
||||
return ViewUtils.showView(uri, new LogView(uri, { entries: logEntries, revName }, repository, defaultBranches));
|
||||
}
|
||||
|
||||
async function getRevs(repository: MagitRepository) {
|
||||
|
@ -14,5 +14,7 @@ export const MagitDocumentSelector: DocumentSelector = { scheme: MagitUriScheme,
|
||||
export enum SemanticTokenTypes {
|
||||
RefName = 'magit-ref-name',
|
||||
RemoteRefName = 'magit-remote-ref-name',
|
||||
HeadName = 'magit-head-name',
|
||||
RemoteHeadName = 'magit-remote-head-name',
|
||||
TagName = 'magit-tag-name',
|
||||
}
|
||||
}
|
||||
|
@ -81,7 +81,7 @@ export default class ViewUtils {
|
||||
return selectedViews;
|
||||
}
|
||||
|
||||
public static generateRefTokensLine(commitHash: string, refs?: Ref[]): (string | Token)[] {
|
||||
public static generateRefTokensLine(commitHash: string, refs?: Ref[], headName?: string, defaultBranches?: { [remoteName: string]: string }): (string | Token)[] {
|
||||
|
||||
const matchingRefs = (refs ?? [])
|
||||
.filter(ref => ref.commit === commitHash)
|
||||
@ -103,7 +103,19 @@ export default class ViewUtils {
|
||||
let m = matchingRefs.find(other => other.name === namePart && other.type === RefType.Head);
|
||||
if (m && m.name) {
|
||||
hasMatchingRemoteBranch[m.name!] = true;
|
||||
refsContent.push(new Token(remotePart + '/', SemanticTokenTypes.RemoteRefName), new Token(m.name ?? '', SemanticTokenTypes.RefName));
|
||||
|
||||
// Determine if local or remote branches are HEADs
|
||||
let remoteRefTokenType = SemanticTokenTypes.RemoteRefName;
|
||||
if (defaultBranches && ref.remote && defaultBranches[ref.remote] === namePart) {
|
||||
remoteRefTokenType = SemanticTokenTypes.RemoteHeadName;
|
||||
}
|
||||
|
||||
let refTokenType = SemanticTokenTypes.RefName;
|
||||
if (m.name === headName) {
|
||||
refTokenType = SemanticTokenTypes.HeadName;
|
||||
}
|
||||
|
||||
refsContent.push(new Token(remotePart + '/', remoteRefTokenType), new Token(m.name ?? '', refTokenType));
|
||||
refsContent.push(' ');
|
||||
return;
|
||||
}
|
||||
@ -114,8 +126,13 @@ export default class ViewUtils {
|
||||
|
||||
let refTokenType = SemanticTokenTypes.RefName;
|
||||
|
||||
if (ref.remote) {
|
||||
if (ref.name === headName) {
|
||||
refTokenType = SemanticTokenTypes.HeadName;
|
||||
} else if (ref.remote) {
|
||||
refTokenType = SemanticTokenTypes.RemoteRefName;
|
||||
if (defaultBranches && ref.remote && ref.remote + '/' + defaultBranches[ref.remote] === ref.name) {
|
||||
refTokenType = SemanticTokenTypes.RemoteHeadName;
|
||||
}
|
||||
} else if (ref.type === RefType.Tag) {
|
||||
refTokenType = SemanticTokenTypes.TagName;
|
||||
}
|
||||
@ -126,4 +143,4 @@ export default class ViewUtils {
|
||||
|
||||
return refsContent;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,17 +10,21 @@ import { DocumentView } from './general/documentView';
|
||||
import { TextView } from './general/textView';
|
||||
import { Token } from './general/semanticTextView';
|
||||
import { SemanticTokenTypes } from '../common/constants';
|
||||
import { Ref, RefType } from '../typings/git';
|
||||
import ViewUtils from '../utils/viewUtils';
|
||||
import { MagitRemote } from '../models/magitRemote';
|
||||
|
||||
export default class LogView extends DocumentView {
|
||||
|
||||
static UriPath: string = 'log.magit';
|
||||
|
||||
constructor(uri: Uri, log: MagitLog) {
|
||||
constructor(uri: Uri, log: MagitLog, magitState: MagitRepository, defaultBranches?: { [remoteName: string]: string }) {
|
||||
super(uri);
|
||||
const refs = magitState.remotes.reduce((prev, remote) => remote.branches.concat(prev), magitState.branches.concat(magitState.tags));
|
||||
|
||||
this.subViews = [
|
||||
new TextView(`Commits in ${log.revName}`),
|
||||
...log.entries.map(entry => new CommitLongFormItemView(entry)),
|
||||
...log.entries.map(entry => new CommitLongFormItemView(entry, refs, magitState.HEAD?.name, defaultBranches)),
|
||||
];
|
||||
}
|
||||
|
||||
@ -34,8 +38,8 @@ export default class LogView extends DocumentView {
|
||||
|
||||
export class CommitLongFormItemView extends CommitItemView {
|
||||
|
||||
constructor(public logEntry: MagitLogEntry) {
|
||||
super(logEntry.commit);
|
||||
constructor(public logEntry: MagitLogEntry, refs?: Ref[], headName?: string, defaultBranches?: { [remoteName: string]: string }) {
|
||||
super(logEntry.commit, undefined, refs);
|
||||
|
||||
const timeDistance = formatDistanceToNowStrict(logEntry.time);
|
||||
const hash = `${GitTextUtils.shortHash(logEntry.commit.hash)} `;
|
||||
@ -46,16 +50,8 @@ export class CommitLongFormItemView extends CommitItemView {
|
||||
const msg = GitTextUtils.shortCommitMessage(logEntry.commit.message);
|
||||
this.content.push(`${hash}${graph}`);
|
||||
|
||||
const refTokens: Token[] = logEntry.refs.map(ref => new Token(ref, SemanticTokenTypes.RefName));
|
||||
if (refTokens.length) {
|
||||
|
||||
this.content.push(' (');
|
||||
refTokens.forEach(refToken => {
|
||||
this.content.push(refToken, ' ');
|
||||
});
|
||||
this.content.pop();
|
||||
|
||||
this.content.push(') ');
|
||||
if (logEntry.refs.length) {
|
||||
this.content.push(...ViewUtils.generateRefTokensLine(logEntry.commit.hash, refs, headName, defaultBranches));
|
||||
}
|
||||
|
||||
const availableMsgWidth = 70 - this.content.reduce((prev, v) => prev + v.length, 0);
|
||||
|
Loading…
Reference in New Issue
Block a user