From e9b9fd186fd67c1c93d42e8ba8cad4dbc71e6b93 Mon Sep 17 00:00:00 2001 From: Wout Mertens Date: Mon, 1 Feb 2021 13:48:36 +0100 Subject: [PATCH] fixup --- components/graph/git-graph-actions.js | 18 ++++--- components/graph/git-node.js | 72 +++++++++++++-------------- components/graph/graph.js | 1 + source/git-api.js | 4 +- test/spec.git-parser.js | 72 +++++++++++---------------- 5 files changed, 78 insertions(+), 89 deletions(-) diff --git a/components/graph/git-graph-actions.js b/components/graph/git-graph-actions.js index 71b7693b0..7b9f946a6 100644 --- a/components/graph/git-graph-actions.js +++ b/components/graph/git-graph-actions.js @@ -81,7 +81,7 @@ class Move extends ActionBase { class Reset extends ActionBase { constructor(graph, node) { - super(graph, 'Reset', 'reset', octicons.trashcan.toSVG({ 'height': 18 })); + super(graph, 'Reset', 'reset', octicons.trashcan.toSVG({ height: 18 })); this.node = node; this.visible = ko.computed(() => { if (this.isRunning()) return true; @@ -95,7 +95,8 @@ class Reset extends ActionBase { context && context.node() && remoteRef.node() != context.node() && - remoteRef.node().timestamp < context.node().timestamp; + remoteRef.node().timestamp < context.node().timestamp + ); }); } @@ -222,11 +223,14 @@ class Push extends ActionBase { if (remoteRef) { return remoteRef.moveTo(ref.node().sha1); } else { - return ref.createRemoteRef().then(() => { - if (this.graph.HEAD().name == ref.name) { - this.grah.HEADref().node(ref.node()); - } - }).finally(() => programEvents.dispatch({ event: 'request-fetch-tags' })); + return ref + .createRemoteRef() + .then(() => { + if (this.graph.HEAD().name == ref.name) { + this.grah.HEADref().node(ref.node()); + } + }) + .finally(() => programEvents.dispatch({ event: 'request-fetch-tags' })); } } } diff --git a/components/graph/git-node.js b/components/graph/git-node.js index 0aff73f73..00d3e13f4 100644 --- a/components/graph/git-node.js +++ b/components/graph/git-node.js @@ -116,43 +116,7 @@ class GitNodeViewModel extends Animateable { new GraphActions.Squash(this.graph, this), ]; - this.render = _.debounce( - () => { - this.refSearchFormVisible(false); - if (!this.isInited) return; - if (this.ancestorOfHEAD()) { - this.r(30); - this.cx(610); - - if (!this.aboveNode) { - this.cy(120); - } else if (this.aboveNode.ancestorOfHEAD()) { - this.cy(this.aboveNode.cy() + 120); - } else { - this.cy(this.aboveNode.cy() + 60); - } - } else { - this.r(15); - this.cx(610 + 90 * this.branchOrder()); - this.cy(this.aboveNode && !isNaN(this.aboveNode.cy()) ? this.aboveNode.cy() + 60 : 120); - } - - if (this.aboveNode && this.aboveNode.selected()) { - this.cy(this.aboveNode.cy() + this.aboveNode.commitComponent.element().offsetHeight + 30); - } - - this.color(this.ideologicalBranch() ? this.ideologicalBranch().color : '#666'); - if (!this.hasBeenRenderedBefore) { - // push this nodes into the graph's node list to be rendered if first time. - // if been pushed before, no need to add to nodes. - this.hasBeenRenderedBefore = true; - graph.nodes.push(this); - } - this.animate(); - }, - 500, - { leading: true } - ); + this.render = _.debounce(this.render.bind(this), 50, { trailing: true }); } getGraphAttr() { @@ -169,6 +133,40 @@ class GitNodeViewModel extends Animateable { if (parent) parent.belowNode = this; } + render() { + this.refSearchFormVisible(false); + if (!this.isInited) return; + if (this.ancestorOfHEAD()) { + this.r(30); + this.cx(610); + + if (!this.aboveNode) { + this.cy(120); + } else if (this.aboveNode.ancestorOfHEAD()) { + this.cy(this.aboveNode.cy() + 120); + } else { + this.cy(this.aboveNode.cy() + 60); + } + } else { + this.r(15); + this.cx(610 + 90 * this.branchOrder()); + this.cy(this.aboveNode && !isNaN(this.aboveNode.cy()) ? this.aboveNode.cy() + 60 : 120); + } + + if (this.aboveNode && this.aboveNode.selected()) { + this.cy(this.aboveNode.cy() + this.aboveNode.commitComponent.element().offsetHeight + 30); + } + + this.color(this.ideologicalBranch() ? this.ideologicalBranch().color : '#666'); + if (!this.hasBeenRenderedBefore) { + // push this nodes into the graph's node list to be rendered if first time. + // if been pushed before, no need to add to nodes. + this.hasBeenRenderedBefore = true; + this.graph.nodes.push(this); + } + this.animate(); + } + setData(logEntry) { this.title(logEntry.message.split('\n')[0]); this.parents(logEntry.parents || []); diff --git a/components/graph/graph.js b/components/graph/graph.js index d9f190b85..bc2d316b5 100644 --- a/components/graph/graph.js +++ b/components/graph/graph.js @@ -3,6 +3,7 @@ const _ = require('lodash'); const moment = require('moment'); const octicons = require('octicons'); const components = require('ungit-components'); +const programEvents = require('ungit-program-events'); const GitNodeViewModel = require('./git-node'); const GitRefViewModel = require('./git-ref'); const EdgeViewModel = require('./edge'); diff --git a/source/git-api.js b/source/git-api.js index edb063806..2fac8170c 100644 --- a/source/git-api.js +++ b/source/git-api.js @@ -70,7 +70,7 @@ exports.registerApi = (env) => { return mkdirp(pathToWatch); }) .then(() => { - const watcher = fs.watch(pathToWatch, options || {}, (event, filename) => { + const watcher = watch(pathToWatch, options || {}, (event, filename) => { if (event === 'rename' || !filename) return; const filePath = path.join(subfolderPath, filename); winston.debug(`File change: ${filePath}`); @@ -395,7 +395,7 @@ exports.registerApi = (env) => { if (err.stderr && err.stderr.indexOf("fatal: bad default revision 'HEAD'") == 0) { return { limit: limit, skip: skip, nodes: [] }; } else if ( - /fatal: your current branch \'.+\' does not have any commits yet.*/.test(err.stderr) + /fatal: your current branch '.+' does not have any commits yet.*/.test(err.stderr) ) { return { limit: limit, skip: skip, nodes: [] }; } else if (err.stderr && err.stderr.indexOf('fatal: Not a git repository') == 0) { diff --git a/test/spec.git-parser.js b/test/spec.git-parser.js index f5c08e61c..b8f4a64e3 100644 --- a/test/spec.git-parser.js +++ b/test/spec.git-parser.js @@ -230,10 +230,8 @@ describe('git-parser parseGitLog', () => { timestamp: 1546610046000, committerEmail: 'test@example.com', committerName: 'Test ungit', - total: { - additions: 176, - deletions: 1, - }, + additions: 176, + deletions: 1, fileLineDiffs: [ { additions: 1, @@ -266,10 +264,8 @@ describe('git-parser parseGitLog', () => { timestamp: 1546607036000, committerEmail: 'test@example.com', committerName: 'Test ungit', - total: { - additions: 32, - deletions: 0, - }, + additions: 32, + deletions: 0, fileLineDiffs: [ { additions: 32, @@ -295,10 +291,8 @@ describe('git-parser parseGitLog', () => { timestamp: 1546606976000, committerEmail: 'test@example.com', committerName: 'Test ungit', - total: { - additions: 0, - deletions: 0, - }, + additions: 0, + deletions: 0, fileLineDiffs: [], isHead: false, message: 'empty commit', @@ -315,10 +309,8 @@ describe('git-parser parseGitLog', () => { timestamp: 1546606916000, committerEmail: 'test@example.com', committerName: 'Test ungit', - total: { - additions: 14, - deletions: 9, - }, + additions: 14, + deletions: 9, fileLineDiffs: [ { additions: 4, @@ -385,10 +377,8 @@ describe('git-parser parseGitLog', () => { timestamp: 1546607036000, committerEmail: 'test@example.com', committerName: 'Test ungit', - total: { - additions: 32, - deletions: 0, - }, + additions: 32, + deletions: 0, fileLineDiffs: [ { additions: 32, @@ -431,10 +421,8 @@ describe('git-parser parseGitLog', () => { timestamp: 1546607036000, committerEmail: 'test@example.com', committerName: 'Test ungit', - total: { - additions: 32, - deletions: 0, - }, + additions: 32, + deletions: 0, fileLineDiffs: [ { additions: 32, @@ -518,10 +506,8 @@ describe('git-parser parseGitLog', () => { expect(gitParser.parseGitLog(gitLog)[0]).to.eql({ refs: ['HEAD', 'refs/heads/git-parser-specs'], - total: { - additions: 32, - deletions: 0, - }, + additions: 32, + deletions: 0, fileLineDiffs: [ { additions: 32, @@ -773,21 +759,21 @@ describe('parseGitStatusNumstat', () => { describe('parseGitStatus', () => { it('parses git status', () => { const gitStatus = - `## git-parser-specs\x00` + - `A file1.js\x00` + - `M file2.js\x00` + - `D file3.js\x00` + - ` D file4.js\x00` + - ` U file5.js\x00` + - `U file6.js\x00` + - `AA file7.js\x00` + - `? file8.js\x00` + - `A file9.js\x00` + - `?D file10.js\x00` + - `AD file11.js\x00` + - ` M file12.js\x00` + - `?? file13.js\x00` + - `R ../source/sys.js\x00../source/sysinfo.js\x00`; + '## git-parser-specs\x00' + + 'A file1.js\x00' + + 'M file2.js\x00' + + 'D file3.js\x00' + + ' D file4.js\x00' + + ' U file5.js\x00' + + 'U file6.js\x00' + + 'AA file7.js\x00' + + '? file8.js\x00' + + 'A file9.js\x00' + + '?D file10.js\x00' + + 'AD file11.js\x00' + + ' M file12.js\x00' + + '?? file13.js\x00' + + 'R ../source/sys.js\x00../source/sysinfo.js\x00'; expect(gitParser.parseGitStatus(gitStatus)).to.eql({ branch: 'git-parser-specs',