How to access file history ?

Asked by Alex Colvin

I'd like to get a history of revisions affecting a particular file along with the name the file had in each revision. "bzr log <file>" gives you the list if the file exists at the start or end, but not if it had another name or had a short lifetime. I could grovel through the"-v" output to track the name changes, but I'd really like to provide a revno and a name.

I'm prepared to use the bzrlib API, but I'm not sure where. I'd like to get the fileid for a filename as of a particular revision, then get a list of revisions touching that fileid. How do I get from revno and name to fileid?

For context, this is for use in a versioned FUSE file system for a history view, where each file appears as a directory of numbered versions. See <http://sourceforge.net/projects/bzrofs/>.

So, for example, I have a file which appears in rev 7 as test.c, and changes to splaytest.c in rev 10. I'd like to be able to specify it as -r8 test.c and find out the rest.

Thanks for any advice.

Question information

Language:
English Edit question
Status:
Solved
For:
Bazaar Edit question
Assignee:
No assignee Edit question
Solved by:
John A Meinel
Solved:
Last query:
Last reply:
Revision history for this message
Vincent Ladeuil (vila) said :
#1

You may be interested in the hidden command touching-revisions. But you'll see that it doesn't shows every revision you may be interested in.

In fact no command-line command will give you the level of detail you're after.

Have a look at the _filter_revisions_touching_file_id in bzrlib/log.py, it will come a bit closer to what
you're after but still requires you to start with the right file-id.
Also it may includes more revisions that you want (look at the include_merges parameter).

Revision history for this message
Best John A Meinel (jameinel) said :
#2

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Alex Colvin wrote:
> New question #95123 on Bazaar:
> https://answers.launchpad.net/bzr/+question/95123
>
> I'd like to get a history of revisions affecting a particular file along with the name the file had in each revision. "bzr log <file>" gives you the list if the file exists at the start or end, but not if it had another name or had a short lifetime. I could grovel through the"-v" output to track the name changes, but I'd really like to provide a revno and a name.
>
> I'm prepared to use the bzrlib API, but I'm not sure where. I'd like to get the fileid for a filename as of a particular revision, then get a list of revisions touching that fileid. How do I get from revno and name to fileid?
>
> For context, this is for use in a versioned FUSE file system for a history view, where each file appears as a directory of numbered versions. See <http://sourceforge.net/projects/bzrofs/>.
>
> So, for example, I have a file which appears in rev 7 as test.c, and changes to splaytest.c in rev 10. I'd like to be able to specify it as -r8 test.c and find out the rest.
>
> Thanks for any advice.
>
>

So I believe the issue is that you want to recurse through history to
find a file at a given path, and then track that file through the rest
of history including renames.

I don't know how efficient you want the search to be, but in rough form:

branch_path = 'path/to/branch'
file_path = 'tree/filename'
b = bzrlib.branch.Branch.open(branch_path)
b.lock_read()
last_rev_id = b.last_revision()
for rev_id in b.repository.iter_reverse_revision_history(last_rev_id):
  tree = b.repository.revision_tree(rev_id)
  file_id = tree.path2id(file_path)
  if file_id is not None:
    print 'Found %s as file_id %s in revid:%s' % (file_path, file_id,
          rev_id)
    # Break/keep going, etc
b.unlock()

At that point you should be able to do:

 bzr log -r ..revid:$REV_ID file_path
and possibly
 bzr log -r revid:$REV_ID.. file_path

If the file was just renamed to something new, rather than deleted.

John
=:->
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAks4zNkACgkQJdeBCYSNAAPmIQCg1lo/efFvzzdKHPPu+sg97k1i
Q5gAnR8Gv511SD5wab2nscfI+SjYLeCH
=5AVs
-----END PGP SIGNATURE-----

Revision history for this message
Alex Colvin (mac3n) said :
#3

That's not what I was hoping for, but that'll do.
I'm trying to avoid scanning every file and every revision.
It looks like I may also be able to cruise through
log -v --show-ids -r$REVNO for every $REVNO affecting the file.
where I can start from an initial file and rev $FILE and $START,
and split the searches
log -v -r --show-ids -r1..$START $FILE
log -v -r --show-ids -r$START..-1 $FILE
so that the starting point is found.

Considering that files can move around and mutate into diretories,
I need to think about how to present the resulting history.
A directory of symlinks to versions might be the way.