Closed Bug 1197433 Opened 11 years ago Closed 9 years ago

non-mq patches do not have useful names for obsoleting old patches

Categories

(Developer Services :: Mercurial: bzexport, defect)

defect
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: sfink, Assigned: sfink)

References

(Depends on 1 open bug)

Details

Attachments

(1 file, 5 obsolete files)

That breaks the handy "automatically obsolete old versions of the attachment" functionality.
When using evolve, precursors can provide a stable identifier. It's not guaranteed to be correct (eg if you split a patch), but it seems like it's close enough to be useful. gps: I pasted in your code for detecting where obsolescence is available, but while testing it, it struck me that just trying it and catching the exception was simpler in this particular case. Let me know if you disagree.
Attachment #8651305 - Flags: review?(gps)
Comment on attachment 8651305 [details] [diff] [review] Set patch filenames more intelligently Review of attachment 8651305 [details] [diff] [review]: ----------------------------------------------------------------- Great hack! It's just crazy enough to work. I would like to see the name detection code refactored slightly to avoid false positives. Please do that and submit for review. Tests would also be nice. Ping me on IRC if you need help writing them. ::: hgext/bzexport/__init__.py @@ +844,5 @@ > + # a bookmark or tag, it seems reasonable to do the same. But for anything > + # else, it seems most useful to track back through obsolete changesets to > + # the first one. This won't work if you split a patch up or whatever, but > + # it ought to be a good default (for evolve users, anyway.) > + if re.match(r'^([0-9a-f]+|\.)$', rev): This is potentially too greedy. A better way to do this to ensure the thing you are naming is a SHA-1 or fragment is something like this: try: ctx = repo[rev] if ctx.hex().startswith(rev): # SHA-1 fragment else: # symbolic name except error.RepoLookupError: # symbolic name
Attachment #8651305 - Flags: review?(gps)
I like the basic idea of looking it up to see if it maps to a single rev, but I'll need to think a bit more about the exact logic. For example, an mq-controlled changeset will resolve to a specific revision, but in that case I would want the mq patch name to be used instead of the initial precursor. On the other hand, if the user gives a bookmark name, I would want the precursor. (The current patch does the wrong thing here.) Sadly, I think that means I'll need some mq-specific code to check whether the name exists as an mq patch name.
Hm, my previous comment directly contradicts what I wrote in the comment in the patch, which was that a bookmark or tag should be preferred to the initial precursor. But I've changed my mind; if obsolescence markers are available, they're better than using a bookmark name (because you might add a new patch onto a bookmark, and it should not replace the previous bookmark head.)
Depends on: 1199037
gps - I kind of dropped this on the floor when I ran into the test problems, but just now somebody on IRC ran into this and complained about it. I have the patch in a working state, and I've been using it successfully the past 6 months. I attempted to write tests for it, but the bzexport tests require a bunch of stuff (eg bugzilla) that I haven't managed to get working locally. I forget the exact problem; it partly works. I think it is that create-test-environment never completely works. I just reran, and after much downloading and thinking and churning, it spewed the errors below. Do you think it would be ok to land without tests for now? I think it would help people trying to migrate away from mq (and not yet to mozreview). Oh. It looks like I filed a blocking bug for the create-test-environment woes, bug 1199037 --- hgrb> failed: [localhost] => (item=httpd,httpd-devel,mod_authnz_external,openldap-devel,python27,python-ldap,rsyslog,sudo) => {"failed": true, "item": "httpd,httpd-devel,mod_authnz_external,openldap-devel,python27,python-ldap,rsyslog,sudo"} hgrb> msg: Error from repoquery: ['/usr/bin/repoquery', '--show-duplicates', '--plugins', '--quiet', '-q', '--disablerepo=*', '--pkgnarrow=installed', '--qf', '%{name}-%{version}-%{release}.%{arch}', 'python-ldap-2.3.10-1.el6.x86_64']: rpmdb: /var/lib/rpm/__db.002: Read-only file system hgrb> error: db3 error(30) from dbenv->open: Read-only file system hgrb> error: cannot open Packages index using db3 - Read-only file system (30) hgrb> error: cannot open Packages database in /var/lib/rpm hgrb> Error: rpmdb open failed
Attachment #8715524 - Flags: review?(gps)
Attachment #8651305 - Attachment is obsolete: true
Comment on attachment 8715524 [details] [diff] [review] Set patch filenames more intelligently Review of attachment 8715524 [details] [diff] [review]: ----------------------------------------------------------------- ::: hgext/bzexport/__init__.py @@ +795,5 @@ > + pass > + > + try: > + ctx = repo[rev] > + except: Never use bareword "except" in Python, as it traps *all* exceptions, including KeyboardInterrupt and SystemExit, which are raised as a result of signals. Instead, trap "Exception", which is in a different class hierarchy from KeyboardInterrupt and SystemExit. @@ +800,5 @@ > + ui.fatal("Revision '{rev}' is unknown".format(rev=rev)) > + > + try: > + revset = 'first(allprecursors({rev}) + {rev})'.format(rev=rev) > + return 'base-' + str(tuple(repo.unfiltered().set(revset))[0]) See https://hg.mozilla.org/hgcustom/version-control-tools/file/4d77f5f45fa1/hgext/reviewboard/client.py#l554 for a more native API for querying precursors for a node. @@ +806,5 @@ > + ui.debug("allprecursors revset not available. evolve extension is most likely not enabled.") > + pass > + > + try: > + revset = 'bookmark("literal:{bookmark}") and id({id})'.format(bookmark=rev, id=ctx.hex()) There is a "namespaces" API you should use for this. bookmarks = repo.names['bookmarks'].names(node) This will return a list of bookmarks associated with a node. repo.names is an iterable of namespaces, so you can query for *any* name associated with a node: for nsname, ns in repo.names.iteritems(): names = ns.names(node) "bookmarks" "tags" and "branches" are built-in namespaces. And every node has a branch name. So you may want to filter those out. Also, if firefoxtree is enabled, there is an "fxtrees" namespace with names like "central." So, it's probably better to ignore all the namespaces. But now you know there is an API.
Attachment #8715524 - Flags: review?(gps)
Finally updated this patch. Happily, I can test the important part of this without docker or a bugzilla repo.
Attachment #8874050 - Flags: review?(gps)
Attachment #8715524 - Attachment is obsolete: true
Comment on attachment 8874050 [details] [diff] [review] Attempt to autocompute a persistent id using obsolescence links Review of attachment 8874050 [details] [diff] [review]: ----------------------------------------------------------------- I'll finish the review later - hopefully by EOD tomorrow. ::: hgext/bzexport/tests/test-basechange.t @@ +8,5 @@ > + $ hg init > + $ cat >> .hg/hgrc << EOF > + > [extensions] > + > mq = ! > + > evolve = $TESTDIR/hgext/bzexport/tests/enable_obsolete.py You can achieve this by setting [experimental] evolution=all.
Then review this one instead. Using your suggestion revealed some other things that needed to be updated.
Attachment #8874984 - Flags: review?(gps)
Attachment #8874050 - Attachment is obsolete: true
Attachment #8874050 - Flags: review?(gps)
Sorry for the churn, but I still can't just create test cases for this stuff. Although my test bugzilla docker container seems to be doing *something*, it fails when bzexport tries to fetch its configuration. So I end up testing this as a side effect of what I'm doing, and I don't use much of the fallback functionality because I use evolve and not mq.
Attachment #8875335 - Flags: review?(gps)
Attachment #8874984 - Attachment is obsolete: true
Attachment #8874984 - Flags: review?(gps)
Comment on attachment 8875335 [details] [diff] [review] Attempt to autocompute a persistent id using obsolescence links Review of attachment 8875335 [details] [diff] [review]: ----------------------------------------------------------------- Nice obsolescence tricks! I suspect this will get r+ on next review. ::: hgext/bzexport/__init__.py @@ +119,5 @@ > + if len(precursors) == 0: > + break > + > + # Multiple precursors means a join point. Pick the first precursor. > + pre = min(precursors, key=lambda m: m.date()) Strictly speaking, this can be wrong because it relies on wall clock accuracy. But I don't think we care enough and there's nothing better/easier. @@ +928,5 @@ > + base = scmutil.revsingle(fullrepo, 'basechange(%s)' % rev) > + return 'base-' + node.short(base) > + > + try: > + bookmarks = repo.names['bookmarks'].names(repo, ctx.node()) I think we should try bookmarks before looking at precursors. Is there a reason you went with the current order? @@ +933,5 @@ > + if len(bookmarks) > 0: > + return 'book-' + bookmarks[0] > + except error.RepoLookupError: > + ui.debug("revision is not a bookmark\n") > + pass Nit: don't need "pass" if there are other statements in a block. @@ +1379,5 @@ > ui.write("Created bug %s at %sshow_bug.cgi?id=%s\n" % (bug, bugzilla, bug)) > + > +def reposetup(ui, repo): > + if obsolete.isenabled(repo, 'bzexport'): > + revset.symbols['basechange'] = revset_basechange I'm not a fan of registering this revset - at least as "basechange" - because people may confuse it for something in core mercurial. Please either refactor to not define as a revset or rename to "bzbasechange" or something. I think you can also _ prefix the revset name to hide it from `hg help revisions`.
Attachment #8875335 - Flags: review?(gps)
(In reply to Gregory Szorc [:gps] from comment #11) > > + # Multiple precursors means a join point. Pick the first precursor. > > + pre = min(precursors, key=lambda m: m.date()) > > Strictly speaking, this can be wrong because it relies on wall clock > accuracy. But I don't think we care enough and there's nothing better/easier. Yeah, I agree it's a code smell. My first version depended on the ordering in the list, but I have no idea whether that's meant to be meaningful. But it's mostly important that this be deterministic, so it should be fine. (Though last I heard, junw was planning on depending on date stamps for distributed obsolescence merges, which kinda creeps me out...) > I think we should try bookmarks before looking at precursors. Is there a > reason you went with the current order? Yes. Bookmarks are frequently wrong. Precursors are rarely wrong. The usual problem is that you're working on a bug and bzexport a patch that does some initial refactoring, then commit a follow-on patch and bzexport that. If you're using bookmarks, the bookmark will transition between patches and the second bzexport will (bugzilla-) obsolete the first. > > + except error.RepoLookupError: > > + ui.debug("revision is not a bookmark\n") > > + pass > > Nit: don't need "pass" if there are other statements in a block. Uh, right. It started out just "pass", then I inserted the debug statement. Heh. > > +def reposetup(ui, repo): > > + if obsolete.isenabled(repo, 'bzexport'): > > + revset.symbols['basechange'] = revset_basechange > > I'm not a fan of registering this revset - at least as "basechange" - > because people may confuse it for something in core mercurial. Please either > refactor to not define as a revset or rename to "bzbasechange" or something. > I think you can also _ prefix the revset name to hide it from `hg help > revisions`. I would like to register it because I find it useful at times for other purposes. I'm happy to conceal it from the help. I don't see anything about underscores, but putting "(EXPERIMENTAL)" in the doc appears to work. I should note that it *isn't* in the help currently. I'm using reposetup here, and that's not going to run if you're just doing help. (I have to use reposetup, because I need the repo to test whether obsolescence is enabled.) But I'll put in (EXPERIMENTAL) anyway.
Attachment #8875951 - Flags: review?(gps)
Attachment #8875335 - Attachment is obsolete: true
Comment on attachment 8875951 [details] [diff] [review] Attempt to autocompute a persistent id using obsolescence links Review of attachment 8875951 [details] [diff] [review]: ----------------------------------------------------------------- For the record, I wish there were tests for the patch ID bits. But meh. bzexport is a bit messy and Phabricator should make it mostly obsolete for Firefox development, so my test standards are low. This is a cool feature. Obsolescence is kinda magical.
Attachment #8875951 - Flags: review?(gps) → review+
Pushed by sfink@mozilla.com: https://hg.mozilla.org/hgcustom/version-control-tools/rev/453bcf1bd611 Attempt to autocompute a persistent id using obsolescence links, r=gps
Status: ASSIGNED → RESOLVED
Closed: 9 years ago
Resolution: --- → FIXED
Pushed by sfink@mozilla.com: https://hg.mozilla.org/hgcustom/version-control-tools/rev/10251bd8035a Rebase bug from bug 1197433 - calling node.short on a ctx instead of a node
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: