Jump to content


get client name


  • Please log in to reply
16 replies to this topic

#1 JoeRiel

JoeRiel

    Member

  • Members
  • PipPip
  • 19 posts

Posted 06 March 2019 - 09:19 PM

Is there a shell command that returns the current client name?  My interest is to use it in the -c option to p4 changes to limit the output to the current client.  It would be nice if p4 changes had an option for that, rather than requiring one to enter the current client.

#2 Sambwise

Sambwise

    Advanced Member

  • Members
  • PipPipPip
  • 917 posts

Posted 06 March 2019 - 09:55 PM

From the command line you can do either "p4 set P4CLIENT" or "p4 info". The various APIs all have some equivalent of "p4 set P4CLIENT", e.g. ClientApi::GetClient in the C++ API, and all the APIs can run server commands like "info" directly.

Quote

My interest is to use it in the -c option to p4 changes to limit the output to the current client.  It would be nice if p4 changes had an option for that, rather than requiring one to enter the current client.

Typically in a command line context if you wanted changes made in the current client's view you'd just use a local path, e.g.:

p4 changes ...


#3 JoeRiel

JoeRiel

    Member

  • Members
  • PipPip
  • 19 posts

Posted 07 March 2019 - 12:01 AM

Using p4 set -q P4CLIENT should allow me to parse that, thanks.  The local setting doesn't work because I want to access the changes while at a lower level.  Am using this to get the last change.  Maybe there is a better way:

#!/bin/bash

client=$(p4 set -q P4CLIENT | cut -c10-)
user=$(p4 set -q P4USER | cut -c8-)
p4 changes -u ${user} -m1 -c ${client} | cut -d\  -f2

#4 Sambwise

Sambwise

    Advanced Member

  • Members
  • PipPipPip
  • 917 posts

Posted 07 March 2019 - 12:30 AM

How much can you say about the tool you're building?  :)  It seems like something along the lines of "p4 changes --me -m1" might work well enough, but I'm not sure I correctly understand the intent of the user/client scoping here.

#5 JoeRiel

JoeRiel

    Member

  • Members
  • PipPip
  • 19 posts

Posted 07 March 2019 - 12:49 AM

It's hardly a tool---that script is it.  Basically I name it p4last and use it to access my latest change in the appropriate client. Avoids having to remember the number, for example

p4 reopen -c $(p4last) newfile

I didn't know about the --me option; it doesn't show up in either the help page or the usage line. Will use that instead, but still need the -c client option.  Or is there a long-style keyword for that?

#6 Sambwise

Sambwise

    Advanced Member

  • Members
  • PipPipPip
  • 917 posts

Posted 07 March 2019 - 12:54 AM

p4 reopen -c $(p4last) newfile


Ah!  That won't work with a submitted change, which is what your tool is going to return most of the time.  :)  Could you explain any further what sort(s) of workflow this tool is supposed to be part of?  What tasks do you normally do where you need to know the "latest change"?  (I'm trying to figure out whether when you say "latest change" you mean "latest submitted change in this stream", or "pending change I last worked on", or what...)

#7 JoeRiel

JoeRiel

    Member

  • Members
  • PipPip
  • 19 posts

Posted 07 March 2019 - 01:05 AM

This is for pending changes., which have been (usually) shelved. The basic workflow is I create a changelist which is then shelved. That shelve is used to do automated testing.  Depending on the results of the test I may have to add more files to the changelist and reshelve and retest, until it is ready to submit.  So I'd like an easy way to refer to the latest shelve.  I may be working on several changes, but most of the time not, so the last one is usually what I want.  If it's not, I'll just enter the number.

#8 Sambwise

Sambwise

    Advanced Member

  • Members
  • PipPipPip
  • 917 posts

Posted 07 March 2019 - 01:16 AM

How often do you switch clients?  "My most recent shelved change" would be "p4 changes --me -s shelved"; it'd only be unsuitable for your purpose if you'd just shelved a change from a different client.

If the client part is important though, and you want pending changes rather than shelved changes specifically, and you want to just get the change number so you can pipe it into something else, I think you can do a one-liner like:

p4 -F "changes -m1 -s pending --me -c %clientName%" -Ztag info | p4 -F "%change%" -Ztag -x - run


#9 JoeRiel

JoeRiel

    Member

  • Members
  • PipPip
  • 19 posts

Posted 07 March 2019 - 02:29 AM

I change clients frequently because I work on multiple projects, each under a different client.

Where are the -F and -Ztag options explained?  What version of p4 is needed for them?  I have Rev. P4/LINUX26X86_64/2018.2/1724420 (2018/11/02).

#10 Sambwise

Sambwise

    Advanced Member

  • Members
  • PipPipPip
  • 917 posts

Posted 07 March 2019 - 04:41 AM

2018.2 should definitely be new enough.

https://www.perforce.../fun-formatting

See "p4 help usage" for info on documented global opts and "p4 help undoc" for info on undocumented everything.  :)

#11 JoeRiel

JoeRiel

    Member

  • Members
  • PipPip
  • 19 posts

Posted 07 March 2019 - 05:32 PM

Thanks, will check out the undoc.  Is there a perforce setting so that p4 help is automatically piped to more or something similar?  I invariably do p4 help ... | more, but it would be nice to have that automatic.

#12 Sambwise

Sambwise

    Advanced Member

  • Members
  • PipPipPip
  • 917 posts

Posted 07 March 2019 - 05:36 PM

P4PAGER maybe?  Never used it, I forget if it applies to "p4 help" output.

I guess now that there's command aliases you could probably do it that way too...

#13 JoeRiel

JoeRiel

    Member

  • Members
  • PipPip
  • 19 posts

Posted 08 March 2019 - 06:52 PM

I haven't quite got your suggestion to work.  Is -c %clientName% literally what I'm supposed to use, where p4 will substitute the name of the current client for %clientName%?

#14 Sambwise

Sambwise

    Advanced Member

  • Members
  • PipPipPip
  • 917 posts

Posted 08 March 2019 - 06:57 PM

In the context of a format string, it should if the command you're running outputs clientName as part of its output dict.  I might have remembered it wrong -- run "p4 -Ztag info" by itself to see all the keys that "p4 info" returns in tagged mode.  One of those SHOULD be the client name (it might be "%client%" instead of "%clientName" like it is most places).

#15 JoeRiel

JoeRiel

    Member

  • Members
  • PipPip
  • 19 posts

Posted 08 March 2019 - 07:13 PM

Oh, I see.  It returns the value of the client field.  Not quite what I'm looking for.  Seems surprising to me that there isn't an option for the changes commands to restrict it to the current client.  What is the "run" at the end of your suggested command supposed to be?

#16 Sambwise

Sambwise

    Advanced Member

  • Members
  • PipPipPip
  • 917 posts

Posted 08 March 2019 - 07:44 PM

That's to run the "changes" command that gets you the output you want (right?  you wanted the last pending change from your user+client?)

It's possible that I bungled the syntax (I don't have p4 installed on this machine so I'm going from memory), but if it's not working, post the error message and I can probably figure out what I goofed.  :unsure:

#17 JoeRiel

JoeRiel

    Member

  • Members
  • PipPip
  • 19 posts

Posted 08 March 2019 - 09:05 PM

Hmm. Actually it is working properly.  Maybe I copied it incorrectly the first time. I looked it over carefully and now see what it is doing.  Thanks much.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users