mirror of
https://github.com/kahole/edamagit.git
synced 2024-09-11 07:15:31 +03:00
Compare commits
3 Commits
2ef9bb5a1e
...
d3b5f40afc
Author | SHA1 | Date | |
---|---|---|---|
|
d3b5f40afc | ||
|
f7cdaeeda4 | ||
|
2bca719144 |
4
package-lock.json
generated
4
package-lock.json
generated
@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "magit",
|
||||
"version": "0.6.41",
|
||||
"version": "0.6.42",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "magit",
|
||||
"version": "0.6.41",
|
||||
"version": "0.6.42",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@vscode/iconv-lite-umd": "^0.7.0",
|
||||
|
@ -7,7 +7,7 @@
|
||||
"author": {
|
||||
"name": "Kristian Andersen Hole"
|
||||
},
|
||||
"version": "0.6.41",
|
||||
"version": "0.6.42",
|
||||
"engines": {
|
||||
"vscode": "^1.50.0"
|
||||
},
|
||||
|
@ -6,7 +6,7 @@ import GitTextUtils from '../utils/gitTextUtils';
|
||||
import MagitUtils from '../utils/magitUtils';
|
||||
import MagitStatusView from '../views/magitStatusView';
|
||||
import { Status, Commit, RefType, Repository, Change, Ref } from '../typings/git';
|
||||
import { MagitBranch, MagitCommitList, MagitUpstreamRef } from '../models/magitBranch';
|
||||
import { MagitBranch, MagitUpstreamRef } from '../models/magitBranch';
|
||||
import { gitRun, LogLevel } from '../utils/gitRawRunner';
|
||||
import * as Constants from '../common/constants';
|
||||
import { getCommit } from '../utils/commitCache';
|
||||
@ -19,8 +19,6 @@ import { MagitRepository } from '../models/magitRepository';
|
||||
import ViewUtils from '../utils/viewUtils';
|
||||
import { scheduleForgeStatusAsync, forgeStatusCached } from '../forge';
|
||||
|
||||
const maxCommitsAheadBehind = 50;
|
||||
|
||||
export async function magitRefresh() { }
|
||||
|
||||
export async function magitStatus(): Promise<any> {
|
||||
@ -72,18 +70,18 @@ export async function internalMagitStatus(repository: Repository): Promise<Magit
|
||||
|
||||
const logTask = repository.state.HEAD?.commit ? repository.log({ maxEntries: 100 }) : Promise.resolve([]);
|
||||
|
||||
let ahead, behind: Promise<MagitCommitList> | undefined;
|
||||
|
||||
const ref = repository.state.HEAD?.name;
|
||||
const upstream = `${ref}@{u}`;
|
||||
// We actually must have a named ref if there is "ahead"/"behind"; you can't
|
||||
// have an "upstream" without being on a named branch. So the && ref is just
|
||||
// to satisfy the type checker.
|
||||
if (repository.state.HEAD?.ahead && ref) {
|
||||
ahead = getCommitRange(repository, upstream, ref, maxCommitsAheadBehind);
|
||||
if (repository.state.HEAD?.commit) {
|
||||
getCommit(repository, repository.state.HEAD?.commit);
|
||||
}
|
||||
if (repository.state.HEAD?.behind && ref) {
|
||||
behind = getCommitRange(repository, ref, upstream, maxCommitsAheadBehind);
|
||||
|
||||
let commitsAheadUpstream: string[] = [], commitsBehindUpstream: string[] = [];
|
||||
if (repository.state.HEAD?.ahead || repository.state.HEAD?.behind) {
|
||||
const ref = repository.state.HEAD.name;
|
||||
const args = ['rev-list', '--left-right', `${ref}...${ref}@{u}`];
|
||||
const res = (await gitRun(repository, args, {}, LogLevel.None)).stdout;
|
||||
[commitsAheadUpstream, commitsBehindUpstream] = GitTextUtils.parseRevListLeftRight(res);
|
||||
commitsAheadUpstream.map(c => getCommit(repository, c));
|
||||
commitsBehindUpstream.map(c => getCommit(repository, c));
|
||||
}
|
||||
|
||||
const workingTreeChanges_NoUntracked = repository.state.workingTreeChanges
|
||||
@ -152,12 +150,8 @@ export async function internalMagitStatus(repository: Repository): Promise<Magit
|
||||
|
||||
HEAD.upstreamRemote = HEAD.upstream;
|
||||
HEAD.upstreamRemote.commit = await upstreamRemoteCommitDetails;
|
||||
if (ahead) {
|
||||
HEAD.upstreamRemote.ahead = await ahead;
|
||||
}
|
||||
if (behind) {
|
||||
HEAD.upstreamRemote.behind = await behind;
|
||||
}
|
||||
HEAD.upstreamRemote.commitsAhead = await Promise.all(commitsAheadUpstream.map(hash => getCommit(repository, hash)));
|
||||
HEAD.upstreamRemote.commitsBehind = await Promise.all(commitsBehindUpstream.map(hash => getCommit(repository, hash)));
|
||||
HEAD.upstreamRemote.rebase = (await isRebaseUpstream) === 'true';
|
||||
}
|
||||
} catch { }
|
||||
@ -207,22 +201,6 @@ function toMagitChange(repository: Repository, change: Change, diff?: string): M
|
||||
return magitChange;
|
||||
}
|
||||
|
||||
async function getCommitRange(repository: Repository, from: string, to: string, maxResults: number): Promise<MagitCommitList> {
|
||||
const args = ['log', '--format=format:%H', `${from}...${to}`, '-n', `${Math.trunc(maxResults) + 1}`];
|
||||
let result;
|
||||
try {
|
||||
result = await gitRun(repository, args, {}, LogLevel.Error);
|
||||
} catch (error) {
|
||||
return {commits: [], truncated: false};
|
||||
}
|
||||
// Slice removes empty string after final newline.
|
||||
const hashes = result.stdout.trim().split(Constants.LineSplitterRegex);
|
||||
return {
|
||||
commits: await Promise.all(hashes.slice(0, maxResults).map(hash => getCommit(repository, hash))),
|
||||
truncated: hashes.length > maxResults,
|
||||
};
|
||||
}
|
||||
|
||||
async function pushRemoteStatus(repository: Repository): Promise<MagitUpstreamRef | undefined> {
|
||||
try {
|
||||
const HEAD = repository.state.HEAD;
|
||||
@ -230,20 +208,17 @@ async function pushRemoteStatus(repository: Repository): Promise<MagitUpstreamRe
|
||||
|
||||
if (HEAD?.name && pushRemote) {
|
||||
|
||||
const ahead = getCommitRange(repository, `${pushRemote}/${HEAD.name}`, HEAD.name, maxCommitsAheadBehind);
|
||||
const behind = getCommitRange(repository, HEAD.name, `${pushRemote}/${HEAD.name}`, maxCommitsAheadBehind);
|
||||
const args = ['rev-list', '--left-right', `${HEAD.name}...${pushRemote}/${HEAD.name}`];
|
||||
const res = (await gitRun(repository, args, {}, LogLevel.None)).stdout;
|
||||
const [commitsAheadPushRemote, commitsBehindPushRemote] = GitTextUtils.parseRevListLeftRight(res);
|
||||
const commitsAhead = await Promise.all(commitsAheadPushRemote.map(c => getCommit(repository, c)));
|
||||
const commitsBehind = await Promise.all(commitsBehindPushRemote.map(c => getCommit(repository, c)));
|
||||
|
||||
const refs = await getRefs(repository);
|
||||
const pushRemoteCommit = refs.find(ref => ref.remote === pushRemote && ref.name === `${pushRemote}/${HEAD.name}`)?.commit;
|
||||
const pushRemoteCommitDetails = pushRemoteCommit ? getCommit(repository, pushRemoteCommit) : Promise.resolve(undefined);
|
||||
|
||||
return {
|
||||
remote: pushRemote,
|
||||
name: HEAD.name,
|
||||
commit: await pushRemoteCommitDetails,
|
||||
ahead: await ahead,
|
||||
behind: await behind,
|
||||
};
|
||||
return { remote: pushRemote, name: HEAD.name, commit: await pushRemoteCommitDetails, commitsAhead, commitsBehind };
|
||||
}
|
||||
} catch { }
|
||||
}
|
||||
|
@ -7,13 +7,9 @@ export interface MagitBranch extends Branch {
|
||||
tag?: Ref;
|
||||
}
|
||||
|
||||
export interface MagitCommitList {
|
||||
commits: Commit[];
|
||||
truncated: boolean;
|
||||
}
|
||||
export interface MagitUpstreamRef extends UpstreamRef {
|
||||
commit?: Commit;
|
||||
ahead?: MagitCommitList;
|
||||
behind?: MagitCommitList;
|
||||
commitsAhead?: Commit[];
|
||||
commitsBehind?: Commit[];
|
||||
rebase?: boolean;
|
||||
}
|
@ -29,8 +29,8 @@ export default class ViewUtils {
|
||||
public static showDocumentColumn(): ViewColumn {
|
||||
const activeColumn = window.activeTextEditor?.viewColumn;
|
||||
|
||||
if (activeColumn && magitConfig.displayBufferSameColumn) {
|
||||
return activeColumn;
|
||||
if (magitConfig.displayBufferSameColumn) {
|
||||
return activeColumn ?? ViewColumn.Active;
|
||||
}
|
||||
|
||||
if ((activeColumn ?? 0) > ViewColumn.One) {
|
||||
|
@ -3,20 +3,17 @@ import { Section, SectionHeaderView } from '../general/sectionHeader';
|
||||
import { Commit, UpstreamRef, Ref } from '../../typings/git';
|
||||
import { LineBreakView } from '../general/lineBreakView';
|
||||
import { CommitItemView } from './commitSectionView';
|
||||
import { MagitCommitList } from '../../models/magitBranch';
|
||||
|
||||
export class UnsourcedCommitSectionView extends View {
|
||||
isFoldable = true;
|
||||
|
||||
static maxEntries = 256;
|
||||
|
||||
get id() { return this.section.toString(); }
|
||||
|
||||
constructor(private section: Section, upstream: UpstreamRef, list: MagitCommitList, refs: Ref[]) {
|
||||
constructor(private section: Section, upstream: UpstreamRef, commits: Commit[], refs: Ref[]) {
|
||||
super();
|
||||
this.subViews = [
|
||||
new SectionHeaderView(section, list.commits.length, `${upstream.remote}/${upstream.name}`, list.truncated),
|
||||
...list.commits.map(commit => new CommitItemView(commit, undefined, refs)),
|
||||
new SectionHeaderView(section, commits.length, `${upstream.remote}/${upstream.name}`),
|
||||
...commits.map(commit => new CommitItemView(commit, undefined, refs)),
|
||||
new LineBreakView()
|
||||
];
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ export enum Section {
|
||||
|
||||
export class SectionHeaderView extends UnclickableTextView {
|
||||
|
||||
constructor(section: Section, count?: number, extraText?: string, truncated=false) {
|
||||
super(`${section.valueOf()}${extraText ? ' ' + extraText : ''}${count ? ` (${count}${truncated ? '+': ''})` : ''}`);
|
||||
constructor(section: Section, count?: number, extraText?: string) {
|
||||
super(`${section.valueOf()}${extraText ? ' ' + extraText + '' : ''}${count ? ' (' + count + ')' : ''}`);
|
||||
}
|
||||
}
|
@ -77,19 +77,19 @@ export default class MagitStatusView extends DocumentView {
|
||||
|
||||
const refs = magitState.remotes.reduce((prev, remote) => remote.branches.concat(prev), magitState.branches.concat(magitState.tags));
|
||||
|
||||
if (magitState.HEAD?.upstreamRemote?.ahead?.commits.length && !magitConfig.hiddenStatusSections.has('unmerged')) {
|
||||
this.addSubview(new UnsourcedCommitSectionView(Section.UnmergedInto, magitState.HEAD.upstreamRemote, magitState.HEAD.upstreamRemote.ahead, refs));
|
||||
} else if (magitState.HEAD?.pushRemote?.ahead?.commits.length && !magitConfig.hiddenStatusSections.has('unpushed')) {
|
||||
this.addSubview(new UnsourcedCommitSectionView(Section.UnpushedTo, magitState.HEAD.pushRemote, magitState.HEAD.pushRemote.ahead, refs));
|
||||
if (magitState.HEAD?.upstreamRemote?.commitsAhead?.length && !magitConfig.hiddenStatusSections.has('unmerged')) {
|
||||
this.addSubview(new UnsourcedCommitSectionView(Section.UnmergedInto, magitState.HEAD.upstreamRemote, magitState.HEAD.upstreamRemote.commitsAhead, refs));
|
||||
} else if (magitState.HEAD?.pushRemote?.commitsAhead?.length && !magitConfig.hiddenStatusSections.has('unpushed')) {
|
||||
this.addSubview(new UnsourcedCommitSectionView(Section.UnpushedTo, magitState.HEAD.pushRemote, magitState.HEAD.pushRemote.commitsAhead, refs));
|
||||
}
|
||||
if (magitState.log.length > 0 && !magitState.HEAD?.upstreamRemote?.ahead?.commits.length && !magitConfig.hiddenStatusSections.has('recent commits')) {
|
||||
if (magitState.log.length > 0 && !magitState.HEAD?.upstreamRemote?.commitsAhead?.length && !magitConfig.hiddenStatusSections.has('recent commits')) {
|
||||
this.addSubview(new CommitSectionView(Section.RecentCommits, magitState.log.slice(0, 10), refs));
|
||||
}
|
||||
|
||||
if (magitState.HEAD?.upstreamRemote?.behind?.commits.length && !magitConfig.hiddenStatusSections.has('unpulled')) {
|
||||
this.addSubview(new UnsourcedCommitSectionView(Section.UnpulledFrom, magitState.HEAD.upstreamRemote, magitState.HEAD.upstreamRemote.behind, refs));
|
||||
} else if (magitState.HEAD?.pushRemote?.behind?.commits.length) {
|
||||
this.addSubview(new UnsourcedCommitSectionView(Section.UnpulledFrom, magitState.HEAD.pushRemote, magitState.HEAD.pushRemote.behind, refs));
|
||||
if (magitState.HEAD?.upstreamRemote?.commitsBehind?.length && !magitConfig.hiddenStatusSections.has('unpulled')) {
|
||||
this.addSubview(new UnsourcedCommitSectionView(Section.UnpulledFrom, magitState.HEAD.upstreamRemote, magitState.HEAD.upstreamRemote.commitsBehind, refs));
|
||||
} else if (magitState.HEAD?.pushRemote?.commitsBehind?.length) {
|
||||
this.addSubview(new UnsourcedCommitSectionView(Section.UnpulledFrom, magitState.HEAD.pushRemote, magitState.HEAD.pushRemote.commitsBehind, refs));
|
||||
}
|
||||
|
||||
if (magitState.forgeState?.pullRequests?.length && !magitConfig.hiddenStatusSections.has('pull requests')) {
|
||||
|
Loading…
Reference in New Issue
Block a user