Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(42)

Side by Side Diff: gcl.py

Issue 464068: Fix the way the temporary directory is created. (Closed)
Patch Set: Created 11 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | tests/gcl_unittest.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 # Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Wrapper script around Rietveld's upload.py that groups files into 6 """Wrapper script around Rietveld's upload.py that groups files into
7 changelists.""" 7 changelists."""
8 8
9 import getpass 9 import getpass
10 import os 10 import os
(...skipping 697 matching lines...) Expand 10 before | Expand all | Expand 10 after
708 The files in the list should either be absolute paths or relative to the 708 The files in the list should either be absolute paths or relative to the
709 given root. If no root directory is provided, the repository root will be 709 given root. If no root directory is provided, the repository root will be
710 used. 710 used.
711 """ 711 """
712 previous_cwd = os.getcwd() 712 previous_cwd = os.getcwd()
713 if root is None: 713 if root is None:
714 os.chdir(GetRepositoryRoot()) 714 os.chdir(GetRepositoryRoot())
715 else: 715 else:
716 os.chdir(root) 716 os.chdir(root)
717 717
718 # If the user specified a custom diff command in their svn config file,
bradn 2009/12/08 02:45:33 tabbing
719 # then it'll be used when we do svn diff, which we don't want to happen
720 # since we want the unified diff. Using --diff-cmd=diff doesn't always
721 # work, since they can have another diff executable in their path that
722 # gives different line endings. So we use a bogus temp directory as the
723 # config directory, which gets around these problems.
724 bogus_dir = tempfile.mkdtemp()
718 diff = [] 725 diff = []
719 for filename in files: 726 for filename in files:
720 # TODO(maruel): Use SVN.DiffItem(). 727 # TODO(maruel): Use SVN.DiffItem().
721 # Use svn info output instead of os.path.isdir because the latter fails 728 # Use svn info output instead of os.path.isdir because the latter fails
722 # when the file is deleted. 729 # when the file is deleted.
723 if SVN.CaptureInfo(filename).get('Node Kind') == 'directory': 730 if SVN.CaptureInfo(filename).get('Node Kind') == 'directory':
724 continue 731 continue
725 # If the user specified a custom diff command in their svn config file,
726 # then it'll be used when we do svn diff, which we don't want to happen
727 # since we want the unified diff. Using --diff-cmd=diff doesn't always
728 # work, since they can have another diff executable in their path that
729 # gives different line endings. So we use a bogus temp directory as the
730 # config directory, which gets around these problems.
731 if sys.platform.startswith("win"):
732 parent_dir = tempfile.gettempdir()
733 else:
734 parent_dir = sys.path[0] # tempdir is not secure.
735 bogus_dir = os.path.join(parent_dir, "temp_svn_config")
736 if not os.path.exists(bogus_dir):
737 os.mkdir(bogus_dir)
738 output = RunShell(["svn", "diff", "--config-dir", bogus_dir, filename]) 732 output = RunShell(["svn", "diff", "--config-dir", bogus_dir, filename])
739 if output: 733 if output:
740 diff.append(output) 734 diff.append(output)
741 elif SVN.IsMoved(filename): 735 elif SVN.IsMoved(filename):
742 # svn diff on a mv/cp'd file outputs nothing. 736 # svn diff on a mv/cp'd file outputs nothing.
743 # We put in an empty Index entry so upload.py knows about them. 737 # We put in an empty Index entry so upload.py knows about them.
744 diff.append("\nIndex: %s\n" % filename) 738 diff.append("\nIndex: %s\n" % filename)
745 else: 739 else:
746 # The file is not modified anymore. It should be removed from the set. 740 # The file is not modified anymore. It should be removed from the set.
747 pass 741 pass
742 shutil.rmtree(bogus_dir)
748 os.chdir(previous_cwd) 743 os.chdir(previous_cwd)
749 return "".join(diff) 744 return "".join(diff)
750 745
751 746
752 747
753 def OptionallyDoPresubmitChecks(change_info, committing, args): 748 def OptionallyDoPresubmitChecks(change_info, committing, args):
754 if FilterFlag(args, "--no_presubmit") or FilterFlag(args, "--force"): 749 if FilterFlag(args, "--no_presubmit") or FilterFlag(args, "--force"):
755 return True 750 return True
756 return DoPresubmitChecks(change_info, committing, True) 751 return DoPresubmitChecks(change_info, committing, True)
757 752
(...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after
1268 return 0 1263 return 0
1269 args =["svn", command] 1264 args =["svn", command]
1270 root = GetRepositoryRoot() 1265 root = GetRepositoryRoot()
1271 args.extend([os.path.join(root, x) for x in change_info.GetFileNames()]) 1266 args.extend([os.path.join(root, x) for x in change_info.GetFileNames()])
1272 RunShell(args, True) 1267 RunShell(args, True)
1273 return 0 1268 return 0
1274 1269
1275 1270
1276 if __name__ == "__main__": 1271 if __name__ == "__main__":
1277 sys.exit(main()) 1272 sys.exit(main())
OLDNEW
« no previous file with comments | « no previous file | tests/gcl_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698