@matheusbsbs / matheus-bagliano / commits / b25b20656d
Fork 0

use strip() iso. slicing for removing \n

Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>

Han-Wen Nienhuys committed May 23, 2007 at 18:49 UTC b25b20656dceff6145a1286f10618ab25d717537
1 file changed +16 -14
contrib/fast-import/git-p4
+16 -14
@@ -15,7 +15,7 @@ import re
15 from sets import Set;
16
17 gitdir = os.environ.get("GIT_DIR", "")
18 -silent = False
18 +silent = True
19
20 def write_pipe(c, str):
21 if not silent:
@@ -109,7 +109,7 @@ def die(msg):
109 sys.exit(1)
110
111 def currentGitBranch():
112 - return read_pipe("git name-rev HEAD").split(" ")[1][:-1]
112 + return read_pipe("git name-rev HEAD").split(" ")[1].strip()
113
114 def isValidGitDir(path):
115 if os.path.exists(path + "/HEAD") and os.path.exists(path + "/refs") and os.path.exists(path + "/objects"):
@@ -117,7 +117,7 @@ def isValidGitDir(path):
117 return False
118
119 def parseRevision(ref):
120 - return read_pipe("git rev-parse %s" % ref)[:-1]
120 + return read_pipe("git rev-parse %s" % ref).strip()
121
122 def extractLogMessageFromGitCommit(commit):
123 logMessage = ""
@@ -205,7 +205,8 @@ class P4RollBack(Command):
205
206 for line in lines:
207 if self.rollbackLocalBranches or (line.startswith("p4/") and line != "p4/HEAD\n"):
208 - ref = refPrefix + line[:-1]
208 + line = line.strip()
209 + ref = refPrefix + line
210 log = extractLogMessageFromGitCommit(ref)
211 depotPath, change = extractDepotPathAndChangeFromGitLog(log)
212 changed = False
@@ -271,7 +272,7 @@ class P4Submit(Command):
272 commits.append("0")
273 else:
274 for line in read_pipe_lines("git rev-list --no-merges %s..%s" % (self.origin, self.master)):
274 - commits.append(line[:-1])
275 + commits.append(line.strip())
276 commits.reverse()
277
278 self.config["commits"] = commits
@@ -372,7 +373,7 @@ class P4Submit(Command):
373 if not self.directSubmit:
374 logMessage = extractLogMessageFromGitCommit(id)
375 logMessage = logMessage.replace("\n", "\n\t")
375 - logMessage = logMessage[:-1]
376 + logMessage = logMessage.strip()
377
378 template = read_pipe("p4 change -o")
379
@@ -513,7 +514,7 @@ class P4Submit(Command):
514
515 if len(self.substFile) > 0:
516 for line in open(self.substFile, "r").readlines():
516 - tokens = line[:-1].split("=")
517 + tokens = line.strip().split("=")
518 self.logSubstitutions[tokens[0]] = tokens[1]
519
520 self.check()
@@ -784,7 +785,7 @@ class P4Sync(Command):
785 lines = cache.readlines()
786 cache.close()
787 for line in lines:
787 - entry = line[:-1].split("\t")
788 + entry = line.strip().split("\t")
789 self.users[entry[0]] = entry[1]
790 except IOError:
791 self.getUserMapFromPerforceServer()
@@ -814,7 +815,7 @@ class P4Sync(Command):
815 print "Label changes: %s" % self.labels.keys()
816
817 def getBranchMapping(self):
817 - self.projectName = self.depotPath[self.depotPath[:-1].rfind("/") + 1:]
818 + self.projectName = self.depotPath[self.depotPath.strip().rfind("/") + 1:]
819
820 for info in p4CmdList("branches"):
821 details = p4Cmd("branch -o %s" % info["branch"])
@@ -848,6 +849,7 @@ class P4Sync(Command):
849 lie = line.strip()
850 if self.importIntoRemotes and ((not line.startswith("p4/")) or line == "p4/HEAD\n"):
851 continue
852 +
853 if self.importIntoRemotes:
854 # strip off p4
855 branch = re.sub ("^p4/", "", line)
@@ -966,7 +968,7 @@ class P4Sync(Command):
968 self.branch = "refs/heads/" + self.branch
969
970 if len(self.depotPath) != 0:
969 - self.depotPath = self.depotPath[:-1]
971 + self.depotPath = self.depotPath.strip()
972
973 if len(args) == 0 and len(self.depotPath) != 0:
974 if not self.silent:
@@ -1184,7 +1186,7 @@ class P4Rebase(Command):
1186 sync = P4Sync()
1187 sync.run([])
1188 print "Rebasing the current branch"
1187 - oldHead = read_pipe("git rev-parse HEAD")[:-1]
1189 + oldHead = read_pipe("git rev-parse HEAD").strip()
1190 system("git rebase p4")
1191 system("git diff-tree --stat --summary -M %s HEAD" % oldHead)
1192 return True
@@ -1217,7 +1219,7 @@ class P4Clone(P4Sync):
1219 depotDir = re.sub(r"/$", "", depotDir)
1220
1221 if not destination:
1220 - destination = os.path.split(depotDir)[-1]
1222 + destination = os.path.split(depotDir)[1]
1223
1224 print "Importing from %s into %s" % (depotPath, destination)
1225 os.makedirs(destination)
@@ -1295,9 +1297,9 @@ if cmd.needsGit:
1297 if len(gitdir) == 0:
1298 gitdir = ".git"
1299 if not isValidGitDir(gitdir):
1298 - gitdir = read_pipe("git rev-parse --git-dir")[:-1]
1300 + gitdir = read_pipe("git rev-parse --git-dir").strip()
1301 if os.path.exists(gitdir):
1300 - cdup = read_pipe("git rev-parse --show-cdup")[:-1];
1302 + cdup = read_pipe("git rev-parse --show-cdup").strip()
1303 if len(cdup) > 0:
1304 os.chdir(cdup);
1305