@@ -834,6 +834,8 @@ class P4Submit(Command):
834
834
return True
835
835
836
836
class P4Sync (Command ):
837
+ delete_actions = ( "delete" , "move/delete" , "purge" )
838
+
837
839
def __init__ (self ):
838
840
Command .__init__ (self )
839
841
self .options = [
@@ -882,6 +884,23 @@ class P4Sync(Command):
882
884
if gitConfig ("git-p4.syncFromOrigin" ) == "false" :
883
885
self .syncWithOrigin = False
884
886
887
+ #
888
+ # P4 wildcards are not allowed in filenames. P4 complains
889
+ # if you simply add them, but you can force it with "-f", in
890
+ # which case it translates them into %xx encoding internally.
891
+ # Search for and fix just these four characters. Do % last so
892
+ # that fixing it does not inadvertently create new %-escapes.
893
+ #
894
+ def wildcard_decode (self , path ):
895
+ # Cannot have * in a filename in windows; untested as to
896
+ # what p4 would do in such a case.
897
+ if not self .isWindows :
898
+ path = path .replace ("%2A" , "*" )
899
+ path = path .replace ("%23" , "#" ) \
900
+ .replace ("%40" , "@" ) \
901
+ .replace ("%25" , "%" )
902
+ return path
903
+
885
904
def extractFilesFromCommit (self , commit ):
886
905
self .cloneExclude = [re .sub (r"\.\.\.$" , "" , path )
887
906
for path in self .cloneExclude ]
@@ -976,6 +995,7 @@ class P4Sync(Command):
976
995
return
977
996
978
997
relPath = self .stripRepoPath (file ['depotFile' ], self .branchPrefixes )
998
+ relPath = self .wildcard_decode (relPath )
979
999
if verbose :
980
1000
sys .stderr .write ("%s\n " % relPath )
981
1001
@@ -1054,10 +1074,10 @@ class P4Sync(Command):
1054
1074
1055
1075
if includeFile :
1056
1076
filesForCommit .append (f )
1057
- if f ['action' ] not in ('delete' , 'move/delete' , 'purge' ):
1058
- filesToRead .append (f )
1059
- else :
1077
+ if f ['action' ] in self .delete_actions :
1060
1078
filesToDelete .append (f )
1079
+ else :
1080
+ filesToRead .append (f )
1061
1081
1062
1082
# deleted files...
1063
1083
for f in filesToDelete :
@@ -1143,7 +1163,7 @@ class P4Sync(Command):
1143
1163
1144
1164
cleanedFiles = {}
1145
1165
for info in files :
1146
- if info ["action" ] in ( "delete" , "purge" ) :
1166
+ if info ["action" ] in self . delete_actions :
1147
1167
continue
1148
1168
cleanedFiles [info ["depotFile" ]] = info ["rev" ]
1149
1169
@@ -1445,7 +1465,7 @@ class P4Sync(Command):
1445
1465
print "Doing initial import of %s from revision %s into %s" % (' ' .join (self .depotPaths ), revision , self .branch )
1446
1466
1447
1467
details = { "user" : "git perforce import user" , "time" : int (time .time ()) }
1448
- details ["desc" ] = ("Initial import of %s from the state at revision %s"
1468
+ details ["desc" ] = ("Initial import of %s from the state at revision %s\n "
1449
1469
% (' ' .join (self .depotPaths ), revision ))
1450
1470
details ["change" ] = revision
1451
1471
newestRevision = 0
@@ -1456,17 +1476,24 @@ class P4Sync(Command):
1456
1476
% (p , revision )
1457
1477
for p in self .depotPaths ])):
1458
1478
1459
- if info ['code' ] == 'error' :
1479
+ if 'code' in info and info ['code' ] == 'error' :
1460
1480
sys .stderr .write ("p4 returned an error: %s\n "
1461
1481
% info ['data' ])
1482
+ if info ['data' ].find ("must refer to client" ) >= 0 :
1483
+ sys .stderr .write ("This particular p4 error is misleading.\n " )
1484
+ sys .stderr .write ("Perhaps the depot path was misspelled.\n " );
1485
+ sys .stderr .write ("Depot path: %s\n " % " " .join (self .depotPaths ))
1486
+ sys .exit (1 )
1487
+ if 'p4ExitCode' in info :
1488
+ sys .stderr .write ("p4 exitcode: %s\n " % info ['p4ExitCode' ])
1462
1489
sys .exit (1 )
1463
1490
1464
1491
1465
1492
change = int (info ["change" ])
1466
1493
if change > newestRevision :
1467
1494
newestRevision = change
1468
1495
1469
- if info ["action" ] in ( "delete" , "purge" ) :
1496
+ if info ["action" ] in self . delete_actions :
1470
1497
# don't increase the file cnt, otherwise details["depotFile123"] will have gaps!
1471
1498
#fileCnt = fileCnt + 1
1472
1499
continue
@@ -1709,6 +1736,8 @@ class P4Sync(Command):
1709
1736
1710
1737
changes .sort ()
1711
1738
else :
1739
+ if not self .p4BranchesInGit :
1740
+ die ("No remote p4 branches. Perhaps you never did \" git p4 clone\" in here." );
1712
1741
if self .verbose :
1713
1742
print "Getting p4 changes for %s...%s" % (', ' .join (self .depotPaths ),
1714
1743
self .changeRange )
@@ -1789,10 +1818,13 @@ class P4Clone(P4Sync):
1789
1818
help = "where to leave result of the clone" ),
1790
1819
optparse .make_option ("-/" , dest = "cloneExclude" ,
1791
1820
action = "append" , type = "string" ,
1792
- help = "exclude depot path" )
1821
+ help = "exclude depot path" ),
1822
+ optparse .make_option ("--bare" , dest = "cloneBare" ,
1823
+ action = "store_true" , default = False ),
1793
1824
]
1794
1825
self .cloneDestination = None
1795
1826
self .needsGit = False
1827
+ self .cloneBare = False
1796
1828
1797
1829
# This is required for the "append" cloneExclude action
1798
1830
def ensure_value (self , attr , value ):
@@ -1832,11 +1864,16 @@ class P4Clone(P4Sync):
1832
1864
self .cloneDestination = self .defaultDestination (args )
1833
1865
1834
1866
print "Importing from %s into %s" % (', ' .join (depotPaths ), self .cloneDestination )
1867
+
1835
1868
if not os .path .exists (self .cloneDestination ):
1836
1869
os .makedirs (self .cloneDestination )
1837
1870
chdir (self .cloneDestination )
1838
- system ("git init" )
1839
- self .gitdir = os .getcwd () + "/.git"
1871
+
1872
+ init_cmd = [ "git" , "init" ]
1873
+ if self .cloneBare :
1874
+ init_cmd .append ("--bare" )
1875
+ subprocess .check_call (init_cmd )
1876
+
1840
1877
if not P4Sync .run (self , depotPaths ):
1841
1878
return False
1842
1879
if self .branch != "master" :
@@ -1846,7 +1883,8 @@ class P4Clone(P4Sync):
1846
1883
masterbranch = "refs/heads/p4/master"
1847
1884
if gitBranchExists (masterbranch ):
1848
1885
system ("git branch master %s" % masterbranch )
1849
- system ("git checkout -f" )
1886
+ if not self .cloneBare :
1887
+ system ("git checkout -f" )
1850
1888
else :
1851
1889
print "Could not detect main branch. No checkout/master branch created."
1852
1890
0 commit comments