from bup.repo import LocalRepo
from helpers import columnate, istty1, last, log
+def item_hash(item, tree_for_commit):
+ """If the item is a Commit, return its commit oid, otherwise return
+ the item's oid, if it has one.
+
+ """
+ if tree_for_commit and isinstance(item, vfs.Commit):
+ return item.coid
+ return getattr(item, 'oid', None)
def item_info(item, name,
show_hash = False,
+ commit_hash=False,
long_fmt = False,
classification = None,
numeric_ids = False,
"""
result = ''
- if show_hash and hasattr(item, 'oid'):
- result += '%s ' % item.oid.encode('hex')
+ if show_hash:
+ oid = item_hash(item, commit_hash)
+ result += '%s ' % (oid.encode('hex') if oid
+ else '0000000000000000000000000000000000000000')
if long_fmt:
meta = item.meta.copy()
meta.path = name
%sls [-a] [path...]
--
s,hash show hash for each file
+commit-hash show commit hash instead of tree for commits (implies -s)
a,all show hidden files
A,almost-all show hidden files except . and ..
l use a detailed, long listing format
elif option in ('-A', '--almost-all'):
show_hidden = 'almost'
+ if opt.commit_hash:
+ opt.hash = True
+
def item_line(item, name):
return item_info(item, name,
show_hash = opt.hash,
+ commit_hash=opt.commit_hash,
long_fmt = opt.l,
classification = classification,
numeric_ids = opt.numeric_ids,
Commit items represent commits (e.g. /.tag/some-commit or
/foo/latest), and for most purposes, they appear as the underlying
tree. S_ISDIR(item_mode(item)) will return true for both tree Items
-and Commits and the commit's oid is the tree hash. The commit hash
-will be item.coid, and nominal_oid(item) will return coid for commits,
-oid for everything else.
+and Commits and the commit's oid is the tree hash; the commit hash is
+item.coid.
"""
_tags = Tags(meta=default_dir_mode)
-def nominal_oid(item):
- """If the item is a Commit, return its commit oid, otherwise return
- the item's oid, if it has one.
-
- """
- if isinstance(item, Commit):
- return item.coid
- return getattr(item, 'oid', None)
-
def copy_item(item):
"""Return a completely independent copy of item, such that
modifications will not affect the original.
WVPASS bup save -n src -d 242312160 --strip src
WVPASS bup tag some-tag src
+src_commit_hash=$(git log --format=%H -n1 src)
+src_tree_hash=$(git log --format=%T -n1 src)
+
WVSTART "ls (short)"
"drwxr-xr-x 0/0
drwxr-xr-x 0/0"
+WVPASSEQ "$(bup ls -ds "src/latest" | tr -s ' ' ' ')" \
+"$src_tree_hash src/latest"
+
+WVPASSEQ "$(bup ls -ds --commit-hash "src/latest" | tr -s ' ' ' ')" \
+"$src_commit_hash src/latest"
+
WVSTART "ls (dates TZ != UTC)"
export TZ=America/Chicago