Skip to content

Commit d784f25

Browse files
committed
Merge branch 'main' into production-change-control
2 parents bd27d4a + 9320089 commit d784f25

File tree

6 files changed

+142
-165
lines changed

6 files changed

+142
-165
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8-
## [2.7.0] - Unreleased
8+
## [2.7.0] - 2024-11-04
99

1010
### Added
1111
- Added 'git push --force' in expert mode (#527)
@@ -52,6 +52,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
5252
- Fixed changing favorites for users without permissions (#587)
5353
- Fix creating new branch from Git Web UI (#591)
5454
- Fix wording for Git Repo Root Directory (#601)
55+
- Fix Diff View options not applying immediately (#590)
56+
- Cleaned up parsing of command output in Git Web UI (#609)
57+
- Fix TempFolder misspecification (#611)
58+
- Fix deleting files on import all (#618)
5559

5660
## [2.6.0] - 2024-10-07
5761

cls/SourceControl/Git/PullEventHandler/IncrementalLoad.cls

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ Method DeleteFile(item As %String = "", externalName As %String = "") As %Status
9191
set sc = $$$OK
9292
}
9393
}
94+
// Force the catch if failing
95+
$$$ThrowOnError(sc)
9496
} catch e {
9597
set filename = ##class(SourceControl.Git.Utils).FullExternalName(item)
9698
if '##class(%File).Exists(filename) {

cls/SourceControl/Git/Utils.cls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ $Replace(..#Storage,"^SYS","^%SYS")
2424
/// Returns root temp folder
2525
ClassMethod DefaultTemp() As %String
2626
{
27-
set defaultTemp = ##class(%File).Construct($System.Util.ManagerDirectory(),"repo/"_$Namespace)
27+
set defaultTemp = ##class(%File).Construct($System.Util.ManagerDirectory(),"repo/")
2828
try {
2929
set defaultTemp = $Get(@..%SYSNamespaceStorage()@("%defaultTemp"), defaultTemp)
3030
} catch e {

cls/SourceControl/Git/WebUIDriver.cls

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,7 @@ ClassMethod HandleRequest(pagePath As %String, InternalName As %String = "", Out
235235
do %data.WriteLine(errStream.ReadLine())
236236
set:changeTerminators nLines = nLines + 1
237237
}
238-
239-
// Need to write out an extra newline
240-
do %data.WriteLine()
238+
241239
do %data.WriteLine("Git-Stderr-Length: " _ (errStream.Size + nLines))
242240
do %data.Write("Git-Return-Code: " _ returnCode) // No ending newline expected
243241
do %data.Rewind()
@@ -295,10 +293,7 @@ ClassMethod HandleRequest(pagePath As %String, InternalName As %String = "", Out
295293
do %data.WriteLine(errStream.ReadLine())
296294
set:changeTerminators nLines = nLines + 1
297295
}
298-
299-
// Need to write out two lines or we get an infinite loop in JavaScript...
300-
do %data.WriteLine()
301-
do %data.WriteLine()
296+
302297
do %data.WriteLine("Git-Stderr-Length: " _ (errStream.Size + nLines))
303298
do %data.Write("Git-Return-Code: " _ returnCode) // No ending newline expected
304299
do %data.Rewind()

git-webui/release/share/git-webui/webui/js/git-webui.js

Lines changed: 66 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,27 @@ webui.gitVersion = function() {
125125
})
126126
}
127127

128+
webui.parseGitResponse = function(data) {
129+
var matches = data.match(/([\S\s]*)Git-Stderr-Length:\s(\d*)[\r\n]{1,2}Git-Return-Code:\s(\d*)/);
130+
if (!matches || (matches.length < 4)) {
131+
return {
132+
output: '',
133+
message: '',
134+
rcode: 1
135+
}
136+
}
137+
var messageData = matches[1].replace(/(\r\n)/gm, "\n");
138+
var errorLength = parseInt(matches[2],10);
139+
var boundary = messageData.length - errorLength;
140+
var stdout = messageData.substring(0, boundary)
141+
var stderr = messageData.substring(boundary);
142+
return {
143+
output: stdout,
144+
message: stderr,
145+
rcode: matches[3]
146+
};
147+
}
148+
128149
webui.git_command = function(command, callback) {
129150
$.ajax({
130151
url: "git-command",
@@ -134,32 +155,10 @@ webui.git_command = function(command, callback) {
134155
command: command
135156
}),
136157
success: function(data) {
137-
// Convention : last lines are footer meta data like headers. An empty line marks the start if the footers
138-
var footers = {};
139-
var fIndex = data.length;
140-
while (true) {
141-
var oldFIndex = fIndex;
142-
fIndex = data.lastIndexOf("\r\n", fIndex - 1);
143-
var line = data.substring(fIndex + 2, oldFIndex);
144-
if (line.length > 0) {
145-
var footer = line.split(": ");
146-
footers[footer[0]] = footer[1];
147-
} else {
148-
break;
149-
}
150-
}
151-
// Trims the the data variable to remove the footers extracted in the loop.
152-
// Windows adds \r\n for every line break but the Git-Stderr-Length variable,
153-
// counts it as only one character, throwing off the message length.
154-
var trimmedData = data.substring(0, fIndex).replace(/(\r\n)/gm, "\n");
155-
var fIndex = trimmedData.length
156-
157-
var messageLength = parseInt(footers["Git-Stderr-Length"]);
158-
var messageStartIndex = fIndex-messageLength;
159-
var message = trimmedData.substring(messageStartIndex, fIndex);
160-
161-
var output = trimmedData.substring(0, messageStartIndex);
162-
var rcode = parseInt(footers["Git-Return-Code"]);
158+
var result = webui.parseGitResponse(data);
159+
var rcode = result.rcode;
160+
var output = result.output;
161+
var message = result.message;
163162

164163
if (rcode == 0) {
165164
if (callback) {
@@ -197,13 +196,8 @@ webui.git_command = function(command, callback) {
197196
}
198197
},
199198
error: function(data) {
200-
var trimmedData = data.substring(0, fIndex).replace(/(\r\n)/gm, "\n");
201-
var fIndex = trimmedData.length
202-
203-
var messageLength = parseInt(footers["Git-Stderr-Length"]);
204-
var messageStartIndex = fIndex-messageLength;
205-
var message = trimmedData.substring(messageStartIndex, fIndex);
206-
webui.showError(message);
199+
var trimmedData = data.replace(/(\r\n)/gm, "\n");
200+
webui.showError(trimmedData);
207201
},
208202
});
209203
}
@@ -233,32 +227,10 @@ webui.git = function(cmd, arg1, arg2, arg3, arg4) {
233227

234228
$.post("git", {command: cmd}, function(data, status, xhr) {
235229
if (xhr.status == 200) {
236-
// Convention : last lines are footer meta data like headers. An empty line marks the start if the footers
237-
var footers = {};
238-
var fIndex = data.length;
239-
while (true) {
240-
var oldFIndex = fIndex;
241-
fIndex = data.lastIndexOf("\r\n", fIndex - 1);
242-
var line = data.substring(fIndex + 2, oldFIndex);
243-
if (line.length > 0) {
244-
var footer = line.split(": ");
245-
footers[footer[0]] = footer[1];
246-
} else {
247-
break;
248-
}
249-
}
250-
// Trims the the data variable to remove the footers extracted in the loop.
251-
// Windows adds \r\n for every line break but the Git-Stderr-Length variable,
252-
// counts it as only one character, throwing off the message length.
253-
var trimmedData = data.substring(0, fIndex).replace(/(\r\n)/gm, "\n");
254-
var fIndex = trimmedData.length
255-
256-
var messageLength = parseInt(footers["Git-Stderr-Length"]);
257-
var messageStartIndex = fIndex-messageLength;
258-
var message = trimmedData.substring(messageStartIndex, fIndex);
259-
260-
var output = trimmedData.substring(0, messageStartIndex);
261-
var rcode = parseInt(footers["Git-Return-Code"]);
230+
var result = webui.parseGitResponse(data);
231+
var rcode = result.rcode;
232+
var output = result.output;
233+
var message = result.message;
262234

263235
if (rcode == 0) {
264236
if (callback) {
@@ -295,15 +267,15 @@ webui.git = function(cmd, arg1, arg2, arg3, arg4) {
295267
}
296268
}
297269
} else {
298-
if(errorCallback) {
299-
errorCallback(message);
270+
if (errorCallback) {
271+
errorCallback(data);
300272
} else{
301-
webui.showError(message);
273+
webui.showError(data);
302274
}
303275
}
304276
}, "text")
305277
.fail(function(xhr, status, error) {
306-
webui.showError("Git webui server not running");
278+
webui.showError("An internal error occurred and has been logged.");
307279
});
308280
};
309281

@@ -1401,21 +1373,17 @@ webui.StashListView = function(stashView) {
14011373
webui.git("stash list --format='%gd::%ch::%cL::%cN::%gs'", function(data) {
14021374
var start = 0;
14031375
var count = 0;
1404-
while (true) {
1405-
var end = data.indexOf("\n", start);
1406-
if (end != -1) {
1407-
var len = end - start;
1408-
} else {
1409-
break;
1376+
var lines = data.split("\n");
1377+
for (var i = 0; i < lines.length; i++) {
1378+
if (lines[i].length == 0) {
1379+
continue;
14101380
}
1411-
var entry = new Entry(self, data.substring(start, start+len));
1381+
var entry = new Entry(self, lines[i]);
14121382
if(start == 0){
14131383
entry.select();
14141384
}
14151385
content.appendChild(entry.element);
1416-
1417-
start = end + 1;
1418-
++count;
1386+
count++;
14191387
}
14201388
if(count == 0){
14211389
var emptyStash = $('<h4 class="empty-stash">You have no stashed changes.</h4>');
@@ -1476,6 +1444,9 @@ webui.StashListView = function(stashView) {
14761444
self.message = ""
14771445

14781446
var pieces = data.split(/::|:\s/gm);
1447+
if (pieces.length < 5) {
1448+
return;
1449+
}
14791450
self.stashIndex = pieces[0].substring(pieces[0].indexOf('{')+1, pieces[0].indexOf('}'));
14801451
self.date = pieces[1];
14811452
self.authorEmail = pieces[2];
@@ -1525,6 +1496,13 @@ webui.DiffView = function(sideBySide, hunkSelectionAllowed, parent, stashedCommi
15251496
var self = this;
15261497

15271498
self.update = function(cmd, diffOpts, file, mode) {
1499+
if (cmd || diffOpts || file || mode) {
1500+
// if new input, update all
1501+
this.cmd = cmd
1502+
this.diffOpts = diffOpts
1503+
this.file = file
1504+
this.mode = mode
1505+
}
15281506
gitApplyType = mode;
15291507
$(".diff-stage", self.element).attr("style", "display:none");
15301508
$(".diff-cancel", self.element).attr("style", "display:none");
@@ -1576,6 +1554,14 @@ webui.DiffView = function(sideBySide, hunkSelectionAllowed, parent, stashedCommi
15761554
}
15771555
};
15781556

1557+
self.clear = function() {
1558+
self.refresh("");
1559+
}
1560+
1561+
self.reRun = function() {
1562+
self.update(this.cmd, this.diffOpts, this.file, this.mode)
1563+
}
1564+
15791565
self.refresh = function(diff) {
15801566
self.currentDiff = diff;
15811567
self.diffHeader = "";
@@ -1789,24 +1775,24 @@ webui.DiffView = function(sideBySide, hunkSelectionAllowed, parent, stashedCommi
17891775

17901776
self.addContext = function() {
17911777
self.context += 3;
1792-
self.update();
1778+
self.reRun();
17931779
}
17941780

17951781
self.removeContext = function() {
17961782
if (self.context > 3) {
17971783
self.context -= 3;
1798-
self.update();
1784+
self.reRun();
17991785
}
18001786
}
18011787

18021788
self.allContext = function() {
18031789
self.complete = !self.complete;
1804-
self.update();
1790+
self.reRun();
18051791
}
18061792

18071793
self.toggleIgnoreWhitespace = function() {
18081794
self.ignoreWhitespace = !self.ignoreWhitespace;
1809-
self.update();
1795+
self.reRun();
18101796
}
18111797

18121798
self.handleClick = function(event) {
@@ -1900,6 +1886,7 @@ webui.DiffView = function(sideBySide, hunkSelectionAllowed, parent, stashedCommi
19001886
webui.git("stash pop stash@{"+stashIndex+"}", function(output){
19011887
webui.showSuccess(output);
19021888
parent.stashView.update(0);
1889+
self.clear();
19031890
});
19041891
}
19051892

@@ -1911,6 +1898,7 @@ webui.DiffView = function(sideBySide, hunkSelectionAllowed, parent, stashedCommi
19111898
webui.git("stash drop stash@{"+stashIndex+"}", function(output){
19121899
webui.showSuccess(output.substring(output.indexOf("Dropped")));
19131900
parent.stashView.update(0);
1901+
self.clear();
19141902
});
19151903
}
19161904

@@ -2473,7 +2461,7 @@ webui.WorkspaceView = function(mainView) {
24732461
self.update = function(mode) {
24742462
self.newChangedFilesView.update();
24752463
if (self.newChangedFilesView.getSelectedItemsCount() == 0) {
2476-
self.diffView.update(undefined, undefined, undefined, mode);
2464+
self.diffView.clear();
24772465
}
24782466
};
24792467

0 commit comments

Comments
 (0)