-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ability to switch between files in Git Diff widget #5965
Changes from 10 commits
2318d28
28ea7d4
5814596
9f7d30c
88bc819
a3e2c7c
e27895c
72fb977
347b2e0
638153b
9f18acd
3cd740e
f22b649
2f82bec
d148050
5d8744a
6f3ea37
241dca7
a1eac87
18ed447
5a6d745
e1bb8f4
c50272a
69715a6
96fed94
436dc59
286339c
e5208f5
d121a3d
cd6f922
89ad74e
65204e0
c4c0cdf
bea914d
21619ad
eaa74c5
2a1147e
7195d82
e2b5c84
0bd2dd9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,7 @@ | |
import org.eclipse.che.ide.commons.exception.ServerException; | ||
import org.eclipse.che.ide.ext.git.client.DateTimeFormatter; | ||
import org.eclipse.che.ide.ext.git.client.GitLocalizationConstant; | ||
import org.eclipse.che.ide.ext.git.client.compare.FileStatus.Status; | ||
import org.eclipse.che.ide.ext.git.client.compare.ChangedItems; | ||
import org.eclipse.che.ide.ext.git.client.outputconsole.GitOutputConsole; | ||
import org.eclipse.che.ide.ext.git.client.outputconsole.GitOutputConsoleFactory; | ||
import org.eclipse.che.ide.ext.git.client.compare.changespanel.ChangesPanelPresenter; | ||
|
@@ -33,13 +33,9 @@ | |
|
||
import javax.validation.constraints.NotNull; | ||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
import static com.google.common.base.Strings.isNullOrEmpty; | ||
import static com.google.common.collect.Iterables.getFirst; | ||
import static java.util.Arrays.stream; | ||
import static java.util.Collections.singletonList; | ||
|
@@ -50,7 +46,6 @@ | |
import static org.eclipse.che.ide.api.notification.StatusNotification.DisplayMode.NOT_EMERGE_MODE; | ||
import static org.eclipse.che.ide.api.notification.StatusNotification.Status.FAIL; | ||
import static org.eclipse.che.ide.api.notification.StatusNotification.Status.SUCCESS; | ||
import static org.eclipse.che.ide.ext.git.client.compare.FileStatus.defineStatus; | ||
import static org.eclipse.che.ide.util.ExceptionUtils.getErrorCode; | ||
|
||
/** | ||
|
@@ -76,7 +71,7 @@ public class CommitPresenter implements CommitView.ActionDelegate { | |
private final ProcessesPanelPresenter consolesPanelPresenter; | ||
|
||
private Project project; | ||
private Set<String> allFiles; | ||
private List<String> allFiles; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you please explain why we're changing a set for a list? We need to store same files several times? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, we needn't, but git returns modified files in some order, so I just do not want to loose it. Also it is needed to navigate through this list. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. May be |
||
private List<String> filesToCommit; | ||
|
||
@Inject | ||
|
@@ -165,26 +160,18 @@ private void showAskForAmendDialog() { | |
} | ||
|
||
private void show(@Nullable String diff) { | ||
Map<String, Status> files = toFileStatusMap(diff); | ||
ChangedItems changedItems = new ChangedItems(project, diff); | ||
filesToCommit.clear(); | ||
allFiles = files.keySet(); | ||
allFiles = changedItems.getChangedItemsList(); | ||
|
||
view.setEnableCommitButton(!view.getMessage().isEmpty()); | ||
view.focusInMessageField(); | ||
view.showDialog(); | ||
changesPanelPresenter.show(files); | ||
changesPanelPresenter.show(changedItems); | ||
view.setMarkedCheckBoxes(stream(appContext.getResources()).map(resource -> resource.getLocation().removeFirstSegments(1)) | ||
.collect(Collectors.toSet())); | ||
} | ||
|
||
private Map<String, Status> toFileStatusMap(@Nullable String diff) { | ||
Map<String, Status> items = new HashMap<>(); | ||
if (!isNullOrEmpty(diff)) { | ||
stream(diff.split("\n")).forEach(item -> items.put(item.substring(2, item.length()), defineStatus(item.substring(0, 1)))); | ||
} | ||
return items; | ||
} | ||
|
||
@Override | ||
public void onCommitClicked() { | ||
Path location = project.getLocation(); | ||
|
@@ -279,7 +266,7 @@ public void onFileNodeCheckBoxValueChanged(Path path, boolean newCheckBoxValue) | |
} | ||
|
||
@Override | ||
public Set<String> getChangedFiles() { | ||
public List<String> getChangedFiles() { | ||
return allFiles; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2012-2017 Codenvy, S.A. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Codenvy, S.A. - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.che.ide.ext.git.client.compare; | ||
|
||
import org.eclipse.che.ide.api.resources.Project; | ||
import org.eclipse.che.ide.ext.git.client.compare.FileStatus.Status; | ||
|
||
import java.util.ArrayList; | ||
import java.util.LinkedHashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
|
||
import static org.eclipse.che.ide.ext.git.client.compare.FileStatus.defineStatus; | ||
|
||
/** | ||
* Describes changed files in git comparison process. | ||
* | ||
* @author Mykola Morhun | ||
*/ | ||
public class ChangedItems { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ModifiedFiles ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if it is added or deleted? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I dont think that Modified or Changed are good words for this class because such words are present in Git Status. This object can contain not only modified/changed but new or deleted There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure I understand why do we use term Item here if we're talking exactly about files only according to javadoc? What do you think about something like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
private final Project project; | ||
private final LinkedHashMap<String, Status> changedFilesStatuses; | ||
private final List<String> changedFilesList; | ||
private final int length; | ||
|
||
/** | ||
* Creates user-friendly representation of git diff. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you mean user-frendly? How does it related to user? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. well, programmer friendly) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. realy? 😄 |
||
* | ||
* @param project | ||
* the project under diff operation | ||
* @param diff | ||
* plain result of git diff operation | ||
*/ | ||
public ChangedItems(Project project, String diff) { | ||
this.project = project; | ||
|
||
changedFilesStatuses = new LinkedHashMap<>(); | ||
for (String item : diff.split("\n")) { | ||
changedFilesStatuses.put(item.substring(2, item.length()), defineStatus(item.substring(0, 1))); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make sure There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To have clear code extract variables for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, it will end up with empty diff |
||
} | ||
|
||
changedFilesList = new ArrayList<>(changedFilesStatuses.keySet()); | ||
|
||
length = changedFilesList.size(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Redundant field There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just cached. But ok, I'll get rid of it. |
||
} | ||
|
||
public Project getProject() { | ||
return project; | ||
} | ||
|
||
/** | ||
* @return number of files in the diff | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I prefer not to use single There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok |
||
*/ | ||
public int getFilesQuantity() { | ||
return length; | ||
} | ||
|
||
public boolean isEmpty() { | ||
return 0 == length; | ||
} | ||
|
||
public Map<String, Status> getChangedItemsMap() { | ||
return changedFilesStatuses; | ||
} | ||
|
||
public List<String> getChangedItemsList() { | ||
return changedFilesList; | ||
} | ||
|
||
public Status getStatusByPath(String pathToChangedItem) { | ||
return changedFilesStatuses.get(pathToChangedItem); | ||
} | ||
|
||
public Status getStatusByIndex(int index) { | ||
return changedFilesStatuses.get(changedFilesList.get(index)); | ||
} | ||
|
||
public String getItemByIndex(int index) { | ||
return changedFilesList.get(index); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
ChangedItems that = (ChangedItems)o; | ||
return Objects.equals(project, that.project) && | ||
Objects.equals(changedFilesStatuses, that.changedFilesStatuses) && | ||
Objects.equals(changedFilesList, that.changedFilesList); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(project, changedFilesStatuses, changedFilesList); | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I personally don't like methods which can accept null values.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, I don't like it too, but here I see no problem. It is well documented and mean undefined.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit out of the scope however in general I agree with @tolusha. In this very example I would recommend to avoid public method calls with
null
values (even well documented). I think it would be nice if you could add a corresponding method so we could callchangesListPresenter.show(changedItems, REVISION)
and it would internally recallchangesListPresenter.show(changedItems, REVISION, null)
or something similar to this.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good piece of advice, but not for this case, unfortunately...
Otherwise we have to make additional methods with different names (to cover two nullable parameters), which will cause additional logic on the invocations.