def load_file(self, pn, unit=BLOB_UNIT): if not os.path.isfile(pn): return None blob = BlobFile2(self, mtime=os.path.getmtime(pn)) for (offset, bytes) in util.each_chunk2(pn, unit): chunk = BlobChunk2(self, chunk=bytes) blob.add(offset, chunk) return blob
def simple_walk(folder): # simple_walk will skip dipping into the folder # that are not tracked in the repo untracked = [] changed = [] for f in os.listdir(folder): if f == META_DIR: continue basename = os.path.basename(folder) if basename == '.' or basename == '': relpath = f else: relpath = os.path.join(folder, f) if relpath in tracked: if os.path.isdir(f): _untracked, _changed = simple_walk(relpath) untracked.extend(_untracked) changed.extend(_changed) else: fblob = tracked[relpath] # compare the file modified time and its metadata blob modified time curr_mtime = os.path.getmtime(relpath) last_mtime = os.path.getmtime( os.path.join(self.path_objs, fblob.hv)) if curr_mtime > last_mtime: # only load file when the file modified time is greater than metadata modified time fblob._load() flag = False # compare chunk hash for (offset, chunk) in util.each_chunk2(relpath, unit): if util.sha1( chunk) != fblob.entries[offset].hv: flag = True break if flag: changed.append(relpath) else: if os.path.isdir(relpath): relpath = os.path.join(relpath, '') untracked.append(relpath) return untracked, changed
def simple_walk(folder): # simple_walk will skip dipping into the folder # that are not tracked in the repo untracked = [] changed = [] for f in os.listdir(folder): if f == META_DIR: continue basename = os.path.basename(folder) if basename == '.' or basename == '': relpath = f else: relpath = os.path.join(folder, f) if relpath in tracked: if os.path.isdir(f): _untracked, _changed = simple_walk(relpath) untracked.extend(_untracked) changed.extend(_changed) else: fblob = tracked[relpath] # compare the file modified time and its metadata blob modified time curr_mtime = os.path.getmtime(relpath) last_mtime = os.path.getmtime(os.path.join(self.path_objs, fblob.hv)) if curr_mtime > last_mtime: # only load file when the file modified time is greater than metadata modified time fblob._load() flag = False # compare chunk hash for (offset, chunk) in util.each_chunk2(relpath, unit): if util.sha1(chunk) != fblob.entries[offset].hv: flag = True break if flag: changed.append(relpath) else: if os.path.isdir(relpath): relpath = os.path.join(relpath, '') untracked.append(relpath) return untracked, changed