Add new perforce variable - How to overload a Private method in the perforce.rb file?

45 views
Skip to first unread message

RandyInLA

unread,
Apr 4, 2012, 10:09:08 PM4/4/12
to Capistrano
Greetings!

My Perforce admin recently decided to force us to add the unicode
variable, "-C utf8", for all perforce transactions. The unicode var
can't be part of :p4sync_flags, nor can it be added as any extra
options. Per the Perforce syntax, it has to live within the existing
Capistrano authentication method. I can hack the actual perforce.rb
file, adding the new variable & update the authentication Private
method to include it, but can't figure out how to overload/override
the authentication method in my recipes! I'd rather either override
the methods in my recipe or submit a change to update Capistrano. I
copied the perforce.rb file, made my changes and pulled out everything
else that shouldn't change:

-----------------------------------------------------------------------------------------------------------
module Capistrano
module Deploy
module SCM

class Perforce < Base
private

# override
def authentication
[ p4port && "-p #{ p4port }",
p4user && "-u #{ p4user }",
p4passwd && "-P #{ p4passwd }",
p4client && "-c #{ p4client }",
p4unicode && "-C #{ p4unicode }" ].compact.join(" ")
end

# new
def p4unicode
variable(:p4unicode)
end

end
end
end
end
-----------------------------------------------------------------------------------------------------------

I've tried putting this in environment.rb, a separate file under /
initializers & deploy.rb, all without success. I currently have it
working by hacking the original perforce.rb file in the rubygem and
that just feels dirty. If anyone can help me override this via my
deploy.rb file or walk me through how to submit a change to
Capistrano, I'd be very grateful!

Thanks!
-=Randy

RandyInLA

unread,
Apr 5, 2012, 5:04:54 PM4/5/12
to Capistrano
After looking at the p4 help for this cli var, I see they call it
charset and not unicode. Changes below:
-----------------------------------------------------------------------------------------------------------
module Capistrano
module Deploy
module SCM

class Perforce < Base
private

# override
def authentication
[ p4port && "-p #{ p4port }",
p4user && "-u #{ p4user }",
p4passwd && "-P #{ p4passwd }",
p4client && "-c #{ p4client }",
p4unicode && "-C #{ p4charset }" ].compact.join(" ")
end

# new
def p4charset
variable(:p4charset)
end

end
end
end
end
-----------------------------------------------------------------------------------------------------------

And in case it wasn't clear, I would add the following to my deploy.rb
file:
set :p4charset, 'utf8'

RandyInLA

unread,
Nov 8, 2012, 4:34:07 PM11/8/12
to capis...@googlegroups.com
I just got bitten by this again today as I updated Capistrano this morning.  I had to hack the perforce.rb file again to make it work.

Can anyone please help me override the private authentication method and add a new variable via my code and not by hacking Capistrano?

Thank you,
-=Randy

Lee Hambley

unread,
Nov 14, 2012, 11:51:31 AM11/14/12
to capis...@googlegroups.com
Randy

Please open an issue at GH issues for this, and someone will take care of it, eventually!

- Lee

--
* You received this message because you are subscribed to the Google Groups "Capistrano" group.
* To post to this group, send email to capis...@googlegroups.com
* To unsubscribe from this group, send email to capistrano+...@googlegroups.com For more options, visit this group at http://groups.google.com/group/capistrano?hl=en

Walker, Randy

unread,
Nov 14, 2012, 12:37:06 PM11/14/12
to capis...@googlegroups.com
Thanks for the reply, Lee!  I already forked, branched, patched the perforce.rb file and created a pull request for Capistrano.  It was merged into master before I woke the next day :)  Should be in the next release, so I'll keep my local monkey patch of perforce.rb for now and won't have to think about it anymore after installing the next version.

-=Randy
Reply all
Reply to author
Forward
0 new messages