[Diff] Added option to create a link to the output
- This link contains the git hashes involved in the comparison. Related to #265
This commit is contained in:
parent
1cfbb6b91e
commit
10ee73feeb
|
|
@ -1500,6 +1500,8 @@ Notes:
|
|||
- **`options`**: [dict] Options for the `diff` output.
|
||||
* Valid keys:
|
||||
- **`output`**: [string='%f-%i%I%v.%x'] Filename for the output (%i=diff, %x=pdf). Affected by global options.
|
||||
- `add_link_id`: [boolean=false] When enabled we create a symlink to the output file with a name that contains the
|
||||
git hashes involved in the comparison.
|
||||
- `cache_dir`: [string=''] Directory to cache the intermediate files. Leave it blank to disable the cache.
|
||||
- `diff_mode`: [string='red_green'] [red_green,stats] In the `red_green` mode added stuff is green and red when removed.
|
||||
The `stats` mode is used to meassure the amount of difference. In this mode all
|
||||
|
|
|
|||
|
|
@ -413,6 +413,9 @@ outputs:
|
|||
type: 'diff'
|
||||
dir: 'Example/diff_dir'
|
||||
options:
|
||||
# [boolean=false] When enabled we create a symlink to the output file with a name that contains the
|
||||
# git hashes involved in the comparison
|
||||
add_link_id: false
|
||||
# [string=''] Directory to cache the intermediate files. Leave it blank to disable the cache
|
||||
cache_dir: ''
|
||||
# [string='red_green'] [red_green,stats] In the `red_green` mode added stuff is green and red when removed.
|
||||
|
|
|
|||
|
|
@ -84,6 +84,9 @@ class DiffOptions(BaseOptions):
|
|||
self.threshold = 0
|
||||
""" [0,1000000] Error threshold for the `stats` mode, 0 is no error. When specified a
|
||||
difference bigger than the indicated value will make the diff fail """
|
||||
self.add_link_id = False
|
||||
""" When enabled we create a symlink to the output file with a name that contains the
|
||||
git hashes involved in the comparison """
|
||||
super().__init__()
|
||||
self._expand_id = 'diff'
|
||||
self._expand_ext = 'pdf'
|
||||
|
|
@ -203,6 +206,8 @@ class DiffOptions(BaseOptions):
|
|||
logger.debug('Changing to '+name)
|
||||
self.run_git(['checkout', '--recurse-submodules', name])
|
||||
self.checkedout = True
|
||||
# A short version of the current hash
|
||||
self.git_hash = self.run_git(['rev-parse', '--short', 'HEAD'])
|
||||
# Populate the cache
|
||||
hash = self.cache_file()
|
||||
finally:
|
||||
|
|
@ -210,7 +215,8 @@ class DiffOptions(BaseOptions):
|
|||
return hash
|
||||
|
||||
def cache_obj(self, name, type):
|
||||
return self.cache_git(name) if type == 'git' else self.cache_file(name)
|
||||
self.git_hash = 'None'
|
||||
return self.cache_git(name) if type == 'git' else self.cache_file(name), self.git_hash
|
||||
|
||||
def create_layers_incl(self, layers):
|
||||
incl_file = None
|
||||
|
|
@ -242,8 +248,8 @@ class DiffOptions(BaseOptions):
|
|||
# List of layers
|
||||
self.incl_file = self.create_layers_incl(self.layers)
|
||||
# Populate the cache
|
||||
old_hash = self.cache_obj(self.old, self.old_type)
|
||||
new_hash = self.cache_obj(self.new, self.new_type)
|
||||
old_hash, gh1 = self.cache_obj(self.old, self.old_type)
|
||||
new_hash, gh2 = self.cache_obj(self.new, self.new_type)
|
||||
# Compute the diff using the cache
|
||||
cmd = [self.command, '--no_reader', '--new_file_hash', new_hash, '--old_file_hash', old_hash,
|
||||
'--cache_dir', self.cache_dir, '--output_dir', dir_name, '--output_name', file_name,
|
||||
|
|
@ -256,6 +262,9 @@ class DiffOptions(BaseOptions):
|
|||
if GS.debug_enabled:
|
||||
cmd.insert(1, '-'+'v'*GS.debug_level)
|
||||
run_command(cmd)
|
||||
if self.add_link_id:
|
||||
name_comps = os.path.splitext(name)
|
||||
os.symlink(name, name_comps[0]+'_'+gh1+'-'+gh2+name_comps[1])
|
||||
finally:
|
||||
# Clean-up
|
||||
if remove_cache:
|
||||
|
|
|
|||
|
|
@ -12,3 +12,4 @@ outputs:
|
|||
new: HEAD
|
||||
new_type: git
|
||||
cache_dir: .cache
|
||||
add_link_id: true
|
||||
|
|
|
|||
Loading…
Reference in New Issue