* [PATCH] git-p4: replace each tab with 8 spaces for consistency
@ 2011-04-07 6:01 Andrew Garber
2011-04-07 7:36 ` Junio C Hamano
0 siblings, 1 reply; 5+ messages in thread
From: Andrew Garber @ 2011-04-07 6:01 UTC (permalink / raw)
To: git, gitster; +Cc: Andrew Garber
Note that the majority of git-p4 uses spaces, not tabs, for indentation.
Consistent indentation is critical to the functionality of Python
scripts: mixing tabs and spaces in Python can lead to hard-to-find bugs.
Andrew Garber (1):
git-p4: replace each tab with 8 spaces for consistency
contrib/fast-import/git-p4 | 64 ++++++++++++++++++++++----------------------
1 files changed, 32 insertions(+), 32 deletions(-)
--
1.7.3.4
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH] git-p4: replace each tab with 8 spaces for consistency
@ 2011-04-07 6:01 Andrew Garber
0 siblings, 0 replies; 5+ messages in thread
From: Andrew Garber @ 2011-04-07 6:01 UTC (permalink / raw)
To: git, gitster; +Cc: Andrew Garber
Note that the majority of git-p4 uses spaces, not tabs, for indentation.
Consistent indentation is critical to the functionality of Python
scripts: mixing tabs and spaces in Python can lead to hard-to-find bugs.
Signed-off-by: Andrew Garber <andrew@andrewgarber.com>
---
contrib/fast-import/git-p4 | 64 ++++++++++++++++++++++----------------------
1 files changed, 32 insertions(+), 32 deletions(-)
diff --git a/contrib/fast-import/git-p4 b/contrib/fast-import/git-p4
index 3881515..78e5b3a 100755
--- a/contrib/fast-import/git-p4
+++ b/contrib/fast-import/git-p4
@@ -222,10 +222,10 @@ def p4CmdList(cmd, stdin=None, stdin_mode='w+b', cb=None):
try:
while True:
entry = marshal.load(p4.stdout)
- if cb is not None:
- cb(entry)
- else:
- result.append(entry)
+ if cb is not None:
+ cb(entry)
+ else:
+ result.append(entry)
except EOFError:
pass
exitCode = p4.wait()
@@ -449,8 +449,8 @@ def p4ChangesForPaths(depotPaths, changeRange):
changes = {}
for line in output:
- changeNum = int(line.split(" ")[1])
- changes[changeNum] = True
+ changeNum = int(line.split(" ")[1])
+ changes[changeNum] = True
changelist = changes.keys()
changelist.sort()
@@ -1033,10 +1033,10 @@ class P4Sync(Command):
# - helper for streamP4Files
def streamOneP4File(self, file, contents):
- if file["type"] == "apple":
- print "\nfile %s is a strange apple file that forks. Ignoring" % \
- file['depotFile']
- return
+ if file["type"] == "apple":
+ print "\nfile %s is a strange apple file that forks. Ignoring" % \
+ file['depotFile']
+ return
relPath = self.stripRepoPath(file['depotFile'], self.branchPrefixes)
relPath = self.wildcard_decode(relPath)
@@ -1085,22 +1085,22 @@ class P4Sync(Command):
# handle another chunk of streaming data
def streamP4FilesCb(self, marshalled):
- if marshalled.has_key('depotFile') and self.stream_have_file_info:
- # start of a new file - output the old one first
- self.streamOneP4File(self.stream_file, self.stream_contents)
- self.stream_file = {}
- self.stream_contents = []
- self.stream_have_file_info = False
+ if marshalled.has_key('depotFile') and self.stream_have_file_info:
+ # start of a new file - output the old one first
+ self.streamOneP4File(self.stream_file, self.stream_contents)
+ self.stream_file = {}
+ self.stream_contents = []
+ self.stream_have_file_info = False
- # pick up the new file information... for the
- # 'data' field we need to append to our array
- for k in marshalled.keys():
- if k == 'data':
- self.stream_contents.append(marshalled['data'])
- else:
- self.stream_file[k] = marshalled[k]
+ # pick up the new file information... for the
+ # 'data' field we need to append to our array
+ for k in marshalled.keys():
+ if k == 'data':
+ self.stream_contents.append(marshalled['data'])
+ else:
+ self.stream_file[k] = marshalled[k]
- self.stream_have_file_info = True
+ self.stream_have_file_info = True
# Stream directly from "p4 files" into "git fast-import"
def streamP4Files(self, files):
@@ -1132,14 +1132,14 @@ class P4Sync(Command):
self.stream_contents = []
self.stream_have_file_info = False
- # curry self argument
- def streamP4FilesCbSelf(entry):
- self.streamP4FilesCb(entry)
+ # curry self argument
+ def streamP4FilesCbSelf(entry):
+ self.streamP4FilesCb(entry)
- p4CmdList("-x - print",
- '\n'.join(['%s#%s' % (f['path'], f['rev'])
+ p4CmdList("-x - print",
+ '\n'.join(['%s#%s' % (f['path'], f['rev'])
for f in filesToRead]),
- cb=streamP4FilesCbSelf)
+ cb=streamP4FilesCbSelf)
# do the last chunk
if self.stream_file.has_key('depotFile'):
@@ -1148,7 +1148,7 @@ class P4Sync(Command):
def commit(self, details, files, branch, branchPrefixes, parent = ""):
epoch = details["time"]
author = details["user"]
- self.branchPrefixes = branchPrefixes
+ self.branchPrefixes = branchPrefixes
if self.verbose:
print "commit into %s" % branch
@@ -1253,7 +1253,7 @@ class P4Sync(Command):
s = ''
for (key, val) in self.users.items():
- s += "%s\t%s\n" % (key.expandtabs(1), val.expandtabs(1))
+ s += "%s\t%s\n" % (key.expandtabs(1), val.expandtabs(1))
open(self.getUserCacheFilename(), "wb").write(s)
self.userMapFromPerforceServer = True
--
1.7.3.4
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] git-p4: replace each tab with 8 spaces for consistency
2011-04-07 6:01 [PATCH] git-p4: replace each tab with 8 spaces for consistency Andrew Garber
@ 2011-04-07 7:36 ` Junio C Hamano
2011-04-07 16:35 ` Phil Hord
0 siblings, 1 reply; 5+ messages in thread
From: Junio C Hamano @ 2011-04-07 7:36 UTC (permalink / raw)
To: Andrew Garber; +Cc: git
Andrew Garber <andrew@andrewgarber.com> writes:
> Note that the majority of git-p4 uses spaces, not tabs, for indentation.
> Consistent indentation is critical to the functionality of Python
> scripts: mixing tabs and spaces in Python can lead to hard-to-find bugs.
Mixing tabs and spaces can lead to hard-to-find bugs, I agree.
I just threw this in to my .git/info/attributes:
contrib/fast-import/git-p4 whitespace=!indent,tail,tab-in-indent
and then did this:
$ >contrib/fast-import/git-p4
$ git diff -R | git apply --whitespace=fix
$ git diff
The changes I get out of the last step seem to exactly match your patch.
Thanks.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] git-p4: replace each tab with 8 spaces for consistency
2011-04-07 7:36 ` Junio C Hamano
@ 2011-04-07 16:35 ` Phil Hord
2011-04-07 18:45 ` Junio C Hamano
0 siblings, 1 reply; 5+ messages in thread
From: Phil Hord @ 2011-04-07 16:35 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Andrew Garber, git
On 04/07/2011 03:36 AM, Junio C Hamano wrote:
> Mixing tabs and spaces can lead to hard-to-find bugs, I agree.
>
> I just threw this in to my .git/info/attributes:
>
> contrib/fast-import/git-p4 whitespace=!indent,tail,tab-in-indent
>
> and then did this:
>
> $ >contrib/fast-import/git-p4
> $ git diff -R | git apply --whitespace=fix
> $ git diff
>
> The changes I get out of the last step seem to exactly match your patch.
Junio! Thanks for that recipe.
I suspected there must be some way to employ git-apply's whitespace=fix
feature to ws-normalize my code, but I was clueless how to do that. I
wound up cobbling together a python script that reimplements the same
fixes (hopefully).
I wish this (the git-apply trick) was documented somewhere and/or made
more prominent. Is it, and I have also overlooked it?
This is what I want:
git fix-whitespace # fix new ws errors in workdir
git fix-whitespace --all # fix all ws errors in workdir
git fix-whitespace foo # fix new ws errors since foo
git fix-whitespace --cached # fix new ws errors in the index
etc.
Is this already implemented somewhere in the git porcelain?
Phil
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] git-p4: replace each tab with 8 spaces for consistency
2011-04-07 16:35 ` Phil Hord
@ 2011-04-07 18:45 ` Junio C Hamano
0 siblings, 0 replies; 5+ messages in thread
From: Junio C Hamano @ 2011-04-07 18:45 UTC (permalink / raw)
To: Phil Hord; +Cc: git
Phil Hord <hordp@cisco.com> writes:
> This is what I want:
>
> git fix-whitespace # fix new ws errors in workdir
> git fix-whitespace --all # fix all ws errors in workdir
> git fix-whitespace foo # fix new ws errors since foo
> git fix-whitespace --cached # fix new ws errors in the index
> etc.
If you understood the example I gave, you should be able to figure all of
these out. In the most general case, you would come up with a way to
generate a diff that represents the change you want to fix (e.g. "new
errors" would be comparing the HEAD and the working tree), reverse apply
the diff and then forward apply the same diff with --whitespace=fix, but
often you can omit "reverse apply the diff" step by finding an appropriate
combination between HEAD/index/working tree.
I long time wrote this alias
[alias]
wsadd = "!sh -c 'git diff -- \"$@\" | git apply --cached --whitespace=fix;\
git co -- ${1-.} \"$@\"' -"
that acts as if you are saying "git add $path" while fixing the whitespace
errors I introduced in the working tree version.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2011-04-07 18:45 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-04-07 6:01 [PATCH] git-p4: replace each tab with 8 spaces for consistency Andrew Garber
2011-04-07 7:36 ` Junio C Hamano
2011-04-07 16:35 ` Phil Hord
2011-04-07 18:45 ` Junio C Hamano
-- strict thread matches above, loose matches on Subject: below --
2011-04-07 6:01 Andrew Garber
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).