Skip to content
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

Fix relative paths failing to resolve in diffs #11

Merged
merged 3 commits into from
Nov 20, 2018
Merged

Fix relative paths failing to resolve in diffs #11

merged 3 commits into from
Nov 20, 2018

Conversation

rtzoeller
Copy link
Contributor

What does this Pull Request accomplish?

Fix diffs not resolving relative paths properly.

The previous implementation used git difftool to automatically run a
script against the files that had changed. git difftool automatically
created copies of the files being diffed in a temporary location, but
did not copy rest of the project, causing relative paths to no longer
resolve.

This change removes the use of git difftool, and instead exports a copy
of the repo at the pull request target before invoking the diff
generator on the changed VIs. This allows relative paths to be resolved
correctly, leading to nicer diffs.

This change also enables generating diffs for .vit and .vim files. Fixes #10.

This change also makes running the diffing code locally easier, by pushing
environment variable handling into the Groovy layer and adding argument
parsing to the Python layer.

Why should this Pull Request be merged?

This makes the diffs look a lot nicer, and be significantly more useful.

What testing has been done?

Building a custom device pull request: http://coordinator/job/VeriStand/job/rtzoeller/job/niveristand-chassis-timesync-custom-device/view/change-requests/job/PR-2/18/

Resulting diff bot post: https://github.com/rtzoeller/niveristand-chassis-timesync-custom-device/pull/2

The previous implementation used git difftool to automatically run a
script against the files that had changed. git difftool automatically
created copies of the files being diffed in a temporary location, but
did not copy rest of the project, causing relative paths to no longer
resolve.

This change removes the use of git difftool, and instead exports a copy
of the repo at the pull request target before invoking the diff
generator on the changed VIs. This allows relative paths to be resolved
correctly, leading to nicer diffs.

This change also enables generating diffs for .vit and .vim files.
@rtzoeller rtzoeller added the enhancement New feature or request label Nov 16, 2018
@rtzoeller
Copy link
Contributor Author

I did some additional configuration work on one of the custom devices (making it pull in the testing tools through a submodule) to demonstrate these changes working. Here is a diff with the testing tools being loaded from a submodule and resolving correctly.

Previously we were only importing it on error, since this script was called once per file by git difftool. Now that it is only called once, we should import traceback at the top level.
This is cleaner than changing the working directory of the parent process twice.
Copy link
Collaborator

@buckd buckd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. My python is only passable, but I don't see anything glaring.

@rtzoeller rtzoeller merged commit a741a16 into ni:master Nov 20, 2018
Copy link

@mshafer-NI mshafer-NI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just some thoughts . . .

traceback.print_exc()

with open(working_dir + "\\diff_failures.txt", "a+") as file:
file.write(vi1 + "\n")
with open(output_dir + "\\diff_failures.txt", "a+") as file:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

os.path.join . . .

# and the temporary directory can be returned directly
for root, dirs, files in os.walk(directory.name):
for file in files:
os.chmod(root + "/" + file, stat.S_IWRITE)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

os.path.join . . .


with export_repo(target_branch) as directory:
for status, filename in diffs:
if status == "A":

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"A" ?? this should probably be an enum (if status == difModes.Add.value)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was debating between adding a type and leaving it as a string. We're parsing this from git's output, and we get them back as "A" and "M". Adding a type would make it a little more robust. Good catch.

resources/labview_diff.py Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants