* [PATCH 1/3] git-p4: Teach gitConfig method about arguments. @ 2011-03-15 12:08 Tor Arvid Lund 2011-03-15 12:08 ` [PATCH 2/3] Teach git-p4 to ignore case in perforce filenames if configured Tor Arvid Lund ` (2 more replies) 0 siblings, 3 replies; 4+ messages in thread From: Tor Arvid Lund @ 2011-03-15 12:08 UTC (permalink / raw) To: git, Pete Wyckoff; +Cc: Tor Arvid Lund With this patch, it is possible to call the gitConfig method with an optional argument string, which will be passed to the "git config" executable. For instance: gitConfig("core.ignorecase", "--bool") will ensure that you get the value "true", and won't have to check the returned value for [1, true, on, yes]. Signed-off-by: Tor Arvid Lund <torarvid@gmail.com> --- contrib/fast-import/git-p4 | 8 ++++++-- 1 files changed, 6 insertions(+), 2 deletions(-) diff --git a/contrib/fast-import/git-p4 b/contrib/fast-import/git-p4 index 7cb479c..4425220 100755 --- a/contrib/fast-import/git-p4 +++ b/contrib/fast-import/git-p4 @@ -333,9 +333,13 @@ def gitBranchExists(branch): return proc.wait() == 0; _gitConfig = {} -def gitConfig(key): +def gitConfig(key, args = None): # set args to "--bool", for instance if not _gitConfig.has_key(key): - _gitConfig[key] = read_pipe("git config %s" % key, ignore_error=True).strip() + argsFilter = "" + if args != None: + argsFilter = "%s " % args + cmd = "git config %s%s" % (argsFilter, key) + _gitConfig[key] = read_pipe(cmd, ignore_error=True).strip() return _gitConfig[key] def p4BranchesInGit(branchesAreInRemotes = True): -- 1.7.3.1.68.g06779.dirty ^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/3] Teach git-p4 to ignore case in perforce filenames if configured. 2011-03-15 12:08 [PATCH 1/3] git-p4: Teach gitConfig method about arguments Tor Arvid Lund @ 2011-03-15 12:08 ` Tor Arvid Lund 2011-03-15 12:08 ` [PATCH 3/3] git-p4: Fix error message crash in P4Sync.commit Tor Arvid Lund 2011-03-15 21:44 ` [PATCH 1/3] git-p4: Teach gitConfig method about arguments Pete Wyckoff 2 siblings, 0 replies; 4+ messages in thread From: Tor Arvid Lund @ 2011-03-15 12:08 UTC (permalink / raw) To: git, Pete Wyckoff; +Cc: Tor Arvid Lund When files are added to perforce, the path to that file has whichever case configuration that exists on the machine of the user who added the file. What does that mean? It means that when Alice adds a file //depot/DirA/FileA.txt ... and Bob adds: //depot/dirA/FileB.txt ... we may or may not get a problem. If a user sets the config variable git-p4.ignorecase to "true", we will consider //depot/DirA and //depot/dirA to be the same directory. Signed-off-by: Tor Arvid Lund <torarvid@gmail.com> --- contrib/fast-import/git-p4 | 27 ++++++++++++++++++++------- 1 files changed, 20 insertions(+), 7 deletions(-) diff --git a/contrib/fast-import/git-p4 b/contrib/fast-import/git-p4 index 4425220..d47596f 100755 --- a/contrib/fast-import/git-p4 +++ b/contrib/fast-import/git-p4 @@ -456,6 +456,19 @@ def p4ChangesForPaths(depotPaths, changeRange): changelist.sort() return changelist +def p4PathStartsWith(path, prefix): + # This method tries to remedy a potential mixed-case issue: + # + # If UserA adds //depot/DirA/file1 + # and UserB adds //depot/dira/file2 + # + # we may or may not have a problem. If you have core.ignorecase=true, + # we treat DirA and dira as the same directory + ignorecase = gitConfig("core.ignorecase", "--bool") == "true" + if ignorecase: + return path.lower().startswith(prefix.lower()) + return path.startswith(prefix) + class Command: def __init__(self): self.usage = "usage: %prog [options]" @@ -603,7 +616,7 @@ class P4Submit(Command): lastTab = path.rfind("\t") if lastTab != -1: path = path[:lastTab] - if not path.startswith(self.depotPath): + if not p4PathStartsWith(path, self.depotPath): continue else: inFilesSection = False @@ -941,11 +954,11 @@ class P4Sync(Command): path = commit["depotFile%s" % fnum] if [p for p in self.cloneExclude - if path.startswith (p)]: + if p4PathStartsWith(path, p)]: found = False else: found = [p for p in self.depotPaths - if path.startswith (p)] + if p4PathStartsWith(path, p)] if not found: fnum = fnum + 1 continue @@ -980,7 +993,7 @@ class P4Sync(Command): prefixes = [re.sub("^(//[^/]+/).*", r'\1', prefixes[0])] for p in prefixes: - if path.startswith(p): + if p4PathStartsWith(path, p): path = path[len(p):] return path @@ -991,7 +1004,7 @@ class P4Sync(Command): while commit.has_key("depotFile%s" % fnum): path = commit["depotFile%s" % fnum] found = [p for p in self.depotPaths - if path.startswith (p)] + if p4PathStartsWith(path, p)] if not found: fnum = fnum + 1 continue @@ -1144,7 +1157,7 @@ class P4Sync(Command): # create a commit. new_files = [] for f in files: - if [p for p in branchPrefixes if f['path'].startswith(p)]: + if [p for p in branchPrefixes if p4PathStartsWith(f['path'], p)]: new_files.append (f) else: sys.stderr.write("Ignoring file outside of prefix: %s\n" % path) @@ -1308,7 +1321,7 @@ class P4Sync(Command): source = paths[0] destination = paths[1] ## HACK - if source.startswith(self.depotPaths[0]) and destination.startswith(self.depotPaths[0]): + if p4PathStartsWith(source, self.depotPaths[0]) and p4PathStartsWith(destination, self.depotPaths[0]): source = source[len(self.depotPaths[0]):-4] destination = destination[len(self.depotPaths[0]):-4] -- 1.7.3.1.68.g06779.dirty ^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 3/3] git-p4: Fix error message crash in P4Sync.commit. 2011-03-15 12:08 [PATCH 1/3] git-p4: Teach gitConfig method about arguments Tor Arvid Lund 2011-03-15 12:08 ` [PATCH 2/3] Teach git-p4 to ignore case in perforce filenames if configured Tor Arvid Lund @ 2011-03-15 12:08 ` Tor Arvid Lund 2011-03-15 21:44 ` [PATCH 1/3] git-p4: Teach gitConfig method about arguments Pete Wyckoff 2 siblings, 0 replies; 4+ messages in thread From: Tor Arvid Lund @ 2011-03-15 12:08 UTC (permalink / raw) To: git, Pete Wyckoff; +Cc: Tor Arvid Lund There is an error message that crashes the script because of an invalid ref to the non-existing "path" variable. It is almost never printed, which would explain why nobody encountered this problem before... But anyway, this oneliner fixes it. Signed-off-by: Tor Arvid Lund <torarvid@gmail.com> --- contrib/fast-import/git-p4 | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/contrib/fast-import/git-p4 b/contrib/fast-import/git-p4 index d47596f..47ba7ad 100755 --- a/contrib/fast-import/git-p4 +++ b/contrib/fast-import/git-p4 @@ -1160,7 +1160,7 @@ class P4Sync(Command): if [p for p in branchPrefixes if p4PathStartsWith(f['path'], p)]: new_files.append (f) else: - sys.stderr.write("Ignoring file outside of prefix: %s\n" % path) + sys.stderr.write("Ignoring file outside of prefix: %s\n" % f['path']) self.gitStream.write("commit %s\n" % branch) # gitStream.write("mark :%s\n" % details["change"]) -- 1.7.3.1.68.g06779.dirty ^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 1/3] git-p4: Teach gitConfig method about arguments. 2011-03-15 12:08 [PATCH 1/3] git-p4: Teach gitConfig method about arguments Tor Arvid Lund 2011-03-15 12:08 ` [PATCH 2/3] Teach git-p4 to ignore case in perforce filenames if configured Tor Arvid Lund 2011-03-15 12:08 ` [PATCH 3/3] git-p4: Fix error message crash in P4Sync.commit Tor Arvid Lund @ 2011-03-15 21:44 ` Pete Wyckoff 2 siblings, 0 replies; 4+ messages in thread From: Pete Wyckoff @ 2011-03-15 21:44 UTC (permalink / raw) To: Tor Arvid Lund; +Cc: git All three patches in this series look good to me. They passed t9800 tests too. Acked-By: Pete Wyckoff <pw@padd.com> ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2011-03-15 21:45 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2011-03-15 12:08 [PATCH 1/3] git-p4: Teach gitConfig method about arguments Tor Arvid Lund 2011-03-15 12:08 ` [PATCH 2/3] Teach git-p4 to ignore case in perforce filenames if configured Tor Arvid Lund 2011-03-15 12:08 ` [PATCH 3/3] git-p4: Fix error message crash in P4Sync.commit Tor Arvid Lund 2011-03-15 21:44 ` [PATCH 1/3] git-p4: Teach gitConfig method about arguments Pete Wyckoff
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).