The tree_status() function does a few slightly different things
depending on the arguments. This patch adds checks that the arguments
are consistent and that the returned value looks good.
It also changes the semantics slightly. If the 'files' parameter is
None, it will run status on all files. If 'files' is a list, it will
run status on only those files. This changes two things:
1) If 'files' is the empty list, it will run status on no files.
2) It 'files' is a list, it will never return the status for other files
Clearing this up will make it easier to understand code that is using
this function.
Signed-off-by: David Kågedal <davidk@lysator.liu.se>
Signed-off-by: Karl Hasselström <kha@treskal.com>
+ # No args means all files
+ if not args:
+ args = None
git.status(args, options.modified, options.new, options.deleted,
options.conflict, options.unknown, options.noexclude,
diff_flags = diff_flags)
git.status(args, options.modified, options.new, options.deleted,
options.conflict, options.unknown, options.noexclude,
diff_flags = diff_flags)
def tree_status(files = None, tree_id = 'HEAD', unknown = False,
noexclude = True, verbose = False, diff_flags = []):
def tree_status(files = None, tree_id = 'HEAD', unknown = False,
noexclude = True, verbose = False, diff_flags = []):
- """Returns a list of pairs - (status, filename)
+ """Get the status of all changed files, or of a selected set of
+ files. Returns a list of pairs - (status, filename).
+
+ If 'files' is None, it will check all files, and optionally all
+ unknown files. If 'files' is a list, it will only check the files
+ in the list.
+ assert files == None or not unknown
+
if verbose:
out.start('Checking for changes in the working directory')
refresh_index()
if verbose:
out.start('Checking for changes in the working directory')
refresh_index()
- if not files:
- files = []
cache_files = []
# unknown files
cache_files = []
# unknown files
conflicts = get_conflicts()
if not conflicts:
conflicts = []
conflicts = get_conflicts()
if not conflicts:
conflicts = []
- cache_files += [('C', filename) for filename in conflicts]
+ cache_files += [('C', filename) for filename in conflicts
+ if files == None or filename in files]
- for line in GRun('git-diff-index', *(diff_flags + [tree_id, '--'] + files)
- ).output_lines():
+ args = diff_flags + [tree_id]
+ if files != None:
+ args += ['--'] + files
+ for line in GRun('git-diff-index', *args).output_lines():
fs = tuple(line.rstrip().split(' ',4)[-1].split('\t',1))
if fs[1] not in conflicts:
cache_files.append(fs)
fs = tuple(line.rstrip().split(' ',4)[-1].split('\t',1))
if fs[1] not in conflicts:
cache_files.append(fs)
+ assert files == None or set(f for s,f in cache_files) <= set(files)
return cache_files
def local_changes(verbose = True):
return cache_files
def local_changes(verbose = True):
def update_cache(files = None, force = False):
"""Update the cache information for the given files
"""
def update_cache(files = None, force = False):
"""Update the cache information for the given files
"""
- if not files:
- files = []
-
cache_files = tree_status(files, verbose = False)
# everything is up-to-date
cache_files = tree_status(files, verbose = False)
# everything is up-to-date
committer_name = None, committer_email = None):
"""Commit the current tree to repository
"""
committer_name = None, committer_email = None):
"""Commit the current tree to repository
"""
- if not files:
- files = []
if not parents:
parents = []
if not parents:
parents = []
diff_flags = []):
"""Show the tree status
"""
diff_flags = []):
"""Show the tree status
"""
- if not files:
- files = []
-
- cache_files = tree_status(files, unknown = True, noexclude = noexclude,
- diff_flags = diff_flags)
- all = not (modified or new or deleted or conflict or unknown)
+ cache_files = tree_status(files,
+ unknown = (files == None),
+ noexclude = noexclude,
+ diff_flags = diff_flags)
+ filtered = (modified or new or deleted or conflict or unknown)
filestat = []
if modified:
filestat.append('M')
filestat = []
if modified:
filestat.append('M')
cache_files = [x for x in cache_files if x[0] in filestat]
for fs in cache_files:
cache_files = [x for x in cache_files if x[0] in filestat]
for fs in cache_files:
- if files and not fs[1] in files:
- continue
- if all:
+ assert files == None or fs[1] in files
+ if not filtered:
out.stdout('%s %s' % (fs[0], fs[1]))
else:
out.stdout('%s' % fs[1])
out.stdout('%s %s' % (fs[0], fs[1]))
else:
out.stdout('%s' % fs[1])