Showing posts with label perforce. Show all posts
Showing posts with label perforce. Show all posts

1.06.2015

p4 diff output colorizer

Create a ruby file p4c.rb:
#!/usr/local/bin/ruby -w
# encoding: UTF-8
#
# A simply `p4 diff` output colorizer.
# Got this from:
# http://writequit.org/blog/?p=341

FILE_R = /^====\s+([\s\S]+)(#\d+) - ([\s\S]+) ====$/
POS_R  = /^(\d+[ad]\d+)$/
OUT_R  = /^< /
IN_R   = /^> /

## Escape sequences for colors
## Misc
$RESET = "\033[0m"
$BOLD = "\033[1m"
$BLINK = "\033[5m"

## Foreground colors
$BLACK = "\033[30m"
$RED = "\033[31m"
$GREEN = "\033[32m"
$BROWN = "\033[33m"
$BLUE = "\033[34m"
$MAGENTA = "\033[35m"
$CYAN = "\033[36m"
$WHITE = "\033[37m"

$stdin.each_line do |line|
  line.chomp!
  if line =~ FILE_R
    puts "#{$MAGENTA}" + line + "#{$RESET}"
  elsif line =~ POS_R
    puts "#{$CYAN}" + line + "#{$RESET}"
  elsif line =~ OUT_R
    puts "#{$RED}" + line + "#{$RESET}"
  elsif line =~ IN_R
    puts "#{$GREEN}" + line + "#{$RESET}"
  else
    puts line
  end
end
You can call it like this...
$ p4 diff Module.pm | ~/bin/p4c.rb
# or with an alias: colorize='~/bin/p4c.rb'
$ p4 diff Module.pm | colorize

12.13.2014

Perforce Client Setup

I got it from here.
1. Export environment variable
$ export P4CONFIG=.p4config

2. Create workspace directory
$ cd /auto/home/delacs/projects/autoselect_feature
$ mkdir code

3. Create p4 config file, name of client will be 'delacs-autoselect-feature'
$ vi .p4config
P4CLIENT=delacs-autoselect-feature
P4PORT=server.domain.com:1666

4. Create the client
$ p4 client

In text editor:
Client: delacs-autoselect-feature
Root:  /auto/home/delacs/projects/autoselect_feature
View: //tools/main/perf/scripts/scheduler/... //delacs-autoselect-feature/code/scheduler/...
      //tools/parser/... //delacs-autoselect-feature/code/parser/...

5. Now, let's pull down code from perforce
$ p4 sync

11.13.2013

Perforce Cheat Sheet

1. New client spec for workspace
$ p4 client
2. Populate workspace with files from server
$ p4 sync
$ p4 sync * - only files from current dir
$ p4 sync ... - current path, all folders and files underneath
$ p4 sync -f filename - force the sync, override no clobber (lose all local changes)
$ p4 sync @490807 - sync to changelist number
$ p4 sync @=490807 - sync only the files revised within that changelist
3. Check out a file for edit
$ p4 edit filename
4. See checked out files
$ p4 opened
$ p4 have filename - what version you have
$ p4 filelog filename - check history
5. View local changes
$ p4 diff
$ p4 diff filename | p4c.rb - colored diff
$ p4 diff -db filename - disregard whitespace
$ p4 diff -t filename - even though files aren't text
6. Create new changelist
$ p4 change
$ p4 change -u changelist_number - update submitted changelist
7. Add files for addition to the depot
$ p4 add
$ p4 add -c change_number -f filenames - add files to changelist
$ p4 add -f filenames - add files to default changelist
$ p4 add -c change_number * */* - add files in current dir and next dir to default changelist
$ "find . -type f | p4 -x - add" - cmd inside quotes would find all files in a directory structure and add them all in
8. Get info about a changelist, listing files that are included
$ p4 describe change_number
9. Get a list of your changes
$ p4 changes -u username
$ p4 changes -u username -s pending
10. Discard changes made to open files
$ p4 revert -c change_number - reverts only those files in the specified changelist
$ p4 revert filename - reverts only this file
11. Submit changes for code review
$ /auto/tools/bin/post-review change_number
12. Checkin your changes
$ p4 submit
$ p4 submit -c change_number
13. Delete pending changelist
$ p4 changes -u username -s pending
$ p4 revert -c 12345 //... - revert all files in my pending changelist 12345
$ p4 change -d 12345 - delete the now-empty changelist
14. Print detailed information about file revisions.
$ p4 filelog filename
15. Add opened files to a specific changelist
$ p4 reopen -c 431494 */*
16. Get specific change information
$ p4 changes //prod/main/...\@445029,445029
Change 445029 on 2014/08/10 by sdc@main:sdc 'Integrate change 444241 from 5.'
17. Move (or rename) a file from one location to another
$ p4 move deploy/deploy_change util/deploy_change
18. Move a directory
$ p4 edit 5.5/*/baseline.xml
$ p4 move 5.5/... 5.5_old/...
18. Take a peek at the branches available
$ p4 branches | grep "5\.6\.0"
19. Delete file
$ p4 delete filename
20. Change file type into executable
$ p4 edit -t +x watchdog