I was reading the following article which is basically covering the -m flag for faster operation. However, when I'm looking to the docs, the -m command is not listed. Thoughts?
The -m flag is described in p4 help clean as follows:
The -m flag used in conjunction with -e can be used to minimize
costly digest computation on the client by checking file modification
times before checking digests to determine if files have been
modified outside of Perforce.
(You can probably ignore the part about -e since edited files are included by default anyway -- that note is just to let you know that if you're explicitly only checking for added/deleted files there's no benefit gained from modtimes.)
It's directly analogous to the equivalent option on reconcile. (clean is essentially a synonym for reconcile -w so the two commands have very similar options.)
Related
I have this command:
git checkout -b <name>
What does -b do in this command? Where can I read about such commands in git and in the terminal in particular?
The -b option specifies a git branch to check out.
For more information, view the git documentation.
The description of the -b option in the git documentation is a little dense:
git checkout -b|-B <new_branch> [<start point>]
Specifying -b causes a new branch to be created as if
git-branch[1] were called and then checked out. In this case you can
use the --track or --no-track options, which will be passed to git
branch. As a convenience, --track without -b implies branch
creation; see the description of --track below.
If -B is given, <new_branch> is created if it doesn’t exist;
otherwise, it is reset. This is the transactional equivalent of
$ git branch -f <branch> [<start point>]
$ git checkout <branch>
that is to say, the branch is not reset/created unless "git checkout"
is successful.
They are command options or parameters.
Commands can take many different options as input, and usually (but not always) these options are prefixed by - or --, followed by a letter or word, and then sometimes followed again by a value for that option.
For git checkout the -b option allows you to specify a value for branch name.
You can type git --help to view high level options or git checkout -h to find out about options specific to checkout function. However, Git being a large complex tool, has many many options so suggest to check out the official documentation online, rather than only the built in help on terminal.
Getting help for terminal commands in general: For most commands, you can type <command> --help or try -h if that didn't work. To read the long-form manual for a command type man <command>. To search through a list of all available commands try apropros <search terms> to find one you want.
BONUS TIP: If you are new to Linux terminal in general, and want to learn various commands quickly without having to google a lot, may I suggest installing the tldr tool.
sudo apt install tldr
Once installed via the above command, you can run tldr <command name>.
For example try tldr tar and it gives you some nice examples about how to use the tool.
I have the problem with macOS mojave, but I guess it generalizes to all bash environment. In the .bashrc or .profile, I add one line as:
alias gc="git add .;git commit --message="$(date +"iMac_%D_%T")""
My purpose is to send the current system time as a message when commiting a change by typing gc. However, the system time was read when alias was invoked (here is when I log in the system).
Can anyone help me out? Thank you in advance!
The simpler approach is to make this a shell function and not an alias at all:
gc() {
git add . && git commit --message="$(date +"iMac_%D_%T")" "$#"
}
That said, as a matter of good git hygeine, I strongly advise against doing this; you'll get output files and temporary files you don't want checked in. git commit -a, by not adding new files, is somewhat safer -- though using git add -p to review changes hunk-by-hunk is by far the best practice to avoid mixing unrelated and unwanted changes into your commits.
Is it possible to use variables defined in P4CONFIG files in p4 commands? Let's say I want to define an alias for quickly seeing pending changelists in the current workspace. So something like:
p4 changes -s pending -c $P4CLIENT
I don't want to define P4CLIENT in my bashrc as I switch between different workspaces a lot. I much prefer it to come from the current P4CONFIG file. Is that possible?
This should do it:
p4 -Ztag -F %clientName% info | p4 -x - changes -s pending -c
Note that you need a relatively current p4 client to use the undoc -F flag, which is described more here: http://www.perforce.com/blog/130826/fun-formatting
You could also script something around "p4 set P4CLIENT", which is a purely client-side query and therefore a bit faster, but you'll need to manipulate the output a bit to make it suitable as an argument to "p4 changes".
I am looking for a generic command line solution that would allow me to add or modify a configuration option inside a config file (INI-like format).
Most Linux configuration files use a INI-like format, with # and ; as comment and with option=value.
Mainly I am looking for something that would take filename, option and value, and that will change the config to match this.
I want to use this to write some auto-deployment scripts. I have no problem on using tools that are not installed by default on Debian or Ubuntu as long they do exist in the default distribution repositories (as I can do an apt-get install xxx, if needed).
Example: change-config /etc/default/nginx ULIMIT '"-n 4096"'
The expected result would be to have ULIMIT="-n 4096" inside the nginx file. Obviously if it does already exists and have the same value, it should do nothing. If it exists, commenting the old line would be fine and adding the new one.
As a note, these config files can have spaces/tabs between parameters so if you have ULIMIT = "..." is still the same command. That's why I was looking for something better than sed as there are plenty of corner cases to evaluate.
Also, I don't want to reinvent the wheel, and I doubt that I am the first one to look for a solution to this kind of problem.
git config is actually a semi-generic INI interface.
❱ git config --file=/etc/default/nginx somegroup.ULIMIT '-n 4096'
❱ cat /etc/default/nginx
[somegroup]
ULIMIT = -n 4096
❱ git config --file=/etc/default/nginx somegroup.ULIMIT
"-n 4096"
It doesn't support adding top-level keys, though. All keys have to be placed in an INI style group, hence the "somegroup." above. That makes it unsuitable for your task, but I thought I'd mention it here for others finding their way here.
Try crudini. BTW I think this file is a shell file rather than an ini file,
but crudini can still work in this case:
crudini --set /etc/default/nginx '' ULIMIT '"-n 4096"'
Augeas / augtool aims to do this, although you'll need the right lens for the type of file you're after (you can also write your own), for example, the Nginx lens.
It also has an API if required.
Not sure if this is possible or not, but I figured I'd ask to see if anyone knows. Is it possible to find a file containing a string in a Perforce repository? Specifically, is it possible to do so without syncing the entire repository to a local directory first? (It's quite large - I don't think I'd have room even if I deleted lots of stuff - that's what the archive servers are for anyhow.)
There's any number of tools that can search through files in a local directory (I personally use Agent Ransack, but it's just one of many), but these will not search a remote Perforce directory, unless there's some (preferably free) tool I'm not aware of that has this capability, or maybe some hidden feature within Perforce itself?
p4 grep is your friend. From the perforce blog
'p4 grep' allows users to use simple file searches as well as regular
expressions to search through file contents of head as well as earlier
revisions of files stored on the server. While not every single option
of a standard grep is supported, the most important options are
available. Here is the syntax of the command according to 'p4 help
grep':
p4 grep [ -a -i -n -v -A after -B before -C context -l -L -t -s -F -G ] -e pattern file[revRange]...
See also, the manual page.
Update: Note that there is a limitation on the number of files that Perforce will search in a single p4 grep command. Presumably this is to help keep the load on the server down. This manifests as an error:
Grep revision limit exceeded (over 10000).
If you have sufficient perforce permissions, you can use p4 configure to increase the dm.grep.maxrevs setting from this default of 10K to something larger. e.g. to set to 1 million:
p4 configure set dm.grep.maxrevs=1M
If you do not have permission to change this, you can work around it by splitting the p4 grep up into multiple commands over the subdirectories. You may have need to split further into sub-subdirectories etc depending on your depot structure.
For example, this command can be used at a bash shell to search each subdirectory of //depot/trunk one at a time. Makes use of the p4 dirs command to obtain the list of subdirectories from the server.
for dir in $(p4 dirs //depot/trunk/*); do
p4 grep -s -i -e the_search_string $dir/...
done
Actually, solved this one myself. p4 grep indeed does the trick. Doc here. You have to carefully narrow it down before it'll work properly - on our server at least you have to get it down to < 10000 files. I also had to redirect the output to a file instead of printing it out in the console, adding > output.txt, because there's a limit of 4096 chars per line in the console and the file paths are quite long.
It's not something you can do with the standard perforce tools. One helpful command might be p4 print but it's not really faster than syncing I would think.
This is a big if but if you have access to the server you can run agent ransack on the perforce directory. Perforce stores all versioned files on disk, it's only the metadata that's in a database.