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

Adjusting SVN commands to consider the @ symbol #4551

Merged
merged 10 commits into from
Jul 30, 2018

Conversation

ffeu
Copy link
Contributor

@ffeu ffeu commented Jul 25, 2018

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same change?
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes? Here's an example.
  • Have you successfully run brew style with your changes locally?
  • Have you successfully run brew tests with your changes locally?

Details

This is another approach to solve problem presented by the #4358 PR.

Subversion uses '@' to point to a specific revision, so when creating formulas with an @ symbol, the local svn path inherits that character and Subversion gets confused.

Basically, an additional @ at the end solves it. So no need to change the paths, it's justing changing the commands.

However, this is not consistent through all commands. The commands are affected as follows:

svn checkout url1 foo@a   # properly checks out url1 to foo@a
svn switch url2 foo@a     # properly switchs foo@a to url2
svn update foo@a@         # properly updates foo@a 
svn info foo@a@           # properly obtains info on foo@a 
svn export foo@a@ newdir  # properly export foo@a contents to newdir

As previously discussed in the #4358 PR, this approach:

  • affects only SVN resources;
  • doesn't change current path used for svn repositories
  • it's expected to NOT interfere with cleanup or mirror

brew style is OK with my changes, but there were warnings unrelated to this PR.

Disclaimer

I kindly request special attention reviewing this PR, as my ruby experience is equal to 28 lines of code (this PR). :)

end

def svn_cached_location
escape(cached_location)
Copy link
Member

Choose a reason for hiding this comment

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

Just use escape(cached_location) everywhere instead of svn_cached_location.

Copy link
Member

Choose a reason for hiding this comment

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

Also this should be reused for the unpack strategy.

end

private

def escape(svn_url)
Copy link
Member

Choose a reason for hiding this comment

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

Should this be a URL or a path?

args << target
target_arg = target.to_s
target_arg = escape(target_arg) if svncommand == "up"
args << target_arg
Copy link
Member

Choose a reason for hiding this comment

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

Can you reorder this a bit? Currently we have to check twice for target.directory? and once for svncommand == "up", which all check for the same thing.

@ffeu
Copy link
Contributor Author

ffeu commented Jul 25, 2018

Hi @reitermarkus, done!

  • removed the svn_cached_location(),
  • renamed escape(url) to svn_escape(path)
  • placed svn_escape() inside unpack_strategy/subversion.rb **
    ** Not sure if that would be the best place though - let me know!

@MikeMcQuaid
Copy link
Member

Thanks for the detailed and great first PR! CC @apjanke for thoughts on this as he'd worked on similar recently.

args << target
elsif svncommand == "update"
args << svn_escape(target)
end
Copy link
Member

Choose a reason for hiding this comment

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

It's still checking for the same thing twice. Make this

args = if target.directory?
  ["svn", "update", svn_escape(target)]
else
  ["svn", "checkout", url, target]
end

That make me think: Is svn update target the same as cd target; svn update?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(args)
Oh, that's indeed way better. I didn't see it and I'm blaming my lack of ruby skills! ;-)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@reitermarkus , about the cd target

Yes, the effect of cd target@peg; svn update is the same as svn update target@peg@ - to the repository, at least.

I thought of that but as I was not sure if or how brew could get affected to these path changes, I kept with this "maybe more conservative approach". As per your comment I looked a bit further and decided to give it a try.

So the export command ended up like this and worked fine (thanks to the chdir).

      system_command! "svn", 
                      args: ["export", "--force", ".", unpack_dir],
                      chdir: path.to_s

The update looked like this and it worked (note: no output is read from it).

    args = if target.directory?
      ["cd", target.to_s, ";", "svn", "update"]
    else
      ["svn", "checkout", url, target]
    end

However, I could not make the svn info work with popen_read. It's used by the methods last_commit, repo_url and source_modified_time. Looks like popen_read keeps returning the output of the first command (cd).

Tried this:

    xml = REXML::Document.new(Utils.popen_read("cd", cached_location.to_s, ";", "svn", "info", "--xml"))

and even tried with &> /dev/null:

    xml = REXML::Document.new(Utils.popen_read("cd", cached_location.to_s, "&> /dev/null;", "svn", "info", "--xml"))

In the end, even if we manage to get past this problem in svn info, I think the svn_escape() is easier to read and may be easier to understand in the future.

One option would be bringing svn_escape() back to download_strategy and using it only there, leaving the export command with the chdir.

What do you think?

Copy link
Member

Choose a reason for hiding this comment

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

Instead of popen_read you can also use system_command. It returns a result which you can call stdout on.

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 didn't test with system_command yet, but do you think this is better?

# with svn_escape
xml = REXML::Document.new(Utils.popen_read( "svn", "info", "--xml", svn_escape(cached_location)))
...
# so far, with system_command, cd ..; & .stdout
xml = REXML::Document.new(system_command("cd", cached_location.to_s, ";", "svn", "info", "--xml").stdout)

To me it seems less obscure using svn_escape... and there's the possibility that more adjustments might have to be done (as it didn't work already with popen_read).

Copy link
Member

@reitermarkus reitermarkus Jul 29, 2018

Choose a reason for hiding this comment

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

info = system_command("svn", args: ["info", "--xml"], chdir: cached_location)
         .stdout
xml = REXML::Document.new(info)

@ffeu
Copy link
Contributor Author

ffeu commented Jul 29, 2018

OK, @reitermarkus, please check latest changes, I've tested and it's working.

  1. But now Subversion is the only place using system_command in the download_strategy, everywhere else uses quiet_system and safe_system, or popen_read when reading output. As you probably know the difference between them, is that alright?

  2. Now the args part ended up being the only place with cd ...; svn. I thought of changing it to:

    args = target.directory? ? ["update"] : ["checkout", url, target]
    if revision
      ohai "Checking out #{@ref}"
      args << "-r" << revision
    end
    args << "--ignore-externals" if ignore_externals
    if args[0] == "update"
      system_command("svn", args: args, chdir: target.to_s)
    else
      system_command("svn", args: args)
    end

Which works, but the output of svn update and checkout are not being shown to the user anymore - I imagine that's no problem but I wanted to double check. If that last bit is OK I'll push it.

args << url unless target.directory?
args << target
args = if target.directory?
["cd", target.to_s, ";", "svn", "update"]
Copy link
Member

Choose a reason for hiding this comment

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

This also needs to use system_command! with chdir:.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's what I meant with my last comment, I wanted to check because of the
check if args[0] == "update"...

Copy link
Member

@reitermarkus reitermarkus left a comment

Choose a reason for hiding this comment

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

One last change, then I think this is good to go.

if revision
ohai "Checking out #{@ref}"
args << "-r" << revision
end
args << "--ignore-externals" if ignore_externals
safe_system(*args)
if args[0] == "update"
Copy link
Member

Choose a reason for hiding this comment

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

Make this target.directory?.

args = ["svn", svncommand]
args << url unless target.directory?
args << target
args = target.directory? ? ["update"] : ["checkout", url, target]
Copy link
Member

Choose a reason for hiding this comment

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

Make this an empty array and insert the args from here below like this.

system_command("svn", args: ["update", *args], chdir: target.to_s)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done!

@reitermarkus reitermarkus merged commit b5548f9 into Homebrew:master Jul 30, 2018
@reitermarkus
Copy link
Member

Thanks, @ffeu, great work!

@apjanke
Copy link
Contributor

apjanke commented Jul 30, 2018

Sorry for the slow reply; I've been traveling.

This looks like a good approach to me.

@ffeu ffeu deleted the fix_svn_with_at_symbol branch July 30, 2018 19:11
@lock lock bot added the outdated PR was locked due to age label Aug 29, 2018
@lock lock bot locked as resolved and limited conversation to collaborators Aug 29, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated PR was locked due to age
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants