Skip to content

Add better support for checkout type config#97322

Merged
joaomoreno merged 4 commits intomicrosoft:masterfrom
Kingwl:better-checkout-type
Nov 9, 2020
Merged

Add better support for checkout type config#97322
joaomoreno merged 4 commits intomicrosoft:masterfrom
Kingwl:better-checkout-type

Conversation

@Kingwl
Copy link
Contributor

@Kingwl Kingwl commented May 9, 2020

This PR fixes #95385

@joaomoreno joaomoreno added the git GIT issues label May 11, 2020
Copy link

@rehangit rehangit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some suggestions.

results.push(...repository.refs.filter(ref => ref.type === RefType.Tag).map(ref => new CheckoutTagItem(ref)));
break;
default:
invalids.add(type);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do we do with the invalids?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I‘m not sure. Any suggestions?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dont need them. Consider my suggestion below which filters out the invalids in the reduce loop.

Comment on lines 205 to 206
const checkoutType = config.get<string>('checkoutType') || 'local,remote,tags';
const checkoutTypes = checkoutType.trim().split(',').map(type => type.trim());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can filter and unique the valid types in advance rather than collecting invalids in the loop.

Suggested change
const checkoutType = config.get<string>('checkoutType') || 'local,remote,tags';
const checkoutTypes = checkoutType.trim().split(',').map(type => type.trim());
const checkoutTypeString = config.get<string>('checkoutType') || 'local,remote,tags';
const checkoutTypes = Array.from(new Set(checkoutTypeString.trim().split(',').map(type => type.trim()).filter(type => ['local','remote','tags'].indexOf(type) > 0)));

invalids.add(type);
break;
}
});

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of forEach loop try something:

const RefTypesByCheckoutTypes = { 'local': RefType.Head, 'remote': RefType.RemoteHead, 'tags': RefType.Tag};
const results: CheckoutItem[] = checkoutTypes.reduce((acc, type) => {
      const items = 
          repository.refs
              .filter(ref => ref.type === RefTypesByCheckoutType[ref.type])
              .map(ref => new CheckoutItem(ref));
      if(items.length>0) acc.push(...items);
      return acc;
  }, []);

@Kingwl Kingwl force-pushed the better-checkout-type branch from e3c7402 to ae54053 Compare June 5, 2020 09:42
@Kingwl
Copy link
Contributor Author

Kingwl commented Sep 18, 2020

Up.

@heksesang
Copy link

One of the suggestions @rehangit made is not implemented, and it did seem like a better and more readable solution than what is there now.

const checkoutTypeString = config.get<string>('checkoutType');

const checkoutTypeOptions = ['local', 'remote', 'tags'];
const checkoutTypes = checkoutTypeString?.trim().split(',').map(type => type.trim()).filter(type => checkoutTypeOptions.includes(type));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use [...new Set(checkoutTypes)] to filter the distinct values.

@Kingwl
Copy link
Contributor Author

Kingwl commented Oct 27, 2020

@heksesang

If my memory is correct. The problem is the checkoutTypes must have the original order rather than in the set.

Copy link
Member

@joaomoreno joaomoreno left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The JSON schema should be much more structured than that: we support arrays including duplicate validation. We should also still support the old string values, don't wanna break no one right? Finally, this is now O(R*T), if R is amount of refs and T is amount of ref types, it should just run on O(R) even if at expense of memory.

I've made those changes and merged this in! Thanks!

@joaomoreno joaomoreno added this to the November 2020 milestone Nov 9, 2020
@joaomoreno joaomoreno merged commit 147f623 into microsoft:master Nov 9, 2020
@Kingwl Kingwl deleted the better-checkout-type branch November 9, 2020 14:23
@github-actions github-actions bot locked and limited conversation to collaborators Dec 25, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

git GIT issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Git: Better support for checkout quick open list

4 participants