return result
+ def prepareSubmitTemplate(self):
+ # remove lines in the Files section that show changes to files outside the depot path we're committing into
+ template = ""
+ inFilesSection = False
+ for line in read_pipe_lines("p4 change -o"):
+ if inFilesSection:
+ if line.startswith("\t"):
+ # path starts and ends with a tab
+ path = line[1:]
+ lastTab = path.rfind("\t")
+ if lastTab != -1:
+ path = path[:lastTab]
+ if not path.startswith(self.depotPath):
+ continue
+ else:
+ inFilesSection = False
+ else:
+ if line.startswith("Files:"):
+ inFilesSection = True
+
+ template += line
+
+ return template
+
def applyCommit(self, id):
if self.directSubmit:
print "Applying local change in working directory/index"
logMessage = logMessage.replace("\n", "\r\n")
logMessage = logMessage.strip()
- template = read_pipe("p4 change -o")
+ template = self.prepareSubmitTemplate()
if self.interactive:
submitTemplate = self.prepareLogMessage(template, logMessage)
return False
[upstream, settings] = findUpstreamBranchPoint()
- depotPath = settings['depot-paths'][0]
+ self.depotPath = settings['depot-paths'][0]
if len(self.origin) == 0:
self.origin = upstream
if self.verbose:
print "Origin branch is " + self.origin
- if len(depotPath) == 0:
+ if len(self.depotPath) == 0:
print "Internal error: cannot locate perforce depot path from existing branches"
sys.exit(128)
- self.clientPath = p4Where(depotPath)
+ self.clientPath = p4Where(self.depotPath)
if len(self.clientPath) == 0:
- print "Error: Cannot locate perforce checkout of %s in client view" % depotPath
+ print "Error: Cannot locate perforce checkout of %s in client view" % self.depotPath
sys.exit(128)
- print "Perforce checkout for depot path %s located at %s" % (depotPath, self.clientPath)
+ print "Perforce checkout for depot path %s located at %s" % (self.depotPath, self.clientPath)
self.oldWorkingDirectory = os.getcwd()
if self.directSubmit:
if file["action"] == "delete":
self.gitStream.write("D %s\n" % relPath)
else:
- mode = 644
- if file["type"].startswith("x"):
- mode = 755
-
data = file['data']
+ mode = "644"
+ if file["type"].startswith("x"):
+ mode = "755"
+ elif file["type"] == "symlink":
+ mode = "120000"
+ # p4 print on a symlink contains "target\n", so strip it off
+ data = data[:-1]
+
if self.isWindows and file["type"].endswith("text"):
data = data.replace("\r\n", "\n")
- self.gitStream.write("M %d inline %s\n" % (mode, relPath))
+ self.gitStream.write("M %s inline %s\n" % (mode, relPath))
self.gitStream.write("data %s\n" % len(data))
self.gitStream.write(data)
self.gitStream.write("\n")
% (labelDetails["label"], change))
def getUserCacheFilename(self):
- return os.environ["HOME"] + "/.gitp4-usercache.txt"
+ home = os.environ.get("HOME", os.environ.get("USERPROFILE"))
+ return home + "/.gitp4-usercache.txt"
def getUserMapFromPerforceServer(self):
if self.userMapFromPerforceServer:
elif ',' not in self.changeRange:
self.revision = self.changeRange
self.changeRange = ""
- p = p[0:atIdx]
+ p = p[:atIdx]
elif p.find("#") != -1:
hashIdx = p.index("#")
self.revision = p[hashIdx:]
- p = p[0:hashIdx]
+ p = p[:hashIdx]
elif self.previousDepotPaths == []:
self.revision = "#head"
for line in output:
changeNum = line.split(" ")[1]
- changes.append(changeNum)
+ changes.append(int(changeNum))
- changes.reverse()
+ changes.sort()
if len(self.maxChanges) > 0:
- changes = changes[0:min(int(self.maxChanges), len(changes))]
+ changes = changes[:min(int(self.maxChanges), len(changes))]
if len(changes) == 0:
if not self.silent: