2712: [rbtools] post-review command line flag --p4-client and --p4-port does not work when P4CONFIG file is used in a multiple workspaces (perforce servers) scenario

yaqian
david
david
Jan. 31, 2014
What version are you running?
1.6.11, rbtools

What's the URL of the page containing the problem?
It's the post-review command in rbtools has the problem, so no URL.

What steps will reproduce the problem?
1. suppose the following settings for two workspaces on two Perforce Servers. (PerforceServer1 and PerforceServer2)

PerforceServer1 settings:
  server port: PerforceServer1:1666
  workspace name: alice-workspace
  workspace root: d:\perforce1
  env variable P4CONFIG=config.txt
  configure file: d:\perforce1\config.txt
  content of the config file:
     P4PORT=PerforceServer1:1666
     P4CLIENT=alice-workspace
     P4USER=alice

PerforceServer2  settings:
  server port: PerforceServer2:1666
  workspace name: bob-workspace
  workspace root: d:\perforce2
  env variable P4CONFIG=config.txt
  configure file: d:\perforce2\config.txt
  content of the config file:
     P4PORT=PerforceServer2:1666
     P4CLIENT=bob-workspace
     P4USER=bob

2. run post-review from a path under d:\perforce1 to post a changelist that actually lives on PerforceServer2. Initiate the post-review command the following way:
   post-review --p4-port=PerforceServer2:1666 --p4-client=bob-workspace 123456

What is the expected output? What do you see instead?
We expect post-review will post the PerforceServer2 changelist 123456; but it actually try to find the changelist on PerforceServer1

What operating system are you using? What browser?
Win7 + Python 2.6.

Please provide any additional information below.

I did the following research on this issue. Hopefully it will be useful for you to fix it.
--
According to the p4 manuals http://www.perforce.com/perforce/doc.current/manuals/p4guide/02_config.html, we can specify perforce settings such as server port, user, and workspace names using the following methods, listed in ORDER of precedence:

1. On the command line (p4.exe), using flags
2. In a config file, if P4CONFIG is set
3. User environment variables (on UNIX or Windows)
...

which means that cmd line flags > P4CONFIG > env variable.

But when running post-review, if the users has specified the --p4-client and --p4-port flags, the corresponding env variables will be set. In the postreview.py python code, I find the following code:

        if options.p4_client:
           os.environ['P4CLIENT'] = options.p4_client

        if options.p4_port:
           os.environ['P4PORT'] = options.p4_port

but because the env variable P4CONFIG is set and the config file exists, the perforce settings in the config file will override the env variables which was specified from the post-review command line. 

For the example in the reproduce steps, because we're running the post-review from a path under d:\perforce1, the workspace root, the setting in the d:\perforce1\config.txt file will take effect and override the env variables, that's why those --p4-client and --p4-port option does not work.

To solve this issue, the post-review tool should, instead of setting env variables, append those flags to the p4 info and p4 describe command directly because command line flags have the highest precedence.
#1 yaqian
any updates about this issue?
david
#2 david
  • +Component-RBTools
david
#3 david
  • +PendingReview
  • +david
david
#4 david
Fixed in rbtools master (bc65437). This will ship with 0.6.
  • -PendingReview
    +Fixed