mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[git] Let dynamically add changes from a stash by updating the live file.
Define "local" parameter in GitChangeUtils.parseChangeList() and use CurrentContentRevision if local. Use it in the GitUnstashDialog.
This commit is contained in:
@@ -508,7 +508,7 @@ public class GitUtil {
|
||||
if ((!firstStep) && lineIsAStart) {
|
||||
final StringScanner innerScanner = new StringScanner(sb.toString());
|
||||
sb.setLength(0);
|
||||
consumer.consume(GitChangeUtils.parseChangeList(project, root, innerScanner, skipDiffsForMerge, h));
|
||||
consumer.consume(GitChangeUtils.parseChangeList(project, root, innerScanner, skipDiffsForMerge, h, false));
|
||||
}
|
||||
sb.append(lineIsAStart ? line.substring(2) : line).append('\n');
|
||||
firstStep = false;
|
||||
@@ -516,7 +516,7 @@ public class GitUtil {
|
||||
if (sb.length() > 0) {
|
||||
final StringScanner innerScanner = new StringScanner(sb.toString());
|
||||
sb.setLength(0);
|
||||
consumer.consume(GitChangeUtils.parseChangeList(project, root, innerScanner, skipDiffsForMerge, h));
|
||||
consumer.consume(GitChangeUtils.parseChangeList(project, root, innerScanner, skipDiffsForMerge, h, false));
|
||||
}
|
||||
if (s.hasMoreData()) {
|
||||
throw new IllegalStateException("More input is avaialble: " + s.line());
|
||||
|
||||
@@ -86,7 +86,7 @@ public class GitShowAllSubmittedFilesAction extends AnAction implements DumbAwar
|
||||
* @param file file affected by the revision
|
||||
*/
|
||||
public static void showSubmittedFiles(final Project project, final VcsFileRevision revision, final VirtualFile file) {
|
||||
showSubmittedFiles(project, revision.getRevisionNumber().asString(), file);
|
||||
showSubmittedFiles(project, revision.getRevisionNumber().asString(), file, false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -95,14 +95,15 @@ public class GitShowAllSubmittedFilesAction extends AnAction implements DumbAwar
|
||||
* @param project a project
|
||||
* @param revision a revision number
|
||||
* @param file file affected by the revision
|
||||
* @param local
|
||||
*/
|
||||
public static void showSubmittedFiles(final Project project, final String revision, final VirtualFile file) {
|
||||
public static void showSubmittedFiles(final Project project, final String revision, final VirtualFile file, final boolean local) {
|
||||
new Task.Backgroundable(project, GitBundle.message("changes.retrieving", revision)) {
|
||||
public void run(@NotNull ProgressIndicator indicator) {
|
||||
indicator.setIndeterminate(true);
|
||||
try {
|
||||
VirtualFile vcsRoot = GitUtil.getGitRoot(file);
|
||||
final CommittedChangeList changeList = GitChangeUtils.getRevisionChanges(project, vcsRoot, revision, true);
|
||||
final CommittedChangeList changeList = GitChangeUtils.getRevisionChanges(project, vcsRoot, revision, true, local);
|
||||
if (changeList != null) {
|
||||
UIUtil.invokeLaterIfNeeded(new Runnable() {
|
||||
public void run() {
|
||||
|
||||
@@ -122,7 +122,7 @@ public class GitChangeUtils {
|
||||
public static void parseChanges(Project project,
|
||||
VirtualFile vcsRoot,
|
||||
@Nullable GitRevisionNumber thisRevision,
|
||||
GitRevisionNumber parentRevision,
|
||||
@Nullable GitRevisionNumber parentRevision,
|
||||
StringScanner s,
|
||||
Collection<Change> changes,
|
||||
final Set<String> ignoreNames) throws VcsException {
|
||||
@@ -230,14 +230,20 @@ public class GitChangeUtils {
|
||||
* of the merge, so changes are reported as difference with the first revision
|
||||
* listed on the the merge that has at least some changes.
|
||||
*
|
||||
*
|
||||
* @param project the project file
|
||||
* @param root the git root
|
||||
* @param revisionName the name of revision (might be tag)
|
||||
* @param skipDiffsForMerge
|
||||
* @param local
|
||||
* @return change list for the respective revision
|
||||
* @throws VcsException in case of problem with running git
|
||||
*/
|
||||
public static GitCommittedChangeList getRevisionChanges(Project project, VirtualFile root, String revisionName, boolean skipDiffsForMerge) throws VcsException {
|
||||
public static GitCommittedChangeList getRevisionChanges(Project project,
|
||||
VirtualFile root,
|
||||
String revisionName,
|
||||
boolean skipDiffsForMerge,
|
||||
boolean local) throws VcsException {
|
||||
GitSimpleHandler h = new GitSimpleHandler(project, root, GitCommand.SHOW);
|
||||
h.setNoSSH(true);
|
||||
h.setSilent(true);
|
||||
@@ -245,7 +251,7 @@ public class GitChangeUtils {
|
||||
revisionName, "--");
|
||||
String output = h.run();
|
||||
StringScanner s = new StringScanner(output);
|
||||
return parseChangeList(project, root, s, skipDiffsForMerge, h);
|
||||
return parseChangeList(project, root, s, skipDiffsForMerge, h, local);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -328,15 +334,24 @@ public class GitChangeUtils {
|
||||
/**
|
||||
* Parse changelist
|
||||
*
|
||||
*
|
||||
* @param project the project
|
||||
* @param root the git root
|
||||
* @param s the scanner for log or show command output
|
||||
* @param skipDiffsForMerge
|
||||
* @param handler the handler that produced the output to parse. - for debugging purposes.
|
||||
* @param local pass {@code true} to indicate that this revision should be an editable
|
||||
* {@link com.intellij.openapi.vcs.changes.CurrentContentRevision}.
|
||||
* Pass {@code false} for
|
||||
* @return the parsed changelist
|
||||
* @throws VcsException if there is a problem with running git
|
||||
*/
|
||||
public static GitCommittedChangeList parseChangeList(Project project, VirtualFile root, StringScanner s, boolean skipDiffsForMerge, GitHandler handler) throws VcsException {
|
||||
public static GitCommittedChangeList parseChangeList(Project project,
|
||||
VirtualFile root,
|
||||
StringScanner s,
|
||||
boolean skipDiffsForMerge,
|
||||
GitHandler handler,
|
||||
boolean local) throws VcsException {
|
||||
ArrayList<Change> changes = new ArrayList<Change>();
|
||||
// parse commit information
|
||||
final Date commitDate = GitUtil.parseTimestampWithNFEReport(s.line(), handler, s.getAllText());
|
||||
@@ -367,7 +382,7 @@ public class GitChangeUtils {
|
||||
final GitRevisionNumber parentRevision = parents.length > 0 ? loadRevision(project, root, parents[0]) : null;
|
||||
// This is the first or normal commit with the single parent.
|
||||
// Just parse changes in this commit as returned by the show command.
|
||||
parseChanges(project, root, thisRevision, parentRevision, s, changes, null);
|
||||
parseChanges(project, root, thisRevision, local ? null : parentRevision, s, changes, null);
|
||||
}
|
||||
else {
|
||||
// This is the merge commit. It has multiple parent commits.
|
||||
@@ -376,10 +391,6 @@ public class GitChangeUtils {
|
||||
|
||||
for (String parent : parents) {
|
||||
final GitRevisionNumber parentRevision = loadRevision(project, root, parent);
|
||||
if (parentRevision == null) {
|
||||
// the repository was cloned with --depth parameter
|
||||
continue;
|
||||
}
|
||||
GitSimpleHandler diffHandler = new GitSimpleHandler(project, root, GitCommand.DIFF);
|
||||
diffHandler.setNoSSH(true);
|
||||
diffHandler.setSilent(true);
|
||||
|
||||
@@ -133,7 +133,7 @@ public class GitRebaseEditor extends DialogWrapper {
|
||||
return;
|
||||
}
|
||||
GitRebaseEntry entry = myTableModel.myEntries.get(row);
|
||||
GitShowAllSubmittedFilesAction.showSubmittedFiles(project, entry.getCommit(), gitRoot);
|
||||
GitShowAllSubmittedFilesAction.showSubmittedFiles(project, entry.getCommit(), gitRoot, false);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -94,7 +94,7 @@ public class GitReferenceValidator {
|
||||
myLastResult = false;
|
||||
try {
|
||||
GitRevisionNumber revision = GitRevisionNumber.resolve(myProject, gitRoot(), revisionExpression);
|
||||
GitShowAllSubmittedFilesAction.showSubmittedFiles(myProject, revision.asString(), gitRoot());
|
||||
GitShowAllSubmittedFilesAction.showSubmittedFiles(myProject, revision.asString(), gitRoot(), false);
|
||||
myLastResult = true;
|
||||
}
|
||||
catch (VcsException ex) {
|
||||
|
||||
@@ -223,7 +223,7 @@ public class GitUnstashDialog extends DialogWrapper {
|
||||
GitUIUtil.showOperationError(myProject, ex, "resolving revision");
|
||||
return;
|
||||
}
|
||||
GitShowAllSubmittedFilesAction.showSubmittedFiles(myProject, resolvedStash, root);
|
||||
GitShowAllSubmittedFilesAction.showSubmittedFiles(myProject, resolvedStash, root, true);
|
||||
}
|
||||
});
|
||||
init();
|
||||
|
||||
Reference in New Issue
Block a user