-
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
Conversation
Signed-off-by: Mykola Morhun <[email protected]>
Signed-off-by: Mykola Morhun <[email protected]>
Signed-off-by: Mykola Morhun <[email protected]>
items.put(item.substring(2, item.length()), defineStatus(item.substring(0, 1))); | ||
} | ||
changesListPresenter.show(items, REVISION, null, project); | ||
changesListPresenter.show(changedItems, REVISION, null); |
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 call changesListPresenter.show(changedItems, REVISION)
and it would internally recall changesListPresenter.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.
|
||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
if diff.isEmpty()
then you will have an issue
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.
Make sure item.length() > 2
If defineStatus(item.substring(0, 1))
throws IllegalArgumentException
then catch it
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.
To have clear code extract variables for item.substring(2, item.length())
and defineStatus(item.substring(0, 1))
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.
No, it will end up with empty diff
} | ||
|
||
/** | ||
* @return number of files in the diff |
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 prefer not to use single @return
annotation in javadoc, but to have something like: "Returns number of files in the diff"
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.
ok
|
||
changedFilesList = new ArrayList<>(changedFilesStatuses.keySet()); | ||
|
||
length = changedFilesList.size(); |
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.
Redundant field
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.
Just cached. But ok, I'll get rid of it.
private final int length; | ||
|
||
/** | ||
* Creates user-friendly representation of git diff. |
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.
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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
realy? 😄
* | ||
* @author Mykola Morhun | ||
*/ | ||
public class ChangedItems { |
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.
ModifiedFiles ?
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.
What if it is added or deleted?
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 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
How about DiffFiles
?
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 think TouchedItems
is worse. But still open for discussion.
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 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 AlteredFiles
? In general I think we can't just name this class ChangedItems
as it does not reflect it's nature, personally I would split it into several classes something like ChangedItemParser
, ChangedItemHolder
and ChangedItem
itself, what do you think?
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.
AlteredFiles
is good name, think no one will be against it.
As about splitting, I see no point to do this. Constructor just do its own work. Its logic isn't complicated to move into separate class. And according to current representation of diff, storing data into internal object will make it more complicated and add small overhead I think.
this.compareWithLatest = true; | ||
view.setEnableSaveChangesButton(true); | ||
|
||
setupCurrentFile(currentFile); |
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.
You don't setup anything. Rename it respectively.
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 disagree to remove it. But name could be changed, ok.
changedItems.getProject() | ||
.getFile(changedItems.getItemByIndex(currentItemIndex)) | ||
.then(file -> { | ||
if (file.isPresent()) { |
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.
if !file.isPresent()
it means it has been deleted. So, we have to show diff also.
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 catch!
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.
By the way, seems that this is broken in master
* Searches for project with git repository to which given file belongs. | ||
*/ | ||
@Nullable | ||
private Container getGitDir(final File file) { |
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.
getGitRootFolder
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.
See no logical difference here.
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.
Root
means not any
|
||
if (rootProject == null) { | ||
final Container gitDir = getGitDir(file); | ||
if (gitDir == null) { |
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.
Should we notify user with some message?
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.
ok
|
||
CancelCallback cancelCallback = view::hide; | ||
|
||
dialogFactory.createConfirmDialog(locale.compareSaveTitle(), locale.compareSaveQuestion(), locale.buttonYes(), locale.buttonNo(), | ||
confirmCallback, cancelCallback).show(); | ||
} | ||
|
||
@Override | ||
public void onSaveChangesClicked() { | ||
if (compareWithLatest) { |
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.
Why do we have to check if compareWithLatest
?
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.
Just for case.
The Save Changes button should be disabled when compare between revisions is shown.
} | ||
|
||
/** @return relative path of given file from specified project */ | ||
private Path getRelPath(final Container project, final File file) { |
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.
It seems like a method for File
class.
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.
Maybe, but I think it doesn't 'fit' for current File
interface
@@ -29,6 +29,9 @@ button.no=No | |||
button.fetch=Fetch | |||
button.push=Push | |||
button.pull=Pull | |||
button.save_changes=Save Changes | |||
button.next_diff=Next | |||
button.previous_diff=Prev |
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.
Previous
?
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.
Let be so
Build success. https://ci.codenvycorp.com/job/che-pullrequests-build/3329/ |
@@ -75,45 +78,106 @@ public ComparePresenter(AppContext appContext, | |||
} | |||
|
|||
/** | |||
* Show compare window. | |||
* Show compare window for given set of files between given revision and latest code version. |
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.
latest code version
is not clear enough, I think it should be HEAD
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.
Yes, agree
Build success. https://ci.codenvycorp.com/job/che-pullrequests-build/3500/ |
Signed-off-by: Mykola Morhun <[email protected]>
Build # 3557 - FAILED Please check console output at https://ci.codenvycorp.com/job/che-pullrequests-build/3557/ to view the results. |
Signed-off-by: Mykola Morhun <[email protected]>
Build success. https://ci.codenvycorp.com/job/che-pullrequests-build/3558/ |
Signed-off-by: Mykola Morhun <[email protected]>
Build success. https://ci.codenvycorp.com/job/che-pullrequests-build/3560/ |
Build success. https://ci.codenvycorp.com/job/che-pullrequests-build/3570/ |
Signed-off-by: Mykola Morhun <[email protected]>
@vparfonov please review new changes |
@slemeur done. |
@mmorhun : Great ! Where are the docs ;) ? |
Build # 3580 - FAILED Please check console output at https://ci.codenvycorp.com/job/che-pullrequests-build/3580/ to view the results. |
@slemeur well, I wanted to add them ;) , but I failed to find appropriate place. We have some docs in |
Maybe we should create separate page in the docs for using git functionality in CHE to not to mess credentials settings and just IDE details/tips. |
You should move forward and add the information about Git Diff in the user documentation - the page you found is fine. I agree with you that the content of the page
Let's start on adding the docs for this PR. If you are able to start to re-organize the content, that would be perfect, but I'll help you on that. Thanks Mykola. |
break; | ||
case RIGHT: | ||
button.addStyleName(resources.windowCss().buttonAlignRight()); | ||
break; |
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.
add default statement or replace with if..else
Build success. https://ci.codenvycorp.com/job/che-pullrequests-build/3605/ |
What does this PR do?
Next
/Previous
button click.next
andprevious
diff:alt + ,
andalt + .
correspondingly. (actuallyalt
+<
or>
but withoutshift
).What issues does this PR fix or reference?
#5892
Changelog
Added ability to switch between files in Git Diff widget.
Release Notes
In this version, we continued to work on improving Git support in Eclipse Che. We have improved the Git diff window so that it's simpler and faster to review changes between two states of code.
To view the diff, use
Git
->Compare
-><Select-to-what>
from main menu. If more than one file has changed the list of changed files will be opened first. To select a file to compare double-click on it or select a file then click theCompare
button.Your changes are displayed in the left editor and the file being compared to is on the right. The left editor can be used for editing and fixing your changes.
When you have multiple files to review you have the ability to navigate under all the files that are changed. The number of files that are reviewable is displayed in the title of the wizard. Use
Next
andPrevious
buttons to navigate to the next or previous file correspondingly. We also introduce new keyboard shortcut for those actionsAlt + .
forNext
andAlt + ,
forPrevious
.Docs PR
eclipse-che/che-docs#283