Index: trychange.py |
diff --git a/trychange.py b/trychange.py |
index 8a6e35eac380b4da19d3a92eb181672681c66426..457157f4cd33752009804b7d84c93232828bf2e2 100755 |
--- a/trychange.py |
+++ b/trychange.py |
@@ -511,7 +511,7 @@ def _TempFilename(name, contents=None): |
@contextlib.contextmanager |
-def _PrepareDescriptionAndPatchFiles(description, options): |
+def _PrepareDescriptionAndPatchFiles(description, options, use_username=True): |
agable
2014/04/11 20:53:11
Why add this complexity? The ref is not actually a
nodir
2014/04/11 23:49:59
Good point
|
"""Creates temporary files with description and patch. |
__enter__ called on the return value returns a tuple of patch_filename and |
@@ -521,10 +521,12 @@ def _PrepareDescriptionAndPatchFiles(description, options): |
description: contents of description file. |
options: patchset options object. Must have attributes: user, |
name (of patch) and diff (contents of patch). |
+ use_username: specifies if username must be included in the patch_filename. |
""" |
current_time = str(datetime.datetime.now()).replace(':', '.') |
- patch_basename = '%s.%s.%s.diff' % (Escape(options.user), |
- Escape(options.name), current_time) |
+ patch_basename = '%s.%s.diff' % (Escape(options.name), current_time) |
+ if use_username: |
+ patch_basename = '%s.%s' % (Escape(options.user), patch_basename) |
with _TempFilename('description', description) as description_filename: |
with _TempFilename(patch_basename, options.diff) as patch_filename: |
yield patch_filename, description_filename |
@@ -637,15 +639,17 @@ def _SendChangeGit(bot_spec, options): |
assert scm.GIT.IsInsideWorkTree(patch_dir) |
assert not scm.GIT.IsWorkTreeDirty(patch_dir) |
- with _PrepareDescriptionAndPatchFiles(description, options) as ( |
+ with _PrepareDescriptionAndPatchFiles(description, options, |
+ use_username=False) as ( |
patch_filename, description_filename): |
logging.info('Committing patch') |
- target_branch = ('refs/patches/' + |
- os.path.basename(patch_filename).replace(' ','-')) |
+ target_branch = 'refs/patches/%s/%s' % ( |
+ Escape(options.user), |
+ os.path.basename(patch_filename).replace(' ','-')) |
agable
2014/04/11 20:53:11
use underscores instead of hyphens
nodir
2014/04/11 23:49:59
Done.
|
target_filename = os.path.join(patch_dir, 'patch.diff') |
branch_file = os.path.join(patch_dir, GIT_BRANCH_FILE) |
try: |
- # Crete a new branch and put the patch there |
+ # Create a new branch and put the patch there. |
patch_git('checkout', '--orphan', target_branch) |
patch_git('reset') |
patch_git('clean', '-f') |