Hi Luciano, On Sat, 31 Mar 2018, Luciano Joublanc wrote: > I've cloned the `maint` branch, built the project, and added the test > as you suggested - it's failing as expected. Excellent. > On 30 March 2018 at 11:20, Johannes Schindelin > <Johannes.Schindelin@xxxxxx> wrote: > > > > However, this would be incorrect, as the flags are stored with the > > *commit*, not with the ref. So if two refs point to the same commit, > > that new code would skip the second one by mistake! > > Isn't that the point here? to deduplicate commits? My limited > understanding is that at a 'ref' is like an alias or pointer to a > commit. The point is to deduplicate refs, not commits ;-) Imagine that you have a git.git clone, and then you work on some topic, say, `bundle-refs` and then call `git checkout -b bundle-refs-wip` from there. If you now say git bundle create wip.bundle bundle-refs bundle-refs-wip you will want both bundle-refs and bundle-refs-wip to show up in that bundle, not just bundle-refs, even if both refs point at the same commit. > > By the way, this makes me think that there is another very real bug > > in the bundle code, in the part I showed above. Suppose you have a > > `master` and a `next` ref, and both point at the same commit, then > > you would want `git bundle create next.bundle master..next` to list > > `next`, don't you think? > > Doesn't this contradict what you just said, that we don't want to skip > refs with the same commit #? I would rather be able to generate such a wip.bundle as outlined above where calling `git ls-remote wip.bundle` would list *both* refs, with the same commit. > In fact, if you look in the calling function, there is a > ` object_array_remove_duplicates(&revs.pending);` > Which to the best of my understanding removes duplicate refs (not > commits). However, I suspect this doesn't cover the `--all` case as > it's a switch rather than a revspec? Would that be right? Oh, I missed that! And I also missed that this is implemented with something *else* than a hashmap, so it won't have linear complexity but instead quadratic. Gross. But you got an interesting nugget there, as it indeed tries to deduplicate, but not by object ID, otherwise the bug you reported would not occur (but other bugs, as I outlined above). Instead, the object_array_remove_duplicates() code does this: -- snip -- void object_array_remove_duplicates(struct object_array *array) { unsigned nr = array->nr, src; struct object_array_entry *objects = array->objects; array->nr = 0; for (src = 0; src < nr; src++) { if (!contains_name(array, objects[src].name)) { if (src != array->nr) objects[array->nr] = objects[src]; array->nr++; } else { object_array_release_entry(&objects[src]); } } } -- snap -- And indeed, the `contains_name()` function iterates through all of the re-added entries and compares the *name*. Running this in a debugger shows the culprit, too: there is a `refs/heads/master`, a `HEAD` and a `master`. Note how the last entry (which was taken directly from the command-line arguments) lacks the `refs/heads/` prefix? *That* is the culprit... > > - most likely, the best way to avoid duplicate refs entries is to use the > > actual ref name and put it into a hash set. Luckily, we do have code > > for this, and examples how to use it, too. See e.g. fc65b00da7e > > (merge-recursive: change current file dir string_lists to hashmap, > > 2017-09-07). So you would define something like > > Separately, if I do end up including the hashmap code, it should be > refactored out into it's own file, right? I do not think that is necessary. Personally, I'd just add the hashmap as local variable to `write_bundle_refs()`, initialize it before the loop, add the struct for the hashmap entry and the _cmp function as file-local (i.e. `static`) function before `write_bundle_refs()`, then add all shown refs (as stored in the `display_ref` variable) to the hashmap, and add another conditional `goto skip_write_ref` after all the others, contingent on `display_ref` *not* being found in the hashmap via `hashmap_get_from_hash(&displayed_refs, strhash(display_ref), display_ref)`. In the same run, I would remove that `object_array_remove_duplicates()` function altogether, as its only caller is now no longer necessary. Ciao, Johannes